diff --git a/src/controls.ts b/src/controls.ts index 9e5ad68d..e7488568 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -51,7 +51,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 66224bab..94dc71d2 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -273,16 +273,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(), );