Skip to content

Commit 2abf7ca

Browse files
authored
Allow multiple rtc sessions per room (with different sessionDescriptions) (#4945)
* Introduce sessionDescription Signed-off-by: Timo K <[email protected]> * Make sessionDescription part of a MatrixRTCSession Signed-off-by: Timo K <[email protected]> * Make session manager only menage session for one sessionDescription Signed-off-by: Timo K <[email protected]> * make membership manager aware about session (application + id) Before this was just hardcoded to a call session Signed-off-by: Timo K <[email protected]> * update tests Signed-off-by: Timo K <[email protected]> * fix doc comments Signed-off-by: Timo K <[email protected]> * Make fields private, improve comments, improve whitespace, don't use deprecated fields Signed-off-by: Timo K <[email protected]> * add test for other application end event Signed-off-by: Timo K <[email protected]> * rename call -> session Signed-off-by: Timo K <[email protected]> * fix tests Signed-off-by: Timo K <[email protected]> * remove id check since its already part of `deepCompare(membership.sessionDescription, sessionDescription)` Signed-off-by: Timo K <[email protected]> * remove scope related tests. The id should be the only thing that scopes sessions. everything else is application (session type) specific Signed-off-by: Timo K <[email protected]> * review Signed-off-by: Timo K <[email protected]> * add test for custom sessionDescription Signed-off-by: Timo K <[email protected]> * callMembershipsForRoom to default to call Signed-off-by: Timo K <[email protected]> * roomSessionForRoom backwards compatible (And deprecate the call specific method) Signed-off-by: Timo K <[email protected]> --------- Signed-off-by: Timo K <[email protected]>
1 parent 2b46579 commit 2abf7ca

File tree

7 files changed

+263
-114
lines changed

7 files changed

+263
-114
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 37 additions & 51 deletions
Large diffs are not rendered by default.

spec/unit/matrixrtc/MatrixRTCSessionManager.spec.ts

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ limitations under the License.
1616

1717
import { ClientEvent, EventTimeline, MatrixClient } from "../../../src";
1818
import { RoomStateEvent } from "../../../src/models/room-state";
19-
import { MatrixRTCSessionManagerEvents } from "../../../src/matrixrtc/MatrixRTCSessionManager";
19+
import { MatrixRTCSessionManager, MatrixRTCSessionManagerEvents } from "../../../src/matrixrtc/MatrixRTCSessionManager";
2020
import { makeMockRoom, membershipTemplate, mockRoomState } from "./mocks";
21+
import { logger } from "../../../src/logger";
2122

2223
describe("MatrixRTCSessionManager", () => {
2324
let client: MatrixClient;
@@ -47,6 +48,21 @@ describe("MatrixRTCSessionManager", () => {
4748
}
4849
});
4950

51+
it("Doesn't fire event if unrelated sessions starts", () => {
52+
const onStarted = jest.fn();
53+
client.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionStarted, onStarted);
54+
55+
try {
56+
const room1 = makeMockRoom([{ ...membershipTemplate, application: "m.other" }]);
57+
jest.spyOn(client, "getRooms").mockReturnValue([room1]);
58+
59+
client.emit(ClientEvent.Room, room1);
60+
expect(onStarted).not.toHaveBeenCalled();
61+
} finally {
62+
client.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, onStarted);
63+
}
64+
});
65+
5066
it("Fires event when session ends", () => {
5167
const onEnded = jest.fn();
5268
client.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, onEnded);
@@ -59,9 +75,75 @@ describe("MatrixRTCSessionManager", () => {
5975
mockRoomState(room1, [{ user_id: membershipTemplate.user_id }]);
6076

6177
const roomState = room1.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
62-
const membEvent = roomState.getStateEvents("")[0];
78+
const membEvent = roomState.getStateEvents("org.matrix.msc3401.call.member")[0];
6379
client.emit(RoomStateEvent.Events, membEvent, roomState, null);
6480

6581
expect(onEnded).toHaveBeenCalledWith(room1.roomId, client.matrixRTC.getActiveRoomSession(room1));
6682
});
83+
84+
it("Fires correctly with for with custom sessionDescription", () => {
85+
const onStarted = jest.fn();
86+
const onEnded = jest.fn();
87+
// create a session manager with a custom session description
88+
const sessionManager = new MatrixRTCSessionManager(logger, client, { id: "test", application: "m.notCall" });
89+
90+
// manually start the session manager (its not the default one started by the client)
91+
sessionManager.start();
92+
sessionManager.on(MatrixRTCSessionManagerEvents.SessionEnded, onEnded);
93+
sessionManager.on(MatrixRTCSessionManagerEvents.SessionStarted, onStarted);
94+
95+
try {
96+
const room1 = makeMockRoom([{ ...membershipTemplate, application: "m.other" }]);
97+
jest.spyOn(client, "getRooms").mockReturnValue([room1]);
98+
99+
client.emit(ClientEvent.Room, room1);
100+
expect(onStarted).not.toHaveBeenCalled();
101+
onStarted.mockClear();
102+
103+
const room2 = makeMockRoom([{ ...membershipTemplate, application: "m.notCall", call_id: "test" }]);
104+
jest.spyOn(client, "getRooms").mockReturnValue([room1, room2]);
105+
106+
client.emit(ClientEvent.Room, room2);
107+
expect(onStarted).toHaveBeenCalled();
108+
onStarted.mockClear();
109+
110+
mockRoomState(room2, [{ user_id: membershipTemplate.user_id }]);
111+
jest.spyOn(client, "getRoom").mockReturnValue(room2);
112+
113+
const roomState = room2.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
114+
const membEvent = roomState.getStateEvents("org.matrix.msc3401.call.member")[0];
115+
client.emit(RoomStateEvent.Events, membEvent, roomState, null);
116+
expect(onEnded).toHaveBeenCalled();
117+
onEnded.mockClear();
118+
119+
mockRoomState(room1, [{ user_id: membershipTemplate.user_id }]);
120+
jest.spyOn(client, "getRoom").mockReturnValue(room1);
121+
122+
const roomStateOther = room1.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
123+
const membEventOther = roomStateOther.getStateEvents("org.matrix.msc3401.call.member")[0];
124+
client.emit(RoomStateEvent.Events, membEventOther, roomStateOther, null);
125+
expect(onEnded).not.toHaveBeenCalled();
126+
} finally {
127+
client.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionStarted, onStarted);
128+
client.matrixRTC.off(MatrixRTCSessionManagerEvents.SessionEnded, onEnded);
129+
}
130+
});
131+
132+
it("Doesn't fire event if unrelated sessions ends", () => {
133+
const onEnded = jest.fn();
134+
client.matrixRTC.on(MatrixRTCSessionManagerEvents.SessionEnded, onEnded);
135+
const room1 = makeMockRoom([{ ...membershipTemplate, application: "m.other_app" }]);
136+
jest.spyOn(client, "getRooms").mockReturnValue([room1]);
137+
jest.spyOn(client, "getRoom").mockReturnValue(room1);
138+
139+
client.emit(ClientEvent.Room, room1);
140+
141+
mockRoomState(room1, [{ user_id: membershipTemplate.user_id }]);
142+
143+
const roomState = room1.getLiveTimeline().getState(EventTimeline.FORWARDS)!;
144+
const membEvent = roomState.getStateEvents("org.matrix.msc3401.call.member")[0];
145+
client.emit(RoomStateEvent.Events, membEvent, roomState, null);
146+
147+
expect(onEnded).not.toHaveBeenCalledWith(room1.roomId, client.matrixRTC.getActiveRoomSession(room1));
148+
});
67149
});

0 commit comments

Comments
 (0)