2024-08-30 19:09:42 -04:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-08-30 19:09:42 -04:00
|
|
|
|
2025-02-18 17:59:58 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 10:22:13 +02:00
|
|
|
Please see LICENSE in the repository root for full details.
|
2024-08-30 19:09:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { expect, test, vi } from "vitest";
|
|
|
|
|
|
|
|
|
|
import {
|
2024-12-06 12:28:37 +01:00
|
|
|
mockRtcMembership,
|
2024-09-06 17:27:08 -04:00
|
|
|
withLocalMedia,
|
|
|
|
|
withRemoteMedia,
|
|
|
|
|
withTestScheduler,
|
|
|
|
|
} from "../utils/test";
|
2024-08-30 19:09:42 -04:00
|
|
|
|
2024-12-06 12:28:37 +01:00
|
|
|
const rtcMembership = mockRtcMembership("@alice:example.org", "AAAA");
|
|
|
|
|
|
2024-10-18 17:51:37 -04:00
|
|
|
test("control a participant's volume", async () => {
|
2024-08-30 19:09:42 -04:00
|
|
|
const setVolumeSpy = vi.fn();
|
2024-12-06 12:28:37 +01:00
|
|
|
await withRemoteMedia(rtcMembership, {}, { setVolume: setVolumeSpy }, (vm) =>
|
2024-08-30 19:09:42 -04:00
|
|
|
withTestScheduler(({ expectObservable, schedule }) => {
|
2024-10-18 17:51:37 -04:00
|
|
|
schedule("-ab---c---d|", {
|
2024-08-30 19:09:42 -04:00
|
|
|
a() {
|
2024-10-18 17:51:37 -04:00
|
|
|
// Try muting by toggling
|
2024-08-30 19:09:42 -04:00
|
|
|
vm.toggleLocallyMuted();
|
|
|
|
|
expect(setVolumeSpy).toHaveBeenLastCalledWith(0);
|
|
|
|
|
},
|
|
|
|
|
b() {
|
2024-10-18 17:51:37 -04:00
|
|
|
// Try unmuting by dragging the slider back up
|
|
|
|
|
vm.setLocalVolume(0.6);
|
2024-08-30 19:09:42 -04:00
|
|
|
vm.setLocalVolume(0.8);
|
2024-10-18 17:51:37 -04:00
|
|
|
vm.commitLocalVolume();
|
|
|
|
|
expect(setVolumeSpy).toHaveBeenCalledWith(0.6);
|
|
|
|
|
expect(setVolumeSpy).toHaveBeenLastCalledWith(0.8);
|
2024-08-30 19:09:42 -04:00
|
|
|
},
|
|
|
|
|
c() {
|
2024-10-18 17:51:37 -04:00
|
|
|
// Try muting by dragging the slider back down
|
|
|
|
|
vm.setLocalVolume(0.2);
|
|
|
|
|
vm.setLocalVolume(0);
|
|
|
|
|
vm.commitLocalVolume();
|
|
|
|
|
expect(setVolumeSpy).toHaveBeenCalledWith(0.2);
|
|
|
|
|
expect(setVolumeSpy).toHaveBeenLastCalledWith(0);
|
|
|
|
|
},
|
|
|
|
|
d() {
|
|
|
|
|
// Try unmuting by toggling
|
2024-08-30 19:09:42 -04:00
|
|
|
vm.toggleLocallyMuted();
|
2024-10-18 17:51:37 -04:00
|
|
|
// The volume should return to the last non-zero committed volume
|
2024-08-30 19:09:42 -04:00
|
|
|
expect(setVolumeSpy).toHaveBeenLastCalledWith(0.8);
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-12-17 04:01:56 +00:00
|
|
|
expectObservable(vm.localVolume$).toBe("ab(cd)(ef)g", {
|
2024-10-18 17:51:37 -04:00
|
|
|
a: 1,
|
|
|
|
|
b: 0,
|
|
|
|
|
c: 0.6,
|
|
|
|
|
d: 0.8,
|
|
|
|
|
e: 0.2,
|
|
|
|
|
f: 0,
|
|
|
|
|
g: 0.8,
|
2024-08-30 19:09:42 -04:00
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-06 17:27:08 -04:00
|
|
|
test("toggle fit/contain for a participant's video", async () => {
|
2024-12-06 12:28:37 +01:00
|
|
|
await withRemoteMedia(rtcMembership, {}, {}, (vm) =>
|
2024-08-30 19:09:42 -04:00
|
|
|
withTestScheduler(({ expectObservable, schedule }) => {
|
|
|
|
|
schedule("-ab|", {
|
|
|
|
|
a: () => vm.toggleFitContain(),
|
|
|
|
|
b: () => vm.toggleFitContain(),
|
|
|
|
|
});
|
2024-12-17 04:01:56 +00:00
|
|
|
expectObservable(vm.cropVideo$).toBe("abc", {
|
2024-08-30 19:09:42 -04:00
|
|
|
a: true,
|
|
|
|
|
b: false,
|
|
|
|
|
c: true,
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-06 17:27:08 -04:00
|
|
|
test("local media remembers whether it should always be shown", async () => {
|
2024-12-06 12:28:37 +01:00
|
|
|
await withLocalMedia(rtcMembership, {}, (vm) =>
|
2024-08-30 19:09:42 -04:00
|
|
|
withTestScheduler(({ expectObservable, schedule }) => {
|
|
|
|
|
schedule("-a|", { a: () => vm.setAlwaysShow(false) });
|
2024-12-17 04:01:56 +00:00
|
|
|
expectObservable(vm.alwaysShow$).toBe("ab", { a: true, b: false });
|
2024-08-30 19:09:42 -04:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
// Next local media should start out *not* always shown
|
2024-12-06 12:28:37 +01:00
|
|
|
await withLocalMedia(
|
|
|
|
|
rtcMembership,
|
|
|
|
|
|
|
|
|
|
{},
|
|
|
|
|
(vm) =>
|
|
|
|
|
withTestScheduler(({ expectObservable, schedule }) => {
|
|
|
|
|
schedule("-a|", { a: () => vm.setAlwaysShow(true) });
|
2024-12-17 04:01:56 +00:00
|
|
|
expectObservable(vm.alwaysShow$).toBe("ab", { a: false, b: true });
|
2024-12-06 12:28:37 +01:00
|
|
|
}),
|
2024-08-30 19:09:42 -04:00
|
|
|
);
|
|
|
|
|
});
|