From 131bdc352271847c1232b38f9892241c291f5964 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 25 Jun 2025 12:14:05 +0200 Subject: [PATCH] fix initial selection when using controlled media --- src/controls.ts | 2 +- src/state/MediaDevices.ts | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) 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(), );