Skip to content

Commit d656b84

Browse files
authored
Wait for client to start syncing before making group calls (#2632)
As hopefully explained in comment Fixes #2589
1 parent 0981652 commit d656b84

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/webrtc/groupCallEventHandler.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RoomState } from "../models/room-state";
2828
import { RoomMember } from "../models/room-member";
2929
import { logger } from '../logger';
3030
import { EventType } from "../@types/event";
31+
import { SyncState } from '../sync';
3132

3233
export enum GroupCallEventHandlerEvent {
3334
Incoming = "GroupCall.incoming",
@@ -48,7 +49,25 @@ export class GroupCallEventHandler {
4849

4950
constructor(private client: MatrixClient) { }
5051

51-
public start(): void {
52+
public async start(): Promise<void> {
53+
// We wait until the client has started syncing for real.
54+
// This is because we only support one call at a time, and want
55+
// the latest. We therefore want the latest state of the room before
56+
// we create a group call for the room so we can be fairly sure that
57+
// the group call we create is really the latest one.
58+
if (this.client.getSyncState() !== SyncState.Syncing) {
59+
logger.debug("Waiting for client to start syncing...");
60+
await new Promise<void>(resolve => {
61+
const onSync = () => {
62+
if (this.client.getSyncState() === SyncState.Syncing) {
63+
this.client.off(ClientEvent.Sync, onSync);
64+
return resolve();
65+
}
66+
};
67+
this.client.on(ClientEvent.Sync, onSync);
68+
});
69+
}
70+
5271
const rooms = this.client.getRooms();
5372

5473
for (const room of rooms) {

0 commit comments

Comments
 (0)