Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getActiveAudioOutputDevice to room API #500

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -550,7 +550,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 @@ -592,16 +603,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