Skip to content

Commit 5aea501

Browse files
authored
Log warning if multiple tracks of the same source are published (#329)
* Log warning if multiple tracks of the same source are published * fix source check * no stack trace for remote participant * also log participant info on remote participant
1 parent aac61a9 commit 5aea501

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.changeset/mighty-carpets-dream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
Log warning if multiple tracks of the same source are published

src/room/participant/LocalParticipant.ts

+17
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,23 @@ export default class LocalParticipant extends Participant {
434434
if (opts.source) {
435435
track.source = opts.source;
436436
}
437+
const existingTrackOfSource = Array.from(this.tracks.values()).find(
438+
(publishedTrack) => track instanceof LocalTrack && publishedTrack.source === track.source,
439+
);
440+
if (existingTrackOfSource) {
441+
try {
442+
// throw an Error in order to capture the stack trace
443+
throw Error(`publishing a second track with the same source: ${track.source}`);
444+
} catch (e: unknown) {
445+
if (e instanceof Error) {
446+
log.warn(e.message, {
447+
oldTrack: existingTrackOfSource,
448+
newTrack: track,
449+
trace: e.stack,
450+
});
451+
}
452+
}
453+
}
437454
if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
438455
track.stopOnMute = true;
439456
}

src/room/participant/RemoteParticipant.ts

+13
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ export default class RemoteParticipant extends Participant {
220220
// always emit events for new publications, Room will not forward them unless it's ready
221221
newTracks.forEach((publication) => {
222222
this.emit(ParticipantEvent.TrackPublished, publication);
223+
const existingTrackOfSource = Array.from(this.tracks.values()).find(
224+
(publishedTrack) => publishedTrack.source === publication.source,
225+
);
226+
if (existingTrackOfSource) {
227+
log.warn(
228+
`received a second track publication for ${this.identity} with the same source: ${publication.source}`,
229+
{
230+
oldTrack: existingTrackOfSource,
231+
newTrack: publication,
232+
participant: this,
233+
},
234+
);
235+
}
223236
});
224237

225238
// detect removed tracks

0 commit comments

Comments
 (0)