Skip to content

Commit

Permalink
Misc fixes for group call widgets (#2657)
Browse files Browse the repository at this point in the history
* Fix GroupCallEventHandler in matryoshka mode

GroupCallEventHandler needs to see a 'Syncing' event before it starts handling any events, so emit one immediately in matryoshka mode.

* Implement joinRoom on RoomWidgetClient

Element Call has undergone some changes to how it loads rooms, meaning that this method must be implemented for the app to work in matryoshka mode.

* Allow audio and video to be muted before local call feed exists

This is desirable for the Element Web integration of Element Call, because we need to be able to mute our devices before ever joining the call or creating a call feed, if the users requests it.

* Fix a strict mode error
  • Loading branch information
robintown committed Sep 9, 2022
1 parent aebe26d commit 36a6117
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class RoomWidgetClient extends MatrixClient {
});
}) ?? [],
);
this.setSyncState(SyncState.Prepared);
this.setSyncState(SyncState.Syncing);
logger.info("Finished backfilling events");

// Watch for TURN servers, if requested
Expand All @@ -146,6 +146,11 @@ export class RoomWidgetClient extends MatrixClient {
this.lifecycle.abort(); // Signal to other async tasks that the client has stopped
}

public async joinRoom(roomIdOrAlias: string): Promise<Room> {
if (roomIdOrAlias === this.roomId) return this.room;
throw new Error(`Unknown room: ${roomIdOrAlias}`);
}

public async sendStateEvent(
roomId: string,
eventType: string,
Expand Down
22 changes: 14 additions & 8 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export class GroupCall extends TypedEventEmitter<
private transmitTimer: ReturnType<typeof setTimeout> | null = null;
private memberStateExpirationTimers: Map<string, ReturnType<typeof setTimeout>> = new Map();
private resendMemberStateTimer: ReturnType<typeof setInterval> | null = null;
private initWithAudioMuted = false;
private initWithVideoMuted = false;

constructor(
private client: MatrixClient,
Expand Down Expand Up @@ -261,23 +263,21 @@ export class GroupCall extends TypedEventEmitter<
throw error;
}

// start muted on ptt calls
if (this.isPtt) {
setTracksEnabled(stream.getAudioTracks(), false);
}

const userId = this.client.getUserId();
const userId = this.client.getUserId()!;

const callFeed = new CallFeed({
client: this.client,
roomId: this.room.roomId,
userId,
stream,
purpose: SDPStreamMetadataPurpose.Usermedia,
audioMuted: stream.getAudioTracks().length === 0 || this.isPtt,
videoMuted: stream.getVideoTracks().length === 0,
audioMuted: this.initWithAudioMuted || stream.getAudioTracks().length === 0 || this.isPtt,
videoMuted: this.initWithVideoMuted || stream.getVideoTracks().length === 0,
});

setTracksEnabled(stream.getAudioTracks(), !callFeed.isAudioMuted());
setTracksEnabled(stream.getVideoTracks(), !callFeed.isVideoMuted());

this.localCallFeed = callFeed;
this.addUserMediaFeed(callFeed);

Expand Down Expand Up @@ -496,6 +496,9 @@ export class GroupCall extends TypedEventEmitter<
// given to any of the actual calls, so these tracks don't actually go
// anywhere. Let's do it anyway to avoid confusion.
setTracksEnabled(this.localCallFeed.stream.getAudioTracks(), !muted);
} else {
logger.log(`groupCall ${this.groupCallId} setMicrophoneMuted no stream muted ${muted}`);
this.initWithAudioMuted = muted;
}

for (const call of this.calls) {
Expand Down Expand Up @@ -532,6 +535,9 @@ export class GroupCall extends TypedEventEmitter<
this.localCallFeed.stream.id} muted ${muted}`);
this.localCallFeed.setAudioVideoMuted(null, muted);
setTracksEnabled(this.localCallFeed.stream.getVideoTracks(), !muted);
} else {
logger.log(`groupCall ${this.groupCallId} setLocalVideoMuted no stream muted ${muted}`);
this.initWithVideoMuted = muted;
}

for (const call of this.calls) {
Expand Down

0 comments on commit 36a6117

Please sign in to comment.