Skip to content

Commit

Permalink
fix: honour manual device selection on polling
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn authored Jul 31, 2024
1 parent d6913cd commit 2147008
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ export class AudioSinkManager {
const { bluetoothDevice, earpiece, speakerPhone, wired } = this.deviceManager.categorizeAudioInputDevices();
const localAudioTrack = this.store.getLocalPeer()?.audioTrack;
if (localAudioTrack && earpiece) {
const externalDeviceID = bluetoothDevice?.deviceId || wired?.deviceId || speakerPhone?.deviceId;
const manualSelection = this.deviceManager.getManuallySelectedAudioDevice();
const externalDeviceID =
manualSelection?.deviceId || bluetoothDevice?.deviceId || wired?.deviceId || speakerPhone?.deviceId;
HMSLogger.d(this.TAG, 'externalDeviceID', externalDeviceID);
// already selected appropriate device
if (localAudioTrack.settings.deviceId === externalDeviceID) {
Expand Down
14 changes: 8 additions & 6 deletions packages/hms-video-store/src/device-manager/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,12 @@ export class DeviceManager implements HMSDeviceManager {
* @returns {MediaDeviceInfo}
*/
getNewAudioInputDevice() {
const localPeer = this.store.getLocalPeer();
const audioTrack = localPeer?.audioTrack;
const manualSelection = this.audioInput.find(
device => device.deviceId === audioTrack?.getManuallySelectedDeviceId(),
);
const manualSelection = this.getManuallySelectedAudioDevice();
if (manualSelection) {
return manualSelection;
}
// if manually selected device is not available, reset on the track
audioTrack?.resetManuallySelectedDeviceId();
this.store.getLocalPeer()?.audioTrack?.resetManuallySelectedDeviceId();
const defaultDevice = this.audioInput.find(device => device.deviceId === 'default');
if (defaultDevice) {
// Selecting a non-default device so that the deviceId comparision does not give
Expand Down Expand Up @@ -421,6 +417,12 @@ export class DeviceManager implements HMSDeviceManager {
}
};

getManuallySelectedAudioDevice() {
const localPeer = this.store.getLocalPeer();
const audioTrack = localPeer?.audioTrack;
return this.audioInput.find(device => device.deviceId === audioTrack?.getManuallySelectedDeviceId());
}

// specifically used for mweb
categorizeAudioInputDevices() {
let bluetoothDevice: InputDeviceInfo | null = null;
Expand Down

0 comments on commit 2147008

Please sign in to comment.