You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
fixup
This commit is contained in:
@@ -64,6 +64,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
|
{
|
||||||
|
listenForStickyEvents: true,
|
||||||
|
listenForMemberStateEvents: true,
|
||||||
|
testCreateSticky: false,
|
||||||
|
createWithDefaults: true, // Create MatrixRTCSession with defaults
|
||||||
|
},
|
||||||
{
|
{
|
||||||
listenForStickyEvents: true,
|
listenForStickyEvents: true,
|
||||||
listenForMemberStateEvents: true,
|
listenForMemberStateEvents: true,
|
||||||
@@ -87,10 +93,33 @@ describe("MatrixRTCSession", () => {
|
|||||||
])(
|
])(
|
||||||
"roomSessionForRoom listenForSticky=$listenForStickyEvents listenForMemberStateEvents=$listenForMemberStateEvents testCreateSticky=$testCreateSticky",
|
"roomSessionForRoom listenForSticky=$listenForStickyEvents listenForMemberStateEvents=$listenForMemberStateEvents testCreateSticky=$testCreateSticky",
|
||||||
(testConfig) => {
|
(testConfig) => {
|
||||||
|
it(`will ${testConfig.listenForMemberStateEvents ? "" : "NOT"} throw if the room does not have any state stored`, () => {
|
||||||
|
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
|
||||||
|
mockRoom.getLiveTimeline.mockReturnValue({
|
||||||
|
getState: jest.fn().mockReturnValue(undefined),
|
||||||
|
} as unknown as EventTimeline);
|
||||||
|
if (testConfig.listenForMemberStateEvents) {
|
||||||
|
// eslint-disable-next-line jest/no-conditional-expect
|
||||||
|
expect(() => {
|
||||||
|
MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
||||||
|
}).toThrow();
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line jest/no-conditional-expect
|
||||||
|
expect(() => {
|
||||||
|
MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
||||||
|
}).not.toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("creates a room-scoped session from room state", () => {
|
it("creates a room-scoped session from room state", () => {
|
||||||
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
|
||||||
|
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships.length).toEqual(1);
|
expect(sess?.memberships.length).toEqual(1);
|
||||||
expect(sess?.memberships[0].sessionDescription.id).toEqual("");
|
expect(sess?.memberships[0].sessionDescription.id).toEqual("");
|
||||||
expect(sess?.memberships[0].scope).toEqual("m.room");
|
expect(sess?.memberships[0].scope).toEqual("m.room");
|
||||||
@@ -105,7 +134,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
application: "not-m.call",
|
application: "not-m.call",
|
||||||
});
|
});
|
||||||
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
|
||||||
const sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
const sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships).toHaveLength(0);
|
expect(sess?.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,7 +149,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
scope: "m.room",
|
scope: "m.room",
|
||||||
});
|
});
|
||||||
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
|
||||||
const sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
const sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships).toHaveLength(0);
|
expect(sess?.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,7 +166,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
const mockRoom = makeMockRoom([membershipTemplate, expiredMembership], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([membershipTemplate, expiredMembership], testConfig.testCreateSticky);
|
||||||
|
|
||||||
jest.advanceTimersByTime(2000);
|
jest.advanceTimersByTime(2000);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships.length).toEqual(1);
|
expect(sess?.memberships.length).toEqual(1);
|
||||||
expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA");
|
expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA");
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
@@ -136,7 +180,25 @@ describe("MatrixRTCSession", () => {
|
|||||||
it("ignores memberships events of members not in the room", () => {
|
it("ignores memberships events of members not in the room", () => {
|
||||||
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
|
||||||
mockRoom.hasMembershipState.mockImplementation((state) => state === KnownMembership.Join);
|
mockRoom.hasMembershipState.mockImplementation((state) => state === KnownMembership.Join);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
|
expect(sess?.memberships.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ignores memberships events with no sender", () => {
|
||||||
|
// Force the sender to be undefined.
|
||||||
|
const mockRoom = makeMockRoom([{ ...membershipTemplate, user_id: "" }], testConfig.testCreateSticky);
|
||||||
|
mockRoom.hasMembershipState.mockImplementation((state) => state === KnownMembership.Join);
|
||||||
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships.length).toEqual(0);
|
expect(sess?.memberships.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -147,14 +209,24 @@ describe("MatrixRTCSession", () => {
|
|||||||
expiredMembership.created_ts = 500;
|
expiredMembership.created_ts = 500;
|
||||||
expiredMembership.expires = 1000;
|
expiredMembership.expires = 1000;
|
||||||
const mockRoom = makeMockRoom([expiredMembership], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([expiredMembership], testConfig.testCreateSticky);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships[0].getAbsoluteExpiry()).toEqual(1500);
|
expect(sess?.memberships[0].getAbsoluteExpiry()).toEqual(1500);
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns empty session if no membership events are present", () => {
|
it("returns empty session if no membership events are present", () => {
|
||||||
const mockRoom = makeMockRoom([], testConfig.testCreateSticky);
|
const mockRoom = makeMockRoom([], testConfig.testCreateSticky);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess?.memberships).toHaveLength(0);
|
expect(sess?.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -185,7 +257,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
} as unknown as EventTimeline);
|
} as unknown as EventTimeline);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess.memberships).toHaveLength(0);
|
expect(sess.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -216,7 +293,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
} as unknown as EventTimeline);
|
} as unknown as EventTimeline);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess.memberships).toHaveLength(0);
|
expect(sess.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -224,7 +306,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
const testMembership = Object.assign({}, membershipTemplate);
|
const testMembership = Object.assign({}, membershipTemplate);
|
||||||
(testMembership.device_id as string | undefined) = undefined;
|
(testMembership.device_id as string | undefined) = undefined;
|
||||||
const mockRoom = makeMockRoom([testMembership]);
|
const mockRoom = makeMockRoom([testMembership]);
|
||||||
const sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
const sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess.memberships).toHaveLength(0);
|
expect(sess.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -232,7 +319,12 @@ describe("MatrixRTCSession", () => {
|
|||||||
const testMembership = Object.assign({}, membershipTemplate);
|
const testMembership = Object.assign({}, membershipTemplate);
|
||||||
(testMembership.call_id as string | undefined) = undefined;
|
(testMembership.call_id as string | undefined) = undefined;
|
||||||
const mockRoom = makeMockRoom([testMembership]);
|
const mockRoom = makeMockRoom([testMembership]);
|
||||||
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
|
sess = MatrixRTCSession.sessionForRoom(
|
||||||
|
client,
|
||||||
|
mockRoom,
|
||||||
|
callSession,
|
||||||
|
testConfig.createWithDefaults ? undefined : testConfig,
|
||||||
|
);
|
||||||
expect(sess.memberships).toHaveLength(0);
|
expect(sess.memberships).toHaveLength(0);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM
|
|||||||
this.refreshRoom(room);
|
this.refreshRoom(room);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onEvent = (event: MatrixEvent): void => {
|
private readonly onEvent = (event: MatrixEvent): void => {
|
||||||
if (!event.unstableStickyExpiresAt) {
|
if (!event.unstableStickyExpiresAt) {
|
||||||
return; // Not sticky, not interested.
|
return; // Not sticky, not interested.
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM
|
|||||||
this.refreshRoom(room);
|
this.refreshRoom(room);
|
||||||
};
|
};
|
||||||
|
|
||||||
private onRoomState = (event: MatrixEvent): void => {
|
private readonly onRoomState = (event: MatrixEvent): void => {
|
||||||
if (event.getType() !== EventType.GroupCallMemberPrefix) {
|
if (event.getType() !== EventType.GroupCallMemberPrefix) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ export class MembershipManager
|
|||||||
implements IMembershipManager
|
implements IMembershipManager
|
||||||
{
|
{
|
||||||
private activated = false;
|
private activated = false;
|
||||||
private logger: Logger;
|
private readonly logger: Logger;
|
||||||
private callIntent: RTCCallIntent | undefined;
|
private callIntent: RTCCallIntent | undefined;
|
||||||
|
|
||||||
public isActivated(): boolean {
|
public isActivated(): boolean {
|
||||||
@@ -329,10 +329,10 @@ export class MembershipManager
|
|||||||
* @param getOldestMembership
|
* @param getOldestMembership
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
private joinConfig: (SessionConfig & MembershipConfig) | undefined,
|
private readonly joinConfig: (SessionConfig & MembershipConfig) | undefined,
|
||||||
protected room: Pick<Room, "roomId" | "getVersion">,
|
protected readonly room: Pick<Room, "roomId" | "getVersion">,
|
||||||
private client: MembershipManagerClient,
|
private readonly client: MembershipManagerClient,
|
||||||
private getOldestMembership: () => CallMembership | undefined,
|
private readonly getOldestMembership: () => CallMembership | undefined,
|
||||||
public readonly sessionDescription: SessionDescription,
|
public readonly sessionDescription: SessionDescription,
|
||||||
parentLogger?: Logger,
|
parentLogger?: Logger,
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user