diff --git a/.changeset/shaggy-balloons-laugh.md b/.changeset/shaggy-balloons-laugh.md new file mode 100644 index 000000000..8b11f1a45 --- /dev/null +++ b/.changeset/shaggy-balloons-laugh.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Additional guards against creating localParticipant as remoteParticipant diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 120249315..6f1f3195c 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -363,6 +363,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit this.emit(EngineEvent.Disconnected); this.close(); } + log.trace('leave request', { leave }); }; } diff --git a/src/room/Room.ts b/src/room/Room.ts index c64d241bc..8499e6fdc 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -288,7 +288,17 @@ class Room extends (EventEmitter as new () => TypedEmitter) // 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; @@ -555,7 +565,12 @@ class Room extends (EventEmitter as new () => TypedEmitter) 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') { diff --git a/src/room/participant/Participant.ts b/src/room/participant/Participant.ts index 265703d7d..712477c5c 100644 --- a/src/room/participant/Participant.ts +++ b/src/room/participant/Participant.ts @@ -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', @@ -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 */ diff --git a/src/room/participant/RemoteParticipant.ts b/src/room/participant/RemoteParticipant.ts index be59eb2b4..5f15bea75 100644 --- a/src/room/participant/RemoteParticipant.ts +++ b/src/room/participant/RemoteParticipant.ts @@ -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); } }); diff --git a/src/room/track/TrackPublication.ts b/src/room/track/TrackPublication.ts index 25cfb37ee..294b20184 100644 --- a/src/room/track/TrackPublication.ts +++ b/src/room/track/TrackPublication.ts @@ -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'; @@ -108,6 +109,7 @@ export class TrackPublication extends EventEmitter { this.simulcasted = info.simulcast; } this.trackInfo = info; + log.trace('update publication info', { info }); } }