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
This commit is contained in:
parent
7b6193ab62
commit
1b4f097b1c
1 changed files with 10 additions and 2 deletions
|
@ -22,6 +22,7 @@ import {
|
||||||
} from "matrix-js-sdk/src/webrtc/groupCall";
|
} from "matrix-js-sdk/src/webrtc/groupCall";
|
||||||
import { GroupCallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/groupCallEventHandler";
|
import { GroupCallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/groupCallEventHandler";
|
||||||
import { ClientEvent } from "matrix-js-sdk/src/client";
|
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 { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import type { Room } from "matrix-js-sdk/src/models/room";
|
import type { Room } from "matrix-js-sdk/src/models/room";
|
||||||
|
@ -53,7 +54,7 @@ export const useLoadGroupCall = (
|
||||||
const waitPromise = new Promise<Room>((resolve) => {
|
const waitPromise = new Promise<Room>((resolve) => {
|
||||||
const onRoomEvent = async (room: Room) => {
|
const onRoomEvent = async (room: Room) => {
|
||||||
if (room.roomId === roomId) {
|
if (room.roomId === roomId) {
|
||||||
client.removeListener(ClientEvent.Room, onRoomEvent);
|
client.removeListener(GroupCallEventHandlerEvent.Room, onRoomEvent);
|
||||||
resolve(room);
|
resolve(room);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -74,6 +75,7 @@ export const useLoadGroupCall = (
|
||||||
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`);
|
||||||
// wait for the room to come down the sync stream, otherwise
|
// wait for the room to come down the sync stream, otherwise
|
||||||
// client.getRoom() won't return the room.
|
// client.getRoom() won't return the room.
|
||||||
return waitForRoom(room.roomId);
|
return waitForRoom(room.roomId);
|
||||||
|
@ -100,7 +102,9 @@ export const useLoadGroupCall = (
|
||||||
|
|
||||||
const fetchOrCreateGroupCall = async (): Promise<GroupCall> => {
|
const fetchOrCreateGroupCall = async (): Promise<GroupCall> => {
|
||||||
const room = await fetchOrCreateRoom();
|
const room = await fetchOrCreateRoom();
|
||||||
|
logger.debug(`Fetched / joined room ${roomIdOrAlias}`);
|
||||||
const groupCall = client.getGroupCallForRoom(room.roomId);
|
const groupCall = client.getGroupCallForRoom(room.roomId);
|
||||||
|
logger.debug("Got group call", groupCall);
|
||||||
|
|
||||||
if (groupCall) return groupCall;
|
if (groupCall) return groupCall;
|
||||||
|
|
||||||
|
@ -111,7 +115,11 @@ export const useLoadGroupCall = (
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// The call doesn't exist, but we can create it
|
// 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(
|
return await client.createGroupCall(
|
||||||
room.roomId,
|
room.roomId,
|
||||||
createPtt ? GroupCallType.Voice : GroupCallType.Video,
|
createPtt ? GroupCallType.Voice : GroupCallType.Video,
|
||||||
|
|
Loading…
Add table
Reference in a new issue