Merge pull request #567 from vector-im/dbkr/waitUntilRoomReadyForGroupCalls

Use new method to wait until a room is ready for group calls
This commit is contained in:
David Baker 2022-09-06 14:00:06 +01:00 committed by GitHub
commit 7304411c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 34 deletions

View file

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

View file

@ -45,39 +45,15 @@ export const useLoadGroupCall = (
useEffect(() => { useEffect(() => {
setState({ loading: true }); 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(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<Room>((_, reject) => {
setTimeout(() => {
reject(new Error("Timed out trying to join room"));
}, 30000);
});
return Promise.race([waitPromise, timeoutPromise]);
};
const fetchOrCreateRoom = async (): Promise<Room> => { const fetchOrCreateRoom = async (): Promise<Room> => {
try { try {
const room = await client.joinRoom(roomIdOrAlias, { viaServers }); const room = await client.joinRoom(roomIdOrAlias, { viaServers });
logger.info(`Joined ${roomIdOrAlias}, waiting for Room event`); logger.info(
// wait for the room to come down the sync stream, otherwise `Joined ${roomIdOrAlias}, waiting room to be ready for group calls`
// client.getRoom() won't return the room. );
return waitForRoom(room.roomId); await client.waitUntilRoomReadyForGroupCalls(room.roomId);
logger.info(`${roomIdOrAlias}, is ready for group calls`);
return room;
} catch (error) { } catch (error) {
if ( if (
isLocalRoomId(roomIdOrAlias) && isLocalRoomId(roomIdOrAlias) &&
@ -92,7 +68,8 @@ export const useLoadGroupCall = (
createPtt createPtt
); );
// likewise, wait for the room // likewise, wait for the room
return await waitForRoom(roomId); await client.waitUntilRoomReadyForGroupCalls(roomId);
return client.getRoom(roomId);
} else { } else {
throw error; throw error;
} }

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" resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.7.tgz#5ffe45eba1f67cc8d7c2377736c728b322524934"
integrity sha512-9jl4wtWanUFSy2sr2lCjErN/oC8KTAtaeaozJtrgot1JiQcEI4Rda9OLgQ7nLKaqb4Z/QUx/fR3XpDzm5Jy1JA== 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#98d119d6e1d39f1c5b01b36e7fda133e9f12f50c":
version "19.3.0" 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/98d119d6e1d39f1c5b01b36e7fda133e9f12f50c"
dependencies: dependencies:
"@babel/runtime" "^7.12.5" "@babel/runtime" "^7.12.5"
"@types/sdp-transform" "^2.4.5" "@types/sdp-transform" "^2.4.5"