@@ -20,17 +20,21 @@ export type SetMediaDeviceOptions = {
2020
2121export function setupDeviceSelector (
2222 kind : MediaDeviceKind ,
23- room ? : Room ,
23+ room : Room ,
2424 localTrack ?: LocalAudioTrack | LocalVideoTrack ,
2525) {
2626 const activeDeviceSubject = new BehaviorSubject < string | undefined > ( undefined ) ;
2727
28- const activeDeviceObservable = room
29- ? createActiveDeviceObservable ( room , kind )
30- : activeDeviceSubject . asObservable ( ) ;
28+ const activeDeviceObservable = createActiveDeviceObservable ( room , kind ) ;
3129
3230 const setActiveMediaDevice = async ( id : string , options : SetMediaDeviceOptions = { } ) => {
33- if ( room ) {
31+ if ( localTrack ) {
32+ await localTrack . setDeviceId ( options . exact ? { exact : id } : id ) ;
33+ const actualId = await localTrack . getDeviceId ( false ) ;
34+ activeDeviceSubject . next (
35+ id === 'default' && localTrack . mediaStreamTrack . label . startsWith ( 'Default' ) ? id : actualId ,
36+ ) ;
37+ } else if ( room ) {
3438 log . debug ( `Switching active device of kind "${ kind } " with id ${ id } .` ) ;
3539 await room . switchActiveDevice ( kind , id , options . exact ) ;
3640 const actualDeviceId : string | undefined = room . getActiveDevice ( kind ) ?? id ;
@@ -49,17 +53,6 @@ export function setupDeviceSelector(
4953 ( id === 'default' && ! targetTrack ) ||
5054 ( id === 'default' && targetTrack ?. mediaStreamTrack . label . startsWith ( 'Default' ) ) ;
5155 activeDeviceSubject . next ( useDefault ? id : actualDeviceId ) ;
52- } else if ( localTrack ) {
53- await localTrack . setDeviceId ( options . exact ? { exact : id } : id ) ;
54- const actualId = await localTrack . getDeviceId ( ) ;
55- activeDeviceSubject . next (
56- id === 'default' && localTrack . mediaStreamTrack . label . startsWith ( 'Default' ) ? id : actualId ,
57- ) ;
58- } else if ( activeDeviceSubject . value !== id ) {
59- log . warn (
60- 'device switch skipped, please provide either a room or a local track to switch on. ' ,
61- ) ;
62- activeDeviceSubject . next ( id ) ;
6356 }
6457 } ;
6558 const className : string = prefixClass ( 'media-device-select' ) ;
0 commit comments