Auto-play voice track when joining a voice room
This commit is contained in:
+14
-1
@@ -1,7 +1,7 @@
|
||||
import {derived, get, writable} from "svelte/store"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {SignJWT} from "jose"
|
||||
import {Room, RoomEvent} from "livekit-client"
|
||||
import {Room, RoomEvent, Track} from "livekit-client"
|
||||
import {now} from "@welshman/lib"
|
||||
import {makeEvent, normalizeRelayUrl, getTag} from "@welshman/util"
|
||||
import {pubkey, publishThunk} from "@welshman/app"
|
||||
@@ -136,6 +136,19 @@ export const joinVoiceRoom = async (url: string, h: string) => {
|
||||
stopPresenceHeartbeat()
|
||||
})
|
||||
|
||||
room.on(RoomEvent.TrackSubscribed, (track, _publication, _participant) => {
|
||||
if (track.kind === Track.Kind.Audio) {
|
||||
const element = track.attach()
|
||||
element.style.display = "none"
|
||||
document.body.appendChild(element)
|
||||
element.play().catch(() => {})
|
||||
}
|
||||
})
|
||||
|
||||
room.on(RoomEvent.TrackUnsubscribed, track => {
|
||||
track.detach().forEach(el => el.remove())
|
||||
})
|
||||
|
||||
await room.connect(LIVEKIT_URL, token)
|
||||
await room.localParticipant.setMicrophoneEnabled(true)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user