Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log warning if multiple tracks of the same source are published #329

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-carpets-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Log warning if multiple tracks of the same source are published
17 changes: 17 additions & 0 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,23 @@ export default class LocalParticipant extends Participant {
if (opts.source) {
track.source = opts.source;
}
const existingTrackOfSource = Array.from(this.tracks.values()).find(
(publishedTrack) => track instanceof LocalTrack && publishedTrack.source === track.source,
);
if (existingTrackOfSource) {
try {
// throw an Error in order to capture the stack trace
throw Error(`publishing a second track with the same source: ${track.source}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent!

} catch (e: unknown) {
if (e instanceof Error) {
log.warn(e.message, {
oldTrack: existingTrackOfSource,
newTrack: track,
trace: e.stack,
});
}
}
}
if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
track.stopOnMute = true;
}
Expand Down
19 changes: 19 additions & 0 deletions src/room/participant/RemoteParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,25 @@ export default class RemoteParticipant extends Participant {
// always emit events for new publications, Room will not forward them unless it's ready
newTracks.forEach((publication) => {
this.emit(ParticipantEvent.TrackPublished, publication);
const existingTrackOfSource = Array.from(this.tracks.values()).find(
(publishedTrack) => publishedTrack.source === publication.source,
);
if (existingTrackOfSource) {
try {
// throw an Error in order to capture the stack trace
throw Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just a regular warning here? since the stack trace isn't going to be useful here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought about it too, unclear why I left it in 🤔
will remove!

`received a second track publication with the same source: ${publication.source}`,
);
} catch (e: unknown) {
if (e instanceof Error) {
log.warn(e.message, {
oldTrack: existingTrackOfSource,
newTrack: publication,
trace: e.stack,
});
}
}
}
});

// detect removed tracks
Expand Down