Skip to content

Commit 61b05a0

Browse files
committed
review valere
Signed-off-by: Timo K <[email protected]>
1 parent b4abbfc commit 61b05a0

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

spec/unit/matrixrtc/CallMembership.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,35 @@ describe("CallMembership", () => {
8181
});
8282

8383
it("returns preferred foci", () => {
84-
const mockFocus = { type: "this_is_a_mock_focus" };
84+
const mockFocus = { type: "livekit", livekit_service_url: "https://example.org" };
8585
const fakeEvent = makeMockEvent(0, { ...membershipTemplate, foci_preferred: [mockFocus] });
8686
const membership = new CallMembership(fakeEvent);
87-
expect(membership.transports).toEqual([mockFocus]);
87+
expect(membership.transports.length).toEqual(1);
88+
expect(membership.transports[0]).toEqual(expect.objectContaining({ type: "livekit" }));
8889
});
8990

9091
describe("getTransport", () => {
91-
const mockFocus = { type: "this_is_a_mock_focus" };
92+
const mockFocus = { type: "livekit", livekit_service_url: "https://example.org" };
9293
const oldestMembership = new CallMembership(makeMockEvent(0, membershipTemplate));
9394
it("gets the correct active transport with oldest_membership", () => {
9495
const membership = new CallMembership(
9596
makeMockEvent(0, {
9697
...membershipTemplate,
98+
// The list of foci_preferred provided by the homeserver. (in the test example we just provide one)
99+
// The oldest member logic will use the first item in this list.
100+
// The multi-sfu logic will (theoretically) also use all the items in the list at once
101+
// (currently the js-sdk sets it to only one item in multi-sfu mode).
97102
foci_preferred: [mockFocus],
98103
focus_active: { type: "livekit", focus_selection: "oldest_membership" },
99104
}),
100105
);
101106

102107
// if we are the oldest member we use our focus.
103-
expect(membership.getTransport(membership)).toStrictEqual(mockFocus);
108+
expect(membership.getTransport(membership)).toEqual(expect.objectContaining({ type: "livekit" }));
109+
expect(membership.transports[0]).toEqual(expect.objectContaining({ type: "livekit" }));
104110

105111
// If there is an older member we use its focus.
106-
expect(membership.getTransport(oldestMembership)).toBe(membershipTemplate.foci_preferred[0]);
112+
expect(membership.getTransport(oldestMembership)).toEqual(expect.objectContaining({ type: "livekit" }));
107113
});
108114

109115
it("gets the correct active transport with multi_sfu", () => {
@@ -115,7 +121,7 @@ describe("CallMembership", () => {
115121
}),
116122
);
117123

118-
// if we are the oldest member we use our focus.
124+
// We use our focus.
119125
expect(membership.getTransport(membership)).toStrictEqual(mockFocus);
120126

121127
// If there is an older member we still use our own focus in multi sfu.
@@ -130,7 +136,6 @@ describe("CallMembership", () => {
130136
}),
131137
);
132138

133-
// if we are the oldest member we use our focus.
134139
expect(membership.getTransport(membership)).toBeUndefined();
135140
});
136141
});

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
} from "./mocks";
3939
import { RTCEncryptionManager } from "../../../src/matrixrtc/RTCEncryptionManager.ts";
4040

41-
const mockFocus = { type: "mock" };
41+
const mockFocus = { type: "livekit", livekit_service_url: "https://test.org" };
4242

4343
const textEncoder = new TextEncoder();
4444

src/matrixrtc/CallMembership.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { RTCCallIntent, Transport } from "./types.ts";
2222
import { type IContent, type MatrixEvent } from "../models/event.ts";
2323
import { type RelationType } from "../@types/event.ts";
2424
import { logger } from "../logger.ts";
25+
import { UNSTABLE_STICKY_KEY, type StickyKeyContent } from "src/models/room-sticky-events.ts";
2526

2627
/**
2728
* The default duration in milliseconds that a membership is considered valid for.
@@ -33,7 +34,7 @@ export const DEFAULT_EXPIRE_DURATION = 1000 * 60 * 60 * 4;
3334
type CallScope = "m.room" | "m.user";
3435
type Member = { user_id: string; device_id: string; id: string };
3536

36-
export interface RtcMembershipData {
37+
export type RtcMembershipData = {
3738
"slot_id": string;
3839
"member": Member;
3940
"m.relates_to"?: {
@@ -47,9 +48,7 @@ export interface RtcMembershipData {
4748
};
4849
"rtc_transports": Transport[];
4950
"versions": string[];
50-
"msc4354_sticky_key"?: string;
51-
"sticky_key"?: string;
52-
}
51+
} & StickyKeyContent;
5352

5453
const checkRtcMembershipData = (
5554
data: IContent,
@@ -103,19 +102,19 @@ const checkRtcMembershipData = (
103102
}
104103

105104
// optional fields
106-
if ((data.sticky_key ?? data.msc4354_sticky_key) === undefined) {
105+
if ((data[UNSTABLE_STICKY_KEY.name] ?? data[UNSTABLE_STICKY_KEY.altName]) === undefined) {
107106
errors.push(prefix + "sticky_key or msc4354_sticky_key must be a defined");
108107
}
109-
if (data.sticky_key !== undefined && typeof data.sticky_key !== "string") {
108+
if (data[UNSTABLE_STICKY_KEY.name] !== undefined && typeof data[UNSTABLE_STICKY_KEY.name] !== "string") {
110109
errors.push(prefix + "sticky_key must be a string");
111110
}
112-
if (data.msc4354_sticky_key !== undefined && typeof data.msc4354_sticky_key !== "string") {
111+
if (data[UNSTABLE_STICKY_KEY.altName] !== undefined && typeof data[UNSTABLE_STICKY_KEY.altName] !== "string") {
113112
errors.push(prefix + "msc4354_sticky_key must be a string");
114113
}
115114
if (
116-
data.sticky_key !== undefined &&
117-
data.msc4354_sticky_key !== undefined &&
118-
data.sticky_key !== data.msc4354_sticky_key
115+
data[UNSTABLE_STICKY_KEY.name] !== undefined &&
116+
data[UNSTABLE_STICKY_KEY.altName] !== undefined &&
117+
data[UNSTABLE_STICKY_KEY.name] !== data[UNSTABLE_STICKY_KEY.altName]
119118
) {
120119
errors.push(prefix + "sticky_key and msc4354_sticky_key must be equal if both are defined");
121120
}

src/models/room-sticky-events.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { type EitherAnd, UnstableValue } from "matrix-events-sdk";
18+
119
import { logger as loggerInstance } from "../logger.ts";
220
import { type MatrixEvent } from "./event.ts";
321
import { TypedEventEmitter } from "./typed-event-emitter.ts";
422

523
const logger = loggerInstance.getChild("RoomStickyEvents");
624

25+
export const UNSTABLE_STICKY_KEY = new UnstableValue("sticky_key", "msc4354_sticky_key");
26+
export type StickyKeyContent = EitherAnd<
27+
{ [UNSTABLE_STICKY_KEY.name]: string },
28+
{ [UNSTABLE_STICKY_KEY.altName]: string }
29+
>;
30+
731
export enum RoomStickyEventsEvent {
832
Update = "RoomStickyEvents.Update",
933
}

0 commit comments

Comments
 (0)