mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +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 { 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 { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import {
|
import {
|
||||||
ConnectionState,
|
ConnectionState,
|
||||||
@@ -25,10 +25,11 @@ import {
|
|||||||
mockLivekitRoom,
|
mockLivekitRoom,
|
||||||
mockLocalParticipant,
|
mockLocalParticipant,
|
||||||
mockMatrixRoom,
|
mockMatrixRoom,
|
||||||
mockMember,
|
mockRoomMember,
|
||||||
mockRemoteParticipant,
|
mockRemoteParticipant,
|
||||||
OurRunHelpers,
|
OurRunHelpers,
|
||||||
withTestScheduler,
|
withTestScheduler,
|
||||||
|
mockMembership,
|
||||||
} from "../utils/test";
|
} from "../utils/test";
|
||||||
import {
|
import {
|
||||||
ECAddonConnectionState,
|
ECAddonConnectionState,
|
||||||
@@ -49,9 +50,9 @@ const bobId = "@bob:example.org";
|
|||||||
const bobDev = "BBBB";
|
const bobDev = "BBBB";
|
||||||
const bobRTCId = bobId + ":" + bobDev;
|
const bobRTCId = bobId + ":" + bobDev;
|
||||||
|
|
||||||
const alice = mockMember({ userId: aliceId });
|
const alice = mockRoomMember({ userId: aliceId });
|
||||||
const bob = mockMember({ userId: bobId });
|
const bob = mockRoomMember({ userId: bobId });
|
||||||
const carol = mockMember({ userId: carolId });
|
const carol = mockRoomMember({ userId: carolId });
|
||||||
|
|
||||||
const localParticipant = mockLocalParticipant({ identity: "" });
|
const localParticipant = mockLocalParticipant({ identity: "" });
|
||||||
const aliceParticipant = mockRemoteParticipant({ identity: aliceRTCId });
|
const aliceParticipant = mockRemoteParticipant({ identity: aliceRTCId });
|
||||||
@@ -71,9 +72,10 @@ const members = new Map([
|
|||||||
[carol.userId, carol],
|
[carol.userId, carol],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const rtcMemberAlice = { sender: aliceId, deviceId: aliceDev };
|
const rtcMemberAlice = mockMembership(aliceId, aliceDev);
|
||||||
const rtcMemberBob = { sender: bobId, deviceId: bobDev };
|
const rtcMemberBob = mockMembership(bobId, bobDev);
|
||||||
const rtcMemberCarol = { sender: carolId, deviceId: carolDev };
|
const rtcMemberCarol = mockMembership(carolId, carolDev);
|
||||||
|
|
||||||
export interface GridLayoutSummary {
|
export interface GridLayoutSummary {
|
||||||
type: "grid";
|
type: "grid";
|
||||||
spotlight?: string[];
|
spotlight?: string[];
|
||||||
@@ -262,6 +264,7 @@ test("screen sharing activates spotlight layout", () => {
|
|||||||
c: [aliceSharingScreen, bobSharingScreen],
|
c: [aliceSharingScreen, bobSharingScreen],
|
||||||
d: [aliceParticipant, bobSharingScreen],
|
d: [aliceParticipant, bobSharingScreen],
|
||||||
}),
|
}),
|
||||||
|
of([rtcMemberAlice, rtcMemberAlice]),
|
||||||
hot("a", { a: ConnectionState.Connected }),
|
hot("a", { a: ConnectionState.Connected }),
|
||||||
(vm) => {
|
(vm) => {
|
||||||
schedule(modeMarbles, {
|
schedule(modeMarbles, {
|
||||||
|
|||||||
@@ -7,7 +7,16 @@ Please see LICENSE in the repository root for full details.
|
|||||||
import { map, of } from "rxjs";
|
import { map, of } from "rxjs";
|
||||||
import { RunHelpers, TestScheduler } from "rxjs/testing";
|
import { RunHelpers, TestScheduler } from "rxjs/testing";
|
||||||
import { expect, vi } from "vitest";
|
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 {
|
import {
|
||||||
LocalParticipant,
|
LocalParticipant,
|
||||||
LocalTrackPublication,
|
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
|
// 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
|
// 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.
|
// 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;
|
return { ...mockEmitter(), ...member } as RoomMember;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +152,7 @@ export async function withLocalMedia(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const vm = new LocalUserMediaViewModel(
|
const vm = new LocalUserMediaViewModel(
|
||||||
"local",
|
"local",
|
||||||
mockMember(member),
|
mockRoomMember(member),
|
||||||
of(mockLocalParticipant({})),
|
of(mockLocalParticipant({})),
|
||||||
{
|
{
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
kind: E2eeType.PER_PARTICIPANT,
|
||||||
@@ -154,7 +185,7 @@ export async function withRemoteMedia(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const vm = new RemoteUserMediaViewModel(
|
const vm = new RemoteUserMediaViewModel(
|
||||||
"remote",
|
"remote",
|
||||||
mockMember(member),
|
mockRoomMember(member),
|
||||||
of(mockRemoteParticipant(participant)),
|
of(mockRemoteParticipant(participant)),
|
||||||
{
|
{
|
||||||
kind: E2eeType.PER_PARTICIPANT,
|
kind: E2eeType.PER_PARTICIPANT,
|
||||||
|
|||||||
Reference in New Issue
Block a user