From 1b4f097b1cc69794af480530717b0ff0c9c51d28 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 1 Sep 2022 11:41:22 +0100 Subject: [PATCH] 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 --- src/room/useLoadGroupCall.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/room/useLoadGroupCall.ts b/src/room/useLoadGroupCall.ts index a741b90..96edc5d 100644 --- a/src/room/useLoadGroupCall.ts +++ b/src/room/useLoadGroupCall.ts @@ -22,6 +22,7 @@ import { } 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"; @@ -53,7 +54,7 @@ export const useLoadGroupCall = ( const waitPromise = new Promise((resolve) => { const onRoomEvent = async (room: Room) => { if (room.roomId === roomId) { - client.removeListener(ClientEvent.Room, onRoomEvent); + client.removeListener(GroupCallEventHandlerEvent.Room, onRoomEvent); resolve(room); } }; @@ -74,6 +75,7 @@ export const useLoadGroupCall = ( 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); @@ -100,7 +102,9 @@ export const useLoadGroupCall = ( const fetchOrCreateGroupCall = async (): Promise => { 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 +115,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,