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

Auto restart track if audioinput disappeared from available devices #1294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 11 additions & 3 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1636,16 +1636,24 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
private handleDeviceChange = async () => {
// check for available devices, but don't request permissions in order to avoid prompts for kinds that haven't been used before
const availableDevices = await DeviceManager.getInstance().getDevices(undefined, false);
// inputs are automatically handled via TrackEvent.Ended causing a TrackEvent.Restarted. Here we only need to worry about audiooutputs changing
const kinds: MediaDeviceKind[] = ['audiooutput'];
const defaultOrFirst = (devices: MediaDeviceInfo[]) => {
const defaultDevice = devices.find((info) => info.label.toLowerCase().includes('default'));
if (defaultDevice) {
return defaultDevice.deviceId;
}
return devices[0]?.deviceId;
};
// generally inputs are automatically handled via TrackEvent.Ended causing a TrackEvent.Restarted. Here we only need to worry about audiooutputs changing
// on Safari however when disconnecting bluetooth devices the associated mediastreamtrack might fail only after a certain time so we're adding audioinputs too
const kinds: MediaDeviceKind[] = ['audiooutput', 'audioinput'];
for (let kind of kinds) {
// switch to first available device if previously active device is not available any more
const devicesOfKind = availableDevices.filter((d) => d.kind === kind);
if (
devicesOfKind.length > 0 &&
!devicesOfKind.find((deviceInfo) => deviceInfo.deviceId === this.getActiveDevice(kind))
) {
await this.switchActiveDevice(kind, devicesOfKind[0].deviceId);
await this.switchActiveDevice(kind, defaultOrFirst(devicesOfKind));
}
}

Expand Down
Loading