diff --git a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts index 6d1e667888..596661efde 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -295,23 +295,7 @@ export class AudioSinkManager { if ('ondevicechange' in navigator.mediaDevices) { return; } - let bluetoothDevice: InputDeviceInfo | null = null; - let speakerPhone: InputDeviceInfo | null = null; - let wired: InputDeviceInfo | null = null; - let earpiece: InputDeviceInfo | null = null; - - for (const device of this.deviceManager.audioInput) { - const label = device.label.toLowerCase(); - if (label.includes('speakerphone')) { - speakerPhone = device; - } else if (label.includes('wired')) { - wired = device; - } else if (label.includes('bluetooth')) { - bluetoothDevice = device; - } else if (label.includes('earpiece')) { - earpiece = device; - } - } + 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; diff --git a/packages/hms-video-store/src/device-manager/DeviceManager.ts b/packages/hms-video-store/src/device-manager/DeviceManager.ts index 8e17fcc5af..45e05aa138 100644 --- a/packages/hms-video-store/src/device-manager/DeviceManager.ts +++ b/packages/hms-video-store/src/device-manager/DeviceManager.ts @@ -4,6 +4,7 @@ import { ErrorFactory } from '../error/ErrorFactory'; import { HMSException } from '../error/HMSException'; import { EventBus } from '../events/EventBus'; import { DeviceMap, HMSDeviceChangeEvent, SelectedDevices } from '../interfaces'; +import { isIOS } from '../internal'; import { HMSAudioTrackSettingsBuilder, HMSVideoTrackSettingsBuilder } from '../media/settings'; import { HMSLocalAudioTrack, HMSLocalTrack, HMSLocalVideoTrack } from '../media/tracks'; import { Store } from '../sdk/store'; @@ -205,7 +206,11 @@ export class DeviceManager implements HMSDeviceManager { } const audioDeviceId = this.store.getConfig()?.settings?.audioInputDeviceId; if (!audioDeviceId && localPeer?.audioTrack) { - await localPeer.audioTrack.setSettings({ deviceId: this.audioInput[0]?.deviceId }, true); + const getInitialDeviceId = () => { + const nonIPhoneDevice = this.audioInput.find(device => !device.label.toLowerCase().includes('iphone')); + return isIOS() && nonIPhoneDevice ? nonIPhoneDevice?.deviceId : this.getNewAudioInputDevice()?.deviceId; + }; + await localPeer.audioTrack.setSettings({ deviceId: getInitialDeviceId() }, true); } }; @@ -416,6 +421,29 @@ export class DeviceManager implements HMSDeviceManager { } }; + // specifically used for mweb + categorizeAudioInputDevices() { + let bluetoothDevice: InputDeviceInfo | null = null; + let speakerPhone: InputDeviceInfo | null = null; + let wired: InputDeviceInfo | null = null; + let earpiece: InputDeviceInfo | null = null; + + for (const device of this.audioInput) { + const label = device.label.toLowerCase(); + if (label.includes('speakerphone')) { + speakerPhone = device; + } else if (label.includes('wired')) { + wired = device; + } else if (/airpods|buds|wireless|bluetooth/gi.test(label)) { + bluetoothDevice = device; + } else if (label.includes('earpiece')) { + earpiece = device; + } + } + + return { bluetoothDevice, speakerPhone, wired, earpiece }; + } + // eslint-disable-next-line complexity private getAudioOutputDeviceMatchingInput(inputDevice?: MediaDeviceInfo) { const blacklist = this.store.getConfig()?.settings?.speakerAutoSelectionBlacklist || []; diff --git a/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/VBPicker.tsx b/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/VBPicker.tsx index 7b9788816e..e60a497c93 100644 --- a/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/VBPicker.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/VBPicker.tsx @@ -30,7 +30,6 @@ import { useSidepaneResetOnLayoutUpdate } from '../AppData/useSidepaneResetOnLay // @ts-ignore import { useSetAppDataByKey, useUISettings } from '../AppData/useUISettings'; import { APP_DATA, SIDE_PANE_OPTIONS, UI_SETTINGS } from '../../common/constants'; -import { defaultMedia } from './constants'; const iconDims = { height: '40px', width: '40px' }; @@ -52,9 +51,7 @@ export const VBPicker = ({ backgroundMedia = [] }: { backgroundMedia: VirtualBac const [loadingEffects, setLoadingEffects] = useSetAppDataByKey(APP_DATA.loadingEffects); const isPluginAdded = useHMSStore(selectIsLocalVideoPluginPresent(VBHandler?.getName() || '')); const background = useHMSStore(selectAppData(APP_DATA.background)); - const mediaList = backgroundMedia.length - ? backgroundMedia.map((media: VirtualBackgroundMedia) => media.url || '') - : defaultMedia; + const mediaList = backgroundMedia.map((media: VirtualBackgroundMedia) => media.url || ''); const inPreview = roomState === HMSRoomState.Preview; // Hidden in preview as the effect will be visible in the preview tile diff --git a/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/constants.ts b/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/constants.ts deleted file mode 100644 index 42b9857363..0000000000 --- a/packages/roomkit-react/src/Prebuilt/components/VirtualBackground/constants.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const defaultMedia = [ - 'https://assets.100ms.live/webapp/vb-mini/vb-1.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-2.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-3.png', - 'https://assets.100ms.live/webapp/vb-mini/vb-4.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-5.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-6.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-7.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-8.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-9.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-10.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-11.jpg', - 'https://assets.100ms.live/webapp/vb-mini/vb-12.jpg', -];