Compare commits

...

8 Commits

Author SHA1 Message Date
David Baker
7304411c5d Merge pull request #567 from vector-im/dbkr/waitUntilRoomReadyForGroupCalls
Use new method to wait until a room is ready for group calls
2022-09-06 14:00:06 +01:00
David Baker
22dd095ea9 Update js-sdk to latest on group-call branch 2022-09-06 13:55:32 +01:00
David Baker
30a270193f Use js-sdk branch 2022-09-06 12:14:24 +01:00
David Baker
ee1dd2293e Use new method to wait until a room is ready fopr group calls
We were waiting for the group call event handler to process the room,
but only if we couldn't get the room from the client - if getRoom returned
a room, we just wouldn't wait. This just uses promises rather than
an event to wait for the room to be ready.

Requires https://github.com/matrix-org/matrix-js-sdk/pull/2641
2022-09-06 11:57:07 +01:00
David Baker
34d5e88def Merge pull request #564 from vector-im/dbkr/fix_multiple_group_calls
Fix bug where additional group calls could be created
2022-09-01 16:18:43 +01:00
David Baker
30c9dfce02 Remove unused import 2022-09-01 13:36:02 +01:00
David Baker
48ad4d040d Actually wait for the right event
& update js-sdk dependency
2022-09-01 13:32:11 +01:00
David Baker
1b4f097b1c Fix bug where additional group calls could be created
This (hopefully) fixes the remaining bug where extra group calls
could be created when entering a room.

We waited for the Room event to arrive, but didn't wait for the
group call event handler to actually process the event, so it would
have depended what order the event handlers were run in.

If this doesn't fix it, it at least adds logging so we'll have more
to go on next time.

Fixes https://github.com/vector-im/element-call/issues/563
2022-09-01 11:41:22 +01:00
3 changed files with 19 additions and 35 deletions

View File

@@ -38,7 +38,7 @@
"classnames": "^2.3.1",
"color-hash": "^2.0.1",
"events": "^3.3.0",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#965f4fb13b4b36b26a3f4d7214cc7630d9f579a5",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#98d119d6e1d39f1c5b01b36e7fda133e9f12f50c",
"matrix-widget-api": "^1.0.0",
"mermaid": "^8.13.8",
"normalize.css": "^8.0.1",

View File

@@ -21,7 +21,7 @@ import {
GroupCallIntent,
} from "matrix-js-sdk/src/webrtc/groupCall";
import { GroupCallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/groupCallEventHandler";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Room } from "matrix-js-sdk/src/models/room";
@@ -45,38 +45,15 @@ export const useLoadGroupCall = (
useEffect(() => {
setState({ loading: true });
const waitForRoom = async (roomId: string): Promise<Room> => {
const room = client.getRoom(roomId);
if (room) return room;
console.log(`Room ${roomId} hasn't arrived yet: waiting`);
const waitPromise = new Promise<Room>((resolve) => {
const onRoomEvent = async (room: Room) => {
if (room.roomId === roomId) {
client.removeListener(ClientEvent.Room, onRoomEvent);
resolve(room);
}
};
client.on(ClientEvent.Room, onRoomEvent);
});
// race the promise with a timeout so we don't
// wait forever for the room
const timeoutPromise = new Promise<Room>((_, reject) => {
setTimeout(() => {
reject(new Error("Timed out trying to join room"));
}, 30000);
});
return Promise.race([waitPromise, timeoutPromise]);
};
const fetchOrCreateRoom = async (): Promise<Room> => {
try {
const room = await client.joinRoom(roomIdOrAlias, { viaServers });
// wait for the room to come down the sync stream, otherwise
// client.getRoom() won't return the room.
return waitForRoom(room.roomId);
logger.info(
`Joined ${roomIdOrAlias}, waiting room to be ready for group calls`
);
await client.waitUntilRoomReadyForGroupCalls(room.roomId);
logger.info(`${roomIdOrAlias}, is ready for group calls`);
return room;
} catch (error) {
if (
isLocalRoomId(roomIdOrAlias) &&
@@ -91,7 +68,8 @@ export const useLoadGroupCall = (
createPtt
);
// likewise, wait for the room
return await waitForRoom(roomId);
await client.waitUntilRoomReadyForGroupCalls(roomId);
return client.getRoom(roomId);
} else {
throw error;
}
@@ -100,7 +78,9 @@ export const useLoadGroupCall = (
const fetchOrCreateGroupCall = async (): Promise<GroupCall> => {
const room = await fetchOrCreateRoom();
logger.debug(`Fetched / joined room ${roomIdOrAlias}`);
const groupCall = client.getGroupCallForRoom(room.roomId);
logger.debug("Got group call", groupCall);
if (groupCall) return groupCall;
@@ -111,7 +91,11 @@ export const useLoadGroupCall = (
)
) {
// The call doesn't exist, but we can create it
console.log(`Creating ${createPtt ? "PTT" : "video"} group call room`);
console.log(
`No call found in ${roomIdOrAlias}: creating ${
createPtt ? "PTT" : "video"
} call`
);
return await client.createGroupCall(
room.roomId,
createPtt ? GroupCallType.Voice : GroupCallType.Video,

View File

@@ -8390,9 +8390,9 @@ matrix-events-sdk@^0.0.1-beta.7:
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.7.tgz#5ffe45eba1f67cc8d7c2377736c728b322524934"
integrity sha512-9jl4wtWanUFSy2sr2lCjErN/oC8KTAtaeaozJtrgot1JiQcEI4Rda9OLgQ7nLKaqb4Z/QUx/fR3XpDzm5Jy1JA==
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#965f4fb13b4b36b26a3f4d7214cc7630d9f579a5":
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#98d119d6e1d39f1c5b01b36e7fda133e9f12f50c":
version "19.3.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/965f4fb13b4b36b26a3f4d7214cc7630d9f579a5"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/98d119d6e1d39f1c5b01b36e7fda133e9f12f50c"
dependencies:
"@babel/runtime" "^7.12.5"
"@types/sdp-transform" "^2.4.5"