From 0bbfdeda5b57e3954a8d985c359ef25a5be6e9d0 Mon Sep 17 00:00:00 2001 From: lukasIO Date: Wed, 20 Dec 2023 17:18:38 +0100 Subject: [PATCH] Make sure to apply audio output selection when participant is first created (#968) * make sure to apply audio output selection when participant is first created * Create slow-chicken-agree.md * catch audio output setting in constructor --- .changeset/slow-chicken-agree.md | 5 +++++ example/sample.ts | 4 ++++ src/room/Room.ts | 10 +++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-chicken-agree.md diff --git a/.changeset/slow-chicken-agree.md b/.changeset/slow-chicken-agree.md new file mode 100644 index 0000000000..14d041e24f --- /dev/null +++ b/.changeset/slow-chicken-agree.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Make sure to apply audio output selection when participant is first created diff --git a/example/sample.ts b/example/sample.ts index a69ab804cb..2a9911bd17 100644 --- a/example/sample.ts +++ b/example/sample.ts @@ -77,6 +77,7 @@ const appActions = { const cryptoKey = ($('crypto-key')).value; const autoSubscribe = ($('auto-subscribe')).checked; const e2eeEnabled = ($('e2ee')).checked; + const audioOutputId = ($('audio-output')).value; setLogLevel(LogLevel.debug); updateSearchParams(url, token, cryptoKey); @@ -84,6 +85,9 @@ const appActions = { const roomOpts: RoomOptions = { adaptiveStream, dynacast, + audioOutput: { + deviceId: audioOutputId, + }, publishDefaults: { simulcast, videoSimulcastLayers: [VideoPresets.h90, VideoPresets.h216], diff --git a/src/room/Room.ts b/src/room/Room.ts index e65ec9c929..b6779ebd6a 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -195,7 +195,10 @@ class Room extends (EventEmitter as new () => TypedEmitter) ); } if (this.options.audioOutput?.deviceId) { - this.switchActiveDevice('audiooutput', unwrapConstraint(this.options.audioOutput.deviceId)); + this.switchActiveDevice( + 'audiooutput', + unwrapConstraint(this.options.audioOutput.deviceId), + ).catch((e) => log.warn(`Could not set audio output: ${e.message}`)); } if (this.options.e2ee) { @@ -1504,6 +1507,11 @@ class Room extends (EventEmitter as new () => TypedEmitter) if (this.options.expWebAudioMix) { participant.setAudioContext(this.audioContext); } + if (this.options.audioOutput?.deviceId) { + participant + .setAudioOutput(this.options.audioOutput) + .catch((e) => log.warn(`Could not set audio output: ${e.message}`)); + } return participant; }