add test for OS autoswichting to default to check if we switch back.

This commit is contained in:
Timo K
2026-04-16 23:30:37 +02:00
parent a40f9b8a1d
commit f4c2b15d7a
2 changed files with 30 additions and 1 deletions

View File

@@ -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", () => {

View File

@@ -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({