Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add creation of room by visiting the URL #1724

Draft
wants to merge 1 commit into
base: livekit
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions src/room/useLoadGroupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { SyncState } from "matrix-js-sdk/src/sync";
import { useTranslation } from "react-i18next";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSession";
import { MatrixError } from "matrix-js-sdk";

import type { Room } from "matrix-js-sdk/src/models/room";
import type { GroupCall } from "matrix-js-sdk/src/webrtc/groupCall";
import { useEnableE2EE } from "../settings/useSetting";
import { createRoom, isLocalRoomId, roomNameFromRoomId } from "../matrix-utils";

export type GroupCallLoaded = {
kind: "loaded";
Expand Down Expand Up @@ -69,20 +71,40 @@ export const useLoadGroupCall = (
// Also, we explicitly look up the room alias here. We previously just tried to
// join anyway but the js-sdk recreates the room if you pass the alias for a
// room you're already joined to (which it probably ought not to).
const lookupResult = await client.getRoomIdForAlias(
roomIdOrAlias.toLowerCase()
);
logger.info(`${roomIdOrAlias} resolved to ${lookupResult.room_id}`);
room = client.getRoom(lookupResult.room_id);
if (!room) {
logger.info(`Room ${lookupResult.room_id} not found, joining.`);
room = await client.joinRoom(lookupResult.room_id, {
viaServers: lookupResult.servers,
});
} else {
logger.info(
`Already in room ${lookupResult.room_id}, not rejoining.`
try {
const lookupResult = await client.getRoomIdForAlias(
roomIdOrAlias.toLowerCase()
);
logger.info(`${roomIdOrAlias} resolved to ${lookupResult.room_id}`);
room = client.getRoom(lookupResult.room_id);
if (!room) {
logger.info(`Room ${lookupResult.room_id} not found, joining.`);
room = await client.joinRoom(lookupResult.room_id, {
viaServers: lookupResult.servers,
});
} else {
logger.info(
`Already in room ${lookupResult.room_id}, not rejoining.`
);
}
} catch (e) {
if (
isLocalRoomId(roomIdOrAlias, client) &&
(e as MatrixError).errcode === "M_NOT_FOUND"
) {
// legacy path: create an unencrypted room if the user lands on a URL for a room that
// doesn't exist
const result = await createRoom(
client,
roomNameFromRoomId(roomIdOrAlias),
false
);

await client.waitUntilRoomReadyForGroupCalls(result.roomId);
return client.getRoom(result.roomId)!;
}

throw e;
}
} else {
// room IDs we just try to join by their ID, which will not work in the
Expand Down