diff --git a/src/state/MuteStates.test.ts b/src/state/MuteStates.test.ts index 7b02d190..f2a6e35f 100644 --- a/src/state/MuteStates.test.ts +++ b/src/state/MuteStates.test.ts @@ -170,6 +170,13 @@ describe("MuteStates", () => { constant(true), ); + let latestSyncedState: boolean | null = null; + muteStates.video.setHandler(async (enabled: boolean): Promise => { + logger.info(`Video mute state set to: ${enabled}`); + latestSyncedState = enabled; + return Promise.resolve(enabled); + }); + let lastVideoEnabled: boolean = false; muteStates.video.enabled$.subscribe((enabled) => { lastVideoEnabled = enabled; @@ -186,5 +193,20 @@ describe("MuteStates", () => { await flushPromises(); // Video should be automatically muted expect(lastVideoEnabled).toBe(false); + expect(latestSyncedState).toBe(false); + + // Try to switch to speaker + audioOutputDevice.select("0000"); + await flushPromises(); + // TODO I'd expect it to go back to previous state (enabled)?? + // But maybe not? If you move the phone away from your ear you may not want it + // to automatically enable video? + expect(lastVideoEnabled).toBe(false); + + // But yet it can be unmuted now + expect(muteStates.video.setEnabled$.value).toBeDefined(); + muteStates.video.setEnabled$.value?.(true); + await flushPromises(); + expect(lastVideoEnabled).toBe(true); }); }); diff --git a/src/state/MuteStates.ts b/src/state/MuteStates.ts index 777e3aa4..f1d61db5 100644 --- a/src/state/MuteStates.ts +++ b/src/state/MuteStates.ts @@ -72,8 +72,6 @@ export class MuteState { private readonly data$ = this.scope.behavior( this.devicesConnected$.pipe( - // this.device.available$.pipe( - // map((available) => available.size > 0), distinctUntilChanged(), withLatestFrom( this.enabledByDefault$, @@ -85,6 +83,11 @@ export class MuteState { logger.info( `MuteState: devices connected: ${devicesConnected}, disabling`, ); + // We need to sync the mute state with the handler + // to ensure nothing is beeing published. + this.handler$.value(false).catch((err) => { + logger.error("MuteState-disable: handler error", err); + }); return { enabled$: of(false), set: null, toggle: null }; }