Skip to content

Commit

Permalink
Make sure to apply audio output selection when participant is first c…
Browse files Browse the repository at this point in the history
…reated (#968)

* make sure to apply audio output selection when participant is first created

* Create slow-chicken-agree.md

* catch audio output setting in constructor
  • Loading branch information
lukasIO authored Dec 20, 2023
1 parent 0dc45b3 commit 0bbfded
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-chicken-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Make sure to apply audio output selection when participant is first created
4 changes: 4 additions & 0 deletions example/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ const appActions = {
const cryptoKey = (<HTMLSelectElement>$('crypto-key')).value;
const autoSubscribe = (<HTMLInputElement>$('auto-subscribe')).checked;
const e2eeEnabled = (<HTMLInputElement>$('e2ee')).checked;
const audioOutputId = (<HTMLSelectElement>$('audio-output')).value;

setLogLevel(LogLevel.debug);
updateSearchParams(url, token, cryptoKey);

const roomOpts: RoomOptions = {
adaptiveStream,
dynacast,
audioOutput: {
deviceId: audioOutputId,
},
publishDefaults: {
simulcast,
videoSimulcastLayers: [VideoPresets.h90, VideoPresets.h216],
Expand Down
10 changes: 9 additions & 1 deletion src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
);
}
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) {
Expand Down Expand Up @@ -1504,6 +1507,11 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
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;
}

Expand Down

0 comments on commit 0bbfded

Please sign in to comment.