Skip to content

Commit

Permalink
Reconcile local mute status after resuming connection (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao authored Jun 29, 2022
1 parent b67ecfd commit c65e206
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lovely-laws-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Reconcile local mute status after resuming connection
6 changes: 6 additions & 0 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
let postAction = () => {};
let req: SimulateScenario | undefined;
switch (scenario) {
case 'signal-reconnect':
this.engine.client.close();
if (this.engine.client.onClose) {
this.engine.client.onClose('simulate disconnect');
}
break;
case 'speaker':
req = SimulateScenario.fromPartial({
speakerUpdate: 3,
Expand Down
30 changes: 29 additions & 1 deletion src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import log from '../../logger';
import { RoomOptions } from '../../options';
import { DataPacket, DataPacket_Kind, ParticipantPermission } from '../../proto/livekit_models';
import {
DataPacket,
DataPacket_Kind,
ParticipantInfo,
ParticipantPermission,
} from '../../proto/livekit_models';
import {
AddTrackRequest,
DataChannelInfo,
Expand Down Expand Up @@ -787,6 +792,29 @@ export default class LocalParticipant extends Participant {
}
}

/** @internal */
updateInfo(info: ParticipantInfo) {
super.updateInfo(info);

// reconcile track mute status.
// if server's track mute status doesn't match actual, we'll have to update
// the server's copy
info.tracks.forEach((ti) => {
const pub = this.tracks.get(ti.sid);

if (pub) {
const mutedOnServer = pub.isMuted || (pub.track?.isUpstreamPaused ?? false);
if (mutedOnServer !== ti.muted) {
log.debug('updating server mute state after reconcile', {
sid: ti.sid,
muted: mutedOnServer,
});
this.engine.client.sendMuteTrack(ti.sid, mutedOnServer);
}
}
});
}

private updateTrackSubscriptionPermissions = () => {
log.debug('updating track subscription permissions', {
allParticipantsAllowed: this.allParticipantsAllowedToSubscribe,
Expand Down

0 comments on commit c65e206

Please sign in to comment.