Skip to content

Commit

Permalink
Additional guards against creating localParticipant as remote partici…
Browse files Browse the repository at this point in the history
…pant (#296)

* Guard against creating localParticipant as remote participant and add log traces

* changeset
  • Loading branch information
lukasIO committed Jun 30, 2022
1 parent e65443a commit 9e78db7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-balloons-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Additional guards against creating localParticipant as remoteParticipant
1 change: 1 addition & 0 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
this.emit(EngineEvent.Disconnected);
this.close();
}
log.trace('leave request', { leave });
};
}

Expand Down
17 changes: 16 additions & 1 deletion src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,17 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)

// populate remote participants, these should not trigger new events
joinResponse.otherParticipants.forEach((info) => {
this.getOrCreateParticipant(info.sid, info);
if (
info.sid !== this.localParticipant.sid &&
info.identity !== this.localParticipant.identity
) {
this.getOrCreateParticipant(info.sid, info);
} else {
log.warn('received info to create local participant as remote participant', {
info,
localParticipant: this.localParticipant,
});
}
});

this.name = joinResponse.room!.name;
Expand Down Expand Up @@ -555,7 +565,12 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
let trackId = parts[1];
if (!trackId || trackId === '') trackId = mediaTrack.id;

if (participantId === this.localParticipant.sid) {
log.warn('tried to create RemoteParticipant for local participant');
return;
}
const participant = this.getOrCreateParticipant(participantId);

let adaptiveStreamSettings: AdaptiveStreamSettings | undefined;
if (this.options.adaptiveStream) {
if (typeof this.options.adaptiveStream === 'object') {
Expand Down
2 changes: 2 additions & 0 deletions src/room/participant/Participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RemoteTrackPublication from '../track/RemoteTrackPublication';
import { Track } from '../track/Track';
import { TrackPublication } from '../track/TrackPublication';
import { RemoteTrack } from '../track/types';
import log from '../../logger';

export enum ConnectionQuality {
Excellent = 'excellent',
Expand Down Expand Up @@ -179,6 +180,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
}
// set this last so setMetadata can detect changes
this.participantInfo = info;
log.trace('update participant info', { info });
}

/** @internal */
Expand Down
4 changes: 4 additions & 0 deletions src/room/participant/RemoteParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export default class RemoteParticipant extends Participant {
// detect removed tracks
this.tracks.forEach((publication) => {
if (!validTracks.has(publication.trackSid)) {
log.trace('detected removed track on remote participant, unpublishing', {
publication,
participantSid: this.sid,
});
this.unpublishTrack(publication.trackSid, true);
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/room/track/TrackPublication.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter } from 'events';
import log from '../../logger';
import { TrackInfo } from '../../proto/livekit_models';
import { TrackEvent } from '../events';
import LocalAudioTrack from './LocalAudioTrack';
Expand Down Expand Up @@ -108,6 +109,7 @@ export class TrackPublication extends EventEmitter {
this.simulcasted = info.simulcast;
}
this.trackInfo = info;
log.trace('update publication info', { info });
}
}

Expand Down

0 comments on commit 9e78db7

Please sign in to comment.