From 131bdc352271847c1232b38f9892241c291f5964 Mon Sep 17 00:00:00 2001 From: Timo Date: Wed, 25 Jun 2025 12:14:05 +0200 Subject: [PATCH 1/4] 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(), ); From 3b1ce22b71dc72e985b8c0f288c4100a57eb0899 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 25 Jun 2025 13:38:47 -0400 Subject: [PATCH 2/4] Fold map operation into combineLatest --- src/state/MediaDevices.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index 08b367a3..4e41a463 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -269,21 +269,21 @@ class ControlledAudioOutput this.deviceSelection$.next(id); } - public readonly selected$ = combineLatest([ - this.available$, - merge( - controlledOutputSelection$.pipe(startWith(undefined)), - this.deviceSelection$, - ), - ]).pipe( - map(([available, selectId]) => { + public readonly selected$ = combineLatest( + [ + this.available$, + merge( + controlledOutputSelection$.pipe(startWith(undefined)), + this.deviceSelection$, + ), + ], + (available, selectId) => { const id = selectId ?? available.keys().next().value; return id ? { id, virtualEarpiece: id === EARPIECE_CONFIG_ID } : undefined; - }), - this.scope.state(), - ); + }, + ).pipe(this.scope.state()); public constructor(private readonly scope: ObservableScope) { this.selected$.subscribe((device) => { From f3419f94c34d9035284810f400d548bfcd26b046 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 25 Jun 2025 13:40:39 -0400 Subject: [PATCH 3/4] Fix empty string IDs not counting as devices --- src/state/MediaDevices.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index 4e41a463..a19c1e7f 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -279,9 +279,9 @@ class ControlledAudioOutput ], (available, selectId) => { const id = selectId ?? available.keys().next().value; - return id - ? { id, virtualEarpiece: id === EARPIECE_CONFIG_ID } - : undefined; + return id === undefined + ? undefined + : { id, virtualEarpiece: id === EARPIECE_CONFIG_ID }; }, ).pipe(this.scope.state()); From f4d590c703f364852cb3e21aecfb2f4856840929 Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 25 Jun 2025 13:42:31 -0400 Subject: [PATCH 4/4] Use consistent name for preferred device IDs --- src/state/MediaDevices.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/state/MediaDevices.ts b/src/state/MediaDevices.ts index a19c1e7f..f441918b 100644 --- a/src/state/MediaDevices.ts +++ b/src/state/MediaDevices.ts @@ -277,8 +277,8 @@ class ControlledAudioOutput this.deviceSelection$, ), ], - (available, selectId) => { - const id = selectId ?? available.keys().next().value; + (available, preferredId) => { + const id = preferredId ?? available.keys().next().value; return id === undefined ? undefined : { id, virtualEarpiece: id === EARPIECE_CONFIG_ID };