diff --git a/src/state/AndroidControlledAudioOutput.test.ts b/src/state/AndroidControlledAudioOutput.test.ts index 12b74052..994003ea 100644 --- a/src/state/AndroidControlledAudioOutput.test.ts +++ b/src/state/AndroidControlledAudioOutput.test.ts @@ -10,7 +10,7 @@ import { firstValueFrom, of, Subject, take, toArray } from "rxjs"; import { type RTCCallIntent } from "matrix-js-sdk/lib/matrixrtc"; import { AndroidControlledAudioOutput } from "./AndroidControlledAudioOutput.ts"; -import type { Controls, OutputDevice } from "../controls"; +import { outputDevice$, type Controls, type OutputDevice } from "../controls"; import { ObservableScope } from "./ObservableScope"; import { withTestScheduler } from "../utils/test"; @@ -514,6 +514,31 @@ describe("Available device changes", () => { expect(mockFn).toHaveBeenCalledWith(BT_HEADSET_DEVICE.id); }); }); + it("Do emit a device change (onAudioDeviceSelect call) back to the prev id if the OS decides to update the device automatically", () => { + createAudioControlledOutput("video"); + + // Let the os pass over the avialabe list + availableSource$.next(BT_HEADSET_BASE_DEVICE_LIST); + // we expect to switch to the BT headset once we get the avialable list. + [ + mockControls.onOutputDeviceSelect, + mockControls.onAudioDeviceSelect, + ].forEach((mockFn) => { + expect(mockFn).toHaveBeenCalledTimes(1); + expect(mockFn).toHaveBeenNthCalledWith(1, BT_HEADSET_DEVICE.id); + }); + // let the os switch to a different output device + outputDevice$.next(WIRED_HEADSET_DEVICE.id); + // We expect the onAudioDeviceSelect to be called again with the BT_HEADSET_DEVICE.id after we update the os output. + [ + mockControls.onOutputDeviceSelect, + mockControls.onAudioDeviceSelect, + ].forEach((mockFn) => { + expect(mockFn).toHaveBeenCalledTimes(2); + expect(mockFn).toHaveBeenNthCalledWith(1, BT_HEADSET_DEVICE.id); + expect(mockFn).toHaveBeenNthCalledWith(2, BT_HEADSET_DEVICE.id); + }); + }); }); describe("Scope management", () => { diff --git a/src/state/AndroidControlledAudioOutput.ts b/src/state/AndroidControlledAudioOutput.ts index 37587e8c..d1fda25f 100644 --- a/src/state/AndroidControlledAudioOutput.ts +++ b/src/state/AndroidControlledAudioOutput.ts @@ -229,6 +229,10 @@ export class AndroidControlledAudioOutput implements MediaDevice< }; } case "nativeSideUpdatedDevice": { + // INFO: This can also be achived by not letting the os EVER switch id automatically in Element X. + // Then we would be able to control everything from EC based on available device changes. + // Probably a good PR to do in EX in combination with removing all the deprecated js-api calls. + // We will stick with what we had in selectedDeviceId. // Except if the selected is not available anymore, then we update the default selection based on the available devices. const chosenDevice = this.chooseEffectiveSelection({