mirror of
https://github.com/vector-im/element-call.git
synced 2026-03-31 07:00:26 +00:00
Mock RTC members
This commit is contained in:
@@ -6,7 +6,7 @@ Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { test, vi, onTestFinished } from "vitest";
|
||||
import { map, Observable } from "rxjs";
|
||||
import { map, Observable, of } from "rxjs";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
ConnectionState,
|
||||
@@ -25,10 +25,11 @@ import {
|
||||
mockLivekitRoom,
|
||||
mockLocalParticipant,
|
||||
mockMatrixRoom,
|
||||
mockMember,
|
||||
mockRoomMember,
|
||||
mockRemoteParticipant,
|
||||
OurRunHelpers,
|
||||
withTestScheduler,
|
||||
mockMembership,
|
||||
} from "../utils/test";
|
||||
import {
|
||||
ECAddonConnectionState,
|
||||
@@ -49,9 +50,9 @@ const bobId = "@bob:example.org";
|
||||
const bobDev = "BBBB";
|
||||
const bobRTCId = bobId + ":" + bobDev;
|
||||
|
||||
const alice = mockMember({ userId: aliceId });
|
||||
const bob = mockMember({ userId: bobId });
|
||||
const carol = mockMember({ userId: carolId });
|
||||
const alice = mockRoomMember({ userId: aliceId });
|
||||
const bob = mockRoomMember({ userId: bobId });
|
||||
const carol = mockRoomMember({ userId: carolId });
|
||||
|
||||
const localParticipant = mockLocalParticipant({ identity: "" });
|
||||
const aliceParticipant = mockRemoteParticipant({ identity: aliceRTCId });
|
||||
@@ -71,9 +72,10 @@ const members = new Map([
|
||||
[carol.userId, carol],
|
||||
]);
|
||||
|
||||
const rtcMemberAlice = { sender: aliceId, deviceId: aliceDev };
|
||||
const rtcMemberBob = { sender: bobId, deviceId: bobDev };
|
||||
const rtcMemberCarol = { sender: carolId, deviceId: carolDev };
|
||||
const rtcMemberAlice = mockMembership(aliceId, aliceDev);
|
||||
const rtcMemberBob = mockMembership(bobId, bobDev);
|
||||
const rtcMemberCarol = mockMembership(carolId, carolDev);
|
||||
|
||||
export interface GridLayoutSummary {
|
||||
type: "grid";
|
||||
spotlight?: string[];
|
||||
@@ -262,6 +264,7 @@ test("screen sharing activates spotlight layout", () => {
|
||||
c: [aliceSharingScreen, bobSharingScreen],
|
||||
d: [aliceParticipant, bobSharingScreen],
|
||||
}),
|
||||
of([rtcMemberAlice, rtcMemberAlice]),
|
||||
hot("a", { a: ConnectionState.Connected }),
|
||||
(vm) => {
|
||||
schedule(modeMarbles, {
|
||||
|
||||
@@ -7,7 +7,16 @@ Please see LICENSE in the repository root for full details.
|
||||
import { map, of } from "rxjs";
|
||||
import { RunHelpers, TestScheduler } from "rxjs/testing";
|
||||
import { expect, vi } from "vitest";
|
||||
import { RoomMember, Room as MatrixRoom } from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
RoomMember,
|
||||
Room as MatrixRoom,
|
||||
MatrixEvent,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
CallMembership,
|
||||
Focus,
|
||||
SessionMembershipData,
|
||||
} from "matrix-js-sdk/src/matrixrtc";
|
||||
import {
|
||||
LocalParticipant,
|
||||
LocalTrackPublication,
|
||||
@@ -88,10 +97,32 @@ function mockEmitter<T>(): EmitterMock<T> {
|
||||
};
|
||||
}
|
||||
|
||||
export function mockMembership(
|
||||
userId: string,
|
||||
deviceId: string,
|
||||
callId = "",
|
||||
fociPreferred: Focus[] = [],
|
||||
focusActive: Focus = { type: "oldest_membership" },
|
||||
membership: Partial<SessionMembershipData> = {},
|
||||
): CallMembership {
|
||||
const data: SessionMembershipData = {
|
||||
application: "m.call",
|
||||
call_id: callId,
|
||||
device_id: deviceId,
|
||||
foci_preferred: fociPreferred,
|
||||
focus_active: focusActive,
|
||||
...membership,
|
||||
};
|
||||
const event = new MatrixEvent({
|
||||
sender: userId,
|
||||
});
|
||||
return new CallMembership(event, data);
|
||||
}
|
||||
|
||||
// Maybe it'd be good to move this to matrix-js-sdk? Our testing needs are
|
||||
// rather simple, but if one util to mock a member is good enough for us, maybe
|
||||
// it's useful for matrix-js-sdk consumers in general.
|
||||
export function mockMember(member: Partial<RoomMember>): RoomMember {
|
||||
export function mockRoomMember(member: Partial<RoomMember>): RoomMember {
|
||||
return { ...mockEmitter(), ...member } as RoomMember;
|
||||
}
|
||||
|
||||
@@ -121,7 +152,7 @@ export async function withLocalMedia(
|
||||
): Promise<void> {
|
||||
const vm = new LocalUserMediaViewModel(
|
||||
"local",
|
||||
mockMember(member),
|
||||
mockRoomMember(member),
|
||||
of(mockLocalParticipant({})),
|
||||
{
|
||||
kind: E2eeType.PER_PARTICIPANT,
|
||||
@@ -154,7 +185,7 @@ export async function withRemoteMedia(
|
||||
): Promise<void> {
|
||||
const vm = new RemoteUserMediaViewModel(
|
||||
"remote",
|
||||
mockMember(member),
|
||||
mockRoomMember(member),
|
||||
of(mockRemoteParticipant(participant)),
|
||||
{
|
||||
kind: E2eeType.PER_PARTICIPANT,
|
||||
|
||||
Reference in New Issue
Block a user