Skip to content

Commit

Permalink
Add getActiveAudioOutputDevice to room API (livekit#500)
Browse files Browse the repository at this point in the history
* add getActiveAudioOutputDevice to room API

* add changeset

* run prettier

* return an empty string if no audiooutput device was set
  • Loading branch information
davideberlein authored and max-b committed Dec 9, 2022
1 parent 48bcd25 commit b5cfa91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-pumpkins-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': minor
---

add getActiveAudioOutputDevice method to Room
25 changes: 15 additions & 10 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,18 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
}

/**
* Switches all active device used in this room to the given device.
* Returns the active audio output device used in this room.
*
* Note: to get the active `audioinput` or `videoinput` use [[LocalTrack.getDeviceId()]]
*
* @return the previously successfully set audio output device ID or an empty string if the default device is used.
*/
getActiveAudioOutputDevice(): string {
return this.options.audioOutput?.deviceId ?? '';
}

/**
* Switches all active devices used in this room to the given device.
*
* Note: setting AudioOutput is not supported on some browsers. See [setSinkId](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId#browser_compatibility)
*
Expand Down Expand Up @@ -612,16 +623,10 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.options.audioOutput ??= {};
const prevDeviceId = this.options.audioOutput.deviceId;
this.options.audioOutput.deviceId = deviceId;
const promises: Promise<void>[] = [];
this.participants.forEach((p) => {
promises.push(
p.setAudioOutput({
deviceId,
}),
);
});
try {
await Promise.all(promises);
await Promise.all(
Array.from(this.participants.values()).map((p) => p.setAudioOutput({ deviceId })),
);
} catch (e) {
this.options.audioOutput.deviceId = prevDeviceId;
throw e;
Expand Down

0 comments on commit b5cfa91

Please sign in to comment.