diff --git a/src/controls.ts b/src/controls.ts index 363b96ad..41cf5852 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -50,7 +50,7 @@ export const setPipEnabled$ = new Subject(); export const availableOutputDevices$ = new Subject(); -export const outputDevice$ = new Subject(); +export const outputDevice$ = new Subject(); /** * This allows the os to mute the call if the user diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index ede6f5b8..08b367a3 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -269,16 +269,19 @@ class ControlledAudioOutput this.deviceSelection$.next(id); } - public readonly selected$ = merge( - this.deviceSelection$, - controlledOutputSelection$, - ).pipe( - startWith(undefined), - map((id) => - id === undefined - ? undefined - : { id, virtualEarpiece: id === EARPIECE_CONFIG_ID }, + public readonly selected$ = combineLatest([ + this.available$, + merge( + controlledOutputSelection$.pipe(startWith(undefined)), + this.deviceSelection$, ), + ]).pipe( + map(([available, selectId]) => { + const id = selectId ?? available.keys().next().value; + return id + ? { id, virtualEarpiece: id === EARPIECE_CONFIG_ID } + : undefined; + }), this.scope.state(), );