@@ -28,6 +28,7 @@ import { RoomState } from "../models/room-state";
2828import { RoomMember } from "../models/room-member" ;
2929import { logger } from '../logger' ;
3030import { EventType } from "../@types/event" ;
31+ import { SyncState } from '../sync' ;
3132
3233export 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