Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/webrtc/groupCallEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { RoomState } from "../models/room-state";
import { RoomMember } from "../models/room-member";
import { logger } from '../logger';
import { EventType } from "../@types/event";
import { SyncState } from '../sync';

export enum GroupCallEventHandlerEvent {
Incoming = "GroupCall.incoming",
Expand All @@ -46,7 +47,25 @@ export class GroupCallEventHandler {

constructor(private client: MatrixClient) { }

public start(): void {
public async start(): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this handle the client sending the sync request but not getting a response and processing it yet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sync event is emitted after each sync result is processed, so it will wait until the first sync result is fully processed.

// We wait until the client has started syncing for real.
// This is because we only support one call at a time, and want
// the latest. We therefore want the latest state of the room before
// we create a group call for the room so we can be fairly sure that
// the group call we create is really the latest one.
if (this.client.getSyncState() !== SyncState.Syncing) {
logger.debug("Waiting for client to start syncing...");
await new Promise<void>(resolve => {
const onSync = () => {
if (this.client.getSyncState() === SyncState.Syncing) {
this.client.off(ClientEvent.Sync, onSync);
return resolve();
}
};
this.client.on(ClientEvent.Sync, onSync);
});
}

const rooms = this.client.getRooms();

for (const room of rooms) {
Expand Down