Skip to content

Commit

Permalink
fix: device label categorisation on prebuilt
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn authored Sep 19, 2024
1 parent 8c79ee4 commit 0766552
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
12 changes: 6 additions & 6 deletions packages/hms-video-store/src/device-manager/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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 { getAudioDeviceCategory, isIOS } from '../internal';
import { HMSAudioTrackSettingsBuilder, HMSVideoTrackSettingsBuilder } from '../media/settings';
import { HMSLocalAudioTrack, HMSLocalTrack, HMSLocalVideoTrack } from '../media/tracks';
import { Store } from '../sdk/store';
Expand Down Expand Up @@ -443,14 +443,14 @@ export class DeviceManager implements HMSDeviceManager {
let earpiece: InputDeviceInfo | null = null;

for (const device of this.audioInput) {
const label = device.label.toLowerCase();
if (label.includes('speakerphone')) {
const deviceCategory = getAudioDeviceCategory(device.label);
if (deviceCategory === 'speakerphone') {
speakerPhone = device;
} else if (label.includes('wired')) {
} else if (deviceCategory === 'wired') {
wired = device;
} else if (/airpods|buds|wireless|bluetooth/gi.test(label)) {
} else if (deviceCategory === 'bluetooth') {
bluetoothDevice = device;
} else if (label.includes('earpiece')) {
} else if (deviceCategory === 'speakerhone') {
earpiece = device;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/hms-video-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
simulcastMapping,
DeviceType,
HMSPeerType,
getAudioDeviceCategory,
} from './internal';

export type {
Expand Down
14 changes: 14 additions & 0 deletions packages/hms-video-store/src/utils/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ export const HMSAudioContextHandler: HMSAudioContext = {
}
},
};

export const getAudioDeviceCategory = (deviceLabel: string) => {
const label = deviceLabel.toLowerCase();
if (label.includes('speakerphone')) {
return 'speakerhone';
} else if (label.includes('wired')) {
return 'wired';
} else if (/airpods|buds|wireless|bluetooth/gi.test(label)) {
return 'bluetooth';
} else if (label.includes('earpiece')) {
return 'earpiece';
}
return 'speakerphone';
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {
DeviceType,
getAudioDeviceCategory,
selectIsLocalVideoEnabled,
selectLocalVideoTrackID,
selectVideoTrackByID,
Expand Down Expand Up @@ -78,12 +79,13 @@ export const AudioActions = () => {
if (!audioFiltered) {
return null;
}
const deviceCategory = getAudioDeviceCategory(currentSelection.label);
let AudioIcon = <SpeakerIcon />;
if (currentSelection && currentSelection.label.toLowerCase().includes('bluetooth')) {
if (deviceCategory === 'bluetooth') {
AudioIcon = <BluetoothIcon />;
} else if (currentSelection && currentSelection.label.toLowerCase().includes('wired')) {
} else if (deviceCategory === 'wired') {
AudioIcon = <HeadphonesIcon />;
} else if (currentSelection && currentSelection.label.toLowerCase().includes('earpiece')) {
} else if (deviceCategory === 'earpiece') {
AudioIcon = <TelePhoneIcon />;
}
return (
Expand Down

0 comments on commit 0766552

Please sign in to comment.