diff --git a/src/livekit/useLivekit.ts b/src/livekit/useLivekit.ts index 5c086a01..33f720de 100644 --- a/src/livekit/useLivekit.ts +++ b/src/livekit/useLivekit.ts @@ -117,7 +117,7 @@ export function useLivekit( // deviceId here, because it will be set by the native app. // (also the id does not need to match a browser device id) deviceId: controlledAudioDevices - ? "default" + ? undefined : getValue(devices.audioOutput.selected$)?.id, }, e2ee, @@ -329,23 +329,23 @@ export function useLivekit( selected$: Observable, ): Subscription => selected$.subscribe((device) => { - let d = device; - if (controlledAudioDevices && kind === "audiooutput") { - d = { id: "default" }; - } + // let d = device; + // if (controlledAudioDevices && kind === "audiooutput") { + // d = { id: "default" }; + // } logger.warn( "[LivekitRoom] syncDevice room.getActiveDevice(kind) !== d.id :", room.getActiveDevice(kind), " !== ", - d?.id, + device?.id, ); if ( !(kind === "audioinput" && platform === "ios") && - d !== undefined && - room.getActiveDevice(kind) !== d.id + device !== undefined && + room.getActiveDevice(kind) !== device.id ) { room - .switchActiveDevice(kind, d.id) + .switchActiveDevice(kind, device.id) .catch((e) => logger.error(`Failed to sync ${kind} device with LiveKit`, e), ); @@ -354,7 +354,9 @@ export function useLivekit( const subscriptions = [ syncDevice("audioinput", devices.audioInput.selected$), - syncDevice("audiooutput", devices.audioOutput.selected$), + !controlledAudioDevices + ? syncDevice("audiooutput", devices.audioOutput.selected$) + : undefined, syncDevice("videoinput", devices.videoInput.selected$), // Restart the audio input track whenever we detect that the active media // device has changed to refer to a different hardware device. We do this @@ -397,7 +399,7 @@ export function useLivekit( ]; return (): void => { - for (const s of subscriptions) s.unsubscribe(); + for (const s of subscriptions) s?.unsubscribe(); }; } }, [room, devices, connectionState, controlledAudioDevices]); diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index 5a81a3a5..fd5a40d6 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -392,10 +392,9 @@ export class MediaDevices { public readonly audioOutput: MediaDevice< AudioOutputDeviceLabel, SelectedAudioOutputDevice - > = - // getUrlParams().controlledAudioDevices - // ? new ControlledAudioOutput(this.scope): - new AudioOutput(this.usingNames$, this.scope); + > = getUrlParams().controlledAudioDevices + ? new ControlledAudioOutput(this.scope) + : new AudioOutput(this.usingNames$, this.scope); public readonly videoInput: MediaDevice = new VideoInput(this.usingNames$, this.scope);