Skip to content

Commit d70e4f7

Browse files
committed
Small improvements
Signed-off-by: Timo K <[email protected]>
1 parent 8f157da commit d70e4f7

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,40 +102,40 @@ describe("MatrixRTCSession", () => {
102102
if (testConfig.listenForMemberStateEvents) {
103103
// eslint-disable-next-line jest/no-conditional-expect
104104
expect(() => {
105-
MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
105+
MatrixRTCSession.sessionForSlot(client, mockRoom, callSession, testConfig);
106106
}).toThrow();
107107
} else {
108108
// eslint-disable-next-line jest/no-conditional-expect
109109
expect(() => {
110-
MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, testConfig);
110+
MatrixRTCSession.sessionForSlot(client, mockRoom, callSession, testConfig);
111111
}).not.toThrow();
112112
}
113113
});
114114

115115
it("creates a room-scoped session from room state", () => {
116116
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
117117

118-
sess = MatrixRTCSession.sessionForRoom(
118+
sess = MatrixRTCSession.sessionForSlot(
119119
client,
120120
mockRoom,
121121
callSession,
122122
testConfig.createWithDefaults ? undefined : testConfig,
123123
);
124124
expect(sess?.memberships.length).toEqual(1);
125-
expect(sess?.memberships[0].sessionDescription.id).toEqual("");
125+
expect(sess?.memberships[0].slotDescription.id).toEqual("");
126126
expect(sess?.memberships[0].scope).toEqual("m.room");
127127
expect(sess?.memberships[0].application).toEqual("m.call");
128128
expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA");
129129
expect(sess?.memberships[0].isExpired()).toEqual(false);
130-
expect(sess?.sessionDescription.id).toEqual("");
130+
expect(sess?.slotDescription.id).toEqual("");
131131
});
132132

133133
it("ignores memberships where application is not m.call", () => {
134134
const testMembership = Object.assign({}, membershipTemplate, {
135135
application: "not-m.call",
136136
});
137137
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
138-
const sess = MatrixRTCSession.sessionForRoom(
138+
const sess = MatrixRTCSession.sessionForSlot(
139139
client,
140140
mockRoom,
141141
callSession,
@@ -150,7 +150,7 @@ describe("MatrixRTCSession", () => {
150150
scope: "m.room",
151151
});
152152
const mockRoom = makeMockRoom([testMembership], testConfig.testCreateSticky);
153-
const sess = MatrixRTCSession.sessionForRoom(
153+
const sess = MatrixRTCSession.sessionForSlot(
154154
client,
155155
mockRoom,
156156
callSession,
@@ -167,7 +167,7 @@ describe("MatrixRTCSession", () => {
167167
const mockRoom = makeMockRoom([membershipTemplate, expiredMembership], testConfig.testCreateSticky);
168168

169169
jest.advanceTimersByTime(2000);
170-
sess = MatrixRTCSession.sessionForRoom(
170+
sess = MatrixRTCSession.sessionForSlot(
171171
client,
172172
mockRoom,
173173
callSession,
@@ -181,7 +181,7 @@ describe("MatrixRTCSession", () => {
181181
it("ignores memberships events of members not in the room", () => {
182182
const mockRoom = makeMockRoom([membershipTemplate], testConfig.testCreateSticky);
183183
mockRoom.hasMembershipState.mockImplementation((state) => state === KnownMembership.Join);
184-
sess = MatrixRTCSession.sessionForRoom(
184+
sess = MatrixRTCSession.sessionForSlot(
185185
client,
186186
mockRoom,
187187
callSession,
@@ -194,7 +194,7 @@ describe("MatrixRTCSession", () => {
194194
// Force the sender to be undefined.
195195
const mockRoom = makeMockRoom([{ ...membershipTemplate, user_id: "" }], testConfig.testCreateSticky);
196196
mockRoom.hasMembershipState.mockImplementation((state) => state === KnownMembership.Join);
197-
sess = MatrixRTCSession.sessionForRoom(
197+
sess = MatrixRTCSession.sessionForSlot(
198198
client,
199199
mockRoom,
200200
callSession,
@@ -210,7 +210,7 @@ describe("MatrixRTCSession", () => {
210210
expiredMembership.created_ts = 500;
211211
expiredMembership.expires = 1000;
212212
const mockRoom = makeMockRoom([expiredMembership], testConfig.testCreateSticky);
213-
sess = MatrixRTCSession.sessionForRoom(
213+
sess = MatrixRTCSession.sessionForSlot(
214214
client,
215215
mockRoom,
216216
callSession,
@@ -222,7 +222,7 @@ describe("MatrixRTCSession", () => {
222222

223223
it("returns empty session if no membership events are present", () => {
224224
const mockRoom = makeMockRoom([], testConfig.testCreateSticky);
225-
sess = MatrixRTCSession.sessionForRoom(
225+
sess = MatrixRTCSession.sessionForSlot(
226226
client,
227227
mockRoom,
228228
callSession,
@@ -258,7 +258,7 @@ describe("MatrixRTCSession", () => {
258258
]),
259259
}),
260260
} as unknown as EventTimeline);
261-
sess = MatrixRTCSession.sessionForRoom(
261+
sess = MatrixRTCSession.sessionForSlot(
262262
client,
263263
mockRoom,
264264
callSession,
@@ -294,7 +294,7 @@ describe("MatrixRTCSession", () => {
294294
]),
295295
}),
296296
} as unknown as EventTimeline);
297-
sess = MatrixRTCSession.sessionForRoom(
297+
sess = MatrixRTCSession.sessionForSlot(
298298
client,
299299
mockRoom,
300300
callSession,
@@ -307,7 +307,7 @@ describe("MatrixRTCSession", () => {
307307
const testMembership = Object.assign({}, membershipTemplate);
308308
(testMembership.device_id as string | undefined) = undefined;
309309
const mockRoom = makeMockRoom([testMembership]);
310-
const sess = MatrixRTCSession.sessionForRoom(
310+
const sess = MatrixRTCSession.sessionForSlot(
311311
client,
312312
mockRoom,
313313
callSession,
@@ -320,7 +320,7 @@ describe("MatrixRTCSession", () => {
320320
const testMembership = Object.assign({}, membershipTemplate);
321321
(testMembership.call_id as string | undefined) = undefined;
322322
const mockRoom = makeMockRoom([testMembership]);
323-
sess = MatrixRTCSession.sessionForRoom(
323+
sess = MatrixRTCSession.sessionForSlot(
324324
client,
325325
mockRoom,
326326
callSession,
@@ -347,7 +347,7 @@ describe("MatrixRTCSession", () => {
347347
});
348348

349349
// Expect for there to be one membership as the state has been merged down.
350-
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, {
350+
sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession, {
351351
listenForStickyEvents: true,
352352
listenForMemberStateEvents: true,
353353
});
@@ -377,15 +377,15 @@ describe("MatrixRTCSession", () => {
377377
return [ev as StickyMatrixEvent];
378378
});
379379

380-
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, {
380+
sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession, {
381381
listenForStickyEvents: true,
382382
listenForMemberStateEvents: true,
383383
});
384384

385385
const memberships = sess.memberships;
386386
expect(memberships.length).toEqual(2);
387387
expect(memberships[0].sender).toEqual(stickyUserId);
388-
expect(memberships[0].sessionDescription.id).toEqual("");
388+
expect(memberships[0].slotDescription.id).toEqual("");
389389
expect(memberships[0].scope).toEqual("m.room");
390390
expect(memberships[0].application).toEqual("m.call");
391391
expect(memberships[0].deviceId).toEqual("AAAAAAA");
@@ -394,13 +394,13 @@ describe("MatrixRTCSession", () => {
394394
// Then state
395395
expect(memberships[1].sender).toEqual(membershipTemplate.user_id);
396396

397-
expect(sess?.sessionDescription.id).toEqual("");
397+
expect(sess?.slotDescription.id).toEqual("");
398398
});
399399
it("handles an incoming sticky event to an existing session", () => {
400400
const mockRoom = makeMockRoom([membershipTemplate]);
401401
const stickyUserId = "@stickyev:user.example";
402402

403-
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession, {
403+
sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession, {
404404
listenForStickyEvents: true,
405405
listenForMemberStateEvents: true,
406406
});

src/matrixrtc/MatrixRTCSessionManager.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,13 @@ export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionM
116116
};
117117

118118
private readonly onEvent = (event: MatrixEvent): void => {
119-
if (!event.unstableStickyExpiresAt) {
120-
return; // Not sticky, not interested.
121-
}
122-
if (event.getType() !== EventType.GroupCallMemberPrefix) {
123-
return;
124-
}
119+
if (!event.unstableStickyExpiresAt) return; // Not sticky, not interested.
120+
121+
if (event.getType() !== EventType.GroupCallMemberPrefix) return;
122+
125123
const room = this.client.getRoom(event.getRoomId());
126-
if (!room) {
127-
return;
128-
}
124+
if (!room) return;
125+
129126
this.refreshRoom(room);
130127
};
131128

src/matrixrtc/MembershipManager.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,18 +1058,12 @@ export class StickyEventMembershipManager extends MembershipManager {
10581058
);
10591059
};
10601060

1061-
protected actionUpdateFromErrors(
1062-
error: unknown,
1063-
type: MembershipActionType,
1064-
method: string,
1065-
): ActionUpdate | undefined {
1066-
// Override method name.
1067-
if (method === "sendStateEvent") {
1068-
method = "_unstable_sendStickyEvent";
1069-
} else if (method === "_unstable_sendDelayedStateEvent") {
1070-
method = "_unstable_sendStickyDelayedEvent";
1071-
}
1072-
return super.actionUpdateFromErrors(error, type, method);
1061+
protected actionUpdateFromErrors(e: unknown, t: MembershipActionType, m: string): ActionUpdate | undefined {
1062+
const mappedMethod = new Map([
1063+
["sendStateEvent", "_unstable_sendStickyEvent"],
1064+
["_unstable_sendDelayedStateEvent", "_unstable_sendStickyDelayedEvent"],
1065+
]).get(m);
1066+
return super.actionUpdateFromErrors(e, t, mappedMethod ?? "unknown method");
10731067
}
10741068

10751069
protected makeMyMembership(expires: number): SessionMembershipData | RtcMembershipData {

0 commit comments

Comments
 (0)