60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
/*
|
|||
|
|
Copyright 2026 Lotus Guild
|
||
|
|
|
||
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||
|
|
Please see LICENSE in the repository root for full details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { beforeEach, expect, test, vi } from "vitest";
|
||
|
|
|
||
|
|
import { LotusWidgetActions } from "./lotusActions";
|
||
|
|
import {
|
||
|
|
clearScreenshareAudio,
|
||
|
|
reportScreenshareAudio,
|
||
|
|
resetScreenshareAudioPresence,
|
||
|
|
} from "./lotusScreenshareAudio";
|
||
|
|
|
||
|
|
const send = vi.fn().mockResolvedValue({});
|
||
|
|
|
||
|
|
vi.mock("../widget", () => ({
|
||
|
|
widget: {
|
||
|
|
api: { transport: { send: (...a: unknown[]): unknown => send(...a) } },
|
||
|
|
},
|
||
|
|
}));
|
||
|
|
|
||
|
|
const sent = (): unknown[] =>
|
||
|
|
send.mock.calls
|
||
|
|
.filter(([action]) => action === LotusWidgetActions.ScreenshareAudioState)
|
||
|
|
.map(([, data]) => data);
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
resetScreenshareAudioPresence();
|
||
|
|
send.mockClear();
|
||
|
|
});
|
||
|
|
|
||
|
|
test("[cinny #277] reports presence only when the combined answer changes", () => {
|
||
|
|
reportScreenshareAudio("sfu-a", false);
|
||
|
|
reportScreenshareAudio("sfu-a", false);
|
||
|
|
reportScreenshareAudio("sfu-a", true);
|
||
|
|
reportScreenshareAudio("sfu-a", true);
|
||
|
|
reportScreenshareAudio("sfu-a", false);
|
||
|
|
expect(sent()).toEqual([
|
||
|
|
{ present: false },
|
||
|
|
{ present: true },
|
||
|
|
{ present: false },
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("[cinny #277] any room with screenshare audio counts as present", () => {
|
||
|
|
reportScreenshareAudio("sfu-a", true);
|
||
|
|
reportScreenshareAudio("sfu-b", false);
|
||
|
|
expect(sent()).toEqual([{ present: true }]);
|
||
|
|
// A share is still playing in sfu-b after sfu-a's stops.
|
||
|
|
reportScreenshareAudio("sfu-b", true);
|
||
|
|
reportScreenshareAudio("sfu-a", false);
|
||
|
|
expect(sent()).toEqual([{ present: true }]);
|
||
|
|
// The renderer for sfu-b unmounts (call left): nothing is playing.
|
||
|
|
clearScreenshareAudio("sfu-b");
|
||
|
|
expect(sent()).toEqual([{ present: true }, { present: false }]);
|
||
|
|
});
|