From ee1dd2293ea2f1b9d6f437e34e085285c24a697d Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 6 Sep 2022 11:57:07 +0100 Subject: [PATCH 1/3] 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 --- src/room/useLoadGroupCall.ts | 39 ++++++++---------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/src/room/useLoadGroupCall.ts b/src/room/useLoadGroupCall.ts index 4c7af1d..37fcf5e 100644 --- a/src/room/useLoadGroupCall.ts +++ b/src/room/useLoadGroupCall.ts @@ -45,39 +45,15 @@ export const useLoadGroupCall = ( useEffect(() => { setState({ loading: true }); - const waitForRoom = async (roomId: string): Promise => { - const room = client.getRoom(roomId); - if (room) return room; - console.log(`Room ${roomId} hasn't arrived yet: waiting`); - - const waitPromise = new Promise((resolve) => { - const onRoomEvent = async (room: Room) => { - if (room.roomId === roomId) { - client.removeListener(GroupCallEventHandlerEvent.Room, onRoomEvent); - resolve(room); - } - }; - client.on(GroupCallEventHandlerEvent.Room, onRoomEvent); - }); - - // race the promise with a timeout so we don't - // wait forever for the room - const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { - reject(new Error("Timed out trying to join room")); - }, 30000); - }); - - return Promise.race([waitPromise, timeoutPromise]); - }; - const fetchOrCreateRoom = async (): Promise => { try { const room = await client.joinRoom(roomIdOrAlias, { viaServers }); - logger.info(`Joined ${roomIdOrAlias}, waiting for Room event`); - // 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) && @@ -92,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; } From 30a270193f17b63ec7062bf319145c041a495c89 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 6 Sep 2022 12:14:24 +0100 Subject: [PATCH 2/3] Use js-sdk branch --- package.json | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9f42385..666f121 100644 --- a/package.json +++ b/package.json @@ -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#da5bc358f40e1e9de39d28aea072a9c38e356bda", + "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#3e8607a77b363e162358995ad6c4c7ce6c7fb168", "matrix-widget-api": "^1.0.0", "mermaid": "^8.13.8", "normalize.css": "^8.0.1", diff --git a/yarn.lock b/yarn.lock index 7dda879..615f7ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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#da5bc358f40e1e9de39d28aea072a9c38e356bda": +"matrix-js-sdk@github:matrix-org/matrix-js-sdk#3e8607a77b363e162358995ad6c4c7ce6c7fb168": version "19.3.0" - resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/da5bc358f40e1e9de39d28aea072a9c38e356bda" + resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/3e8607a77b363e162358995ad6c4c7ce6c7fb168" dependencies: "@babel/runtime" "^7.12.5" "@types/sdp-transform" "^2.4.5" From 22dd095ea975169a79c85c79a8a797b15c6ae35d Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 6 Sep 2022 13:55:32 +0100 Subject: [PATCH 3/3] Update js-sdk to latest on group-call branch --- package.json | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 666f121..230e080 100644 --- a/package.json +++ b/package.json @@ -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#3e8607a77b363e162358995ad6c4c7ce6c7fb168", + "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", diff --git a/yarn.lock b/yarn.lock index 615f7ec..b654f81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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#3e8607a77b363e162358995ad6c4c7ce6c7fb168": +"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/3e8607a77b363e162358995ad6c4c7ce6c7fb168" + 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"