Compare commits

...
Author SHA1 Message Date
Timo K. d3c94ac888 Fix the key collision due to url 2026-10-27 20:13:59 +01:00
3 changed files with 56 additions and 8 deletions
+9 -2
View File
@@ -139,12 +139,19 @@ test("Subscriber falls back to the JWT service when the homeserver lacks MSC4195
await SpaHelpers.createCall(page, "Androl", "HelloCall", true);
const inviteLink = await SpaHelpers.getCallInviteLink(page);
// The guest joins but their C-S requests fail.
// The guest joins from the other homeserver, whose SFU it publishes on, but
// their C-S requests fail. On the host's homeserver the guest would publish
// on the host's JWT service and need no subscriber connection.
const guestContext = await browser.newContext({ reducedMotion: "reduce" });
const guestPage = await guestContext.newPage();
await useHomeserver(guestPage, otherHomeserver);
await rejectCsApiTokens(guestPage);
const guestRequests = recordAuthRequests(guestPage);
await SpaHelpers.joinCallFromInviteLink(guestPage, inviteLink, "Pevara");
await SpaHelpers.joinCallFromInviteLink(
guestPage,
`${inviteLink}&viaServers=synapse.m.localhost`,
"Pevara",
);
// Wait for the call to connect and render.
await SpaHelpers.expectVideoTilesCount(page, 2);
@@ -207,6 +207,44 @@ describe("connections$ stream", () => {
});
});
test("Shares one connection between transports with and without a url for the same JWT service", () => {
withTestScheduler(({ behavior, expectObservable }) => {
const service = "https://lk.elsewhere.org";
const withUrl: TransportLocator = {
transport: {
type: "livekit",
url: "wss://sfu.elsewhere.org",
livekit_service_url: service,
},
serverName: "elsewhere.org",
};
const withoutUrl: TransportLocator = {
transport: { type: "livekit", livekit_service_url: service },
serverName: "elsewhere.org",
};
const connectionMap$ = createConnectionMap$({
scope: testScope,
connectionFactory: fakeConnectionFactory,
localTransport: TRANSPORT_1,
remoteTransports$: behavior("a", {
a: new Epoch([withUrl, withoutUrl], 0),
}),
logger: logger,
ownMembershipIdentity: ownMemberMock,
});
expectObservable(connectionMap$).toBe("a", {
a: expect.toSatisfy((e: Epoch<ConnectionMap>) => {
expect(e.value.getConnections().length).toBe(2);
expect(e.value.getConnectionForTransport(withoutUrl)).toBe(
e.value.getConnectionForTransport(withUrl),
);
return true;
}),
});
});
});
test("Keeps one connection per homeserver for transports with a url", () => {
withTestScheduler(({ behavior, expectObservable }) => {
const urlTransport: TransportLocator = {
@@ -31,18 +31,21 @@ export type TransportKey = string & { __transportKey: true };
* for a transport with a `url`, where our homeserver asks that server for the
* token. A JWT service is reached directly, so members of several homeservers
* advertising the same one share a connection rather than each get their own.
*
* A `url` or a `livekit_server_url` are not part of the key: the service decides the
* LiveKit room either way, and the SFU disconnects the first of two
* connections joining it under one identity. -> we have to achive: same SFU with the same key.
*
* We assume one SFU per homeserver. So we just use the serverName as the key.
*/
export function keyFor({
transport,
serverName,
}: TransportLocator): TransportKey {
const hasUrl = "url" in transport;
// Serialize the fields in a consistent order
return JSON.stringify([
hasUrl ? transport.url : null,
"livekit_service_url" in transport ? transport.livekit_service_url : null,
hasUrl ? serverName : null,
]) as TransportKey;
// Right now we can assume one SFU per server. even if the server advertises multiple,
// we will end up with just the first one on all participants.
return serverName as TransportKey;
}
function removeDuplicateTransports(