Skip to content

Commit acf9dca

Browse files
conference: handle metadata of streams properly
Don't include tracks in the metadata that are not yet published (for which we don't have any remote streams available). Also, inform about metadata changes once tracks get published and unpublished.
1 parent cd65c4a commit acf9dca

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

pkg/conference/processor.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
4949
switch msg := message.Content.(type) {
5050
case peer.JoinedTheCall:
5151
participant.logger.Info("Joined the call")
52-
c.resendMetadataToAllExcept(participant.id)
5352

5453
case peer.LeftTheCall:
5554
participant.logger.Info("Left the call")
@@ -69,6 +68,7 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
6968
}
7069

7170
participant.publishedTracks[key] = msg.Track
71+
c.resendMetadataToAllExcept(participant.id)
7272

7373
case peer.PublishedTrackFailed:
7474
participant.logger.Infof("Failed published track: %s", msg.Track.ID())
@@ -85,6 +85,8 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
8585
otherParticipant.peer.UnsubscribeFrom([]*webrtc.TrackLocalStaticRTP{msg.Track})
8686
}
8787

88+
c.resendMetadataToAllExcept(participant.id)
89+
8890
case peer.NewICECandidate:
8991
participant.logger.Debug("Received a new local ICE candidate")
9092

pkg/conference/state.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,24 @@ func (c *Conference) removeParticipant(participantID ParticipantID) {
6363
}
6464

6565
// Helper to get the list of available streams for a given participant, i.e. the list of streams
66-
// that a given participant **can subscribe to**.
66+
// that a given participant **can subscribe to**. Each stream may have multiple tracks.
6767
func (c *Conference) getAvailableStreamsFor(forParticipant ParticipantID) event.CallSDPStreamMetadata {
6868
streamsMetadata := make(event.CallSDPStreamMetadata)
6969
for id, participant := range c.participants {
70+
// Skip us. As we know about our own tracks.
7071
if forParticipant != id {
71-
for streamID, metadata := range participant.streamMetadata {
72-
streamsMetadata[streamID] = metadata
72+
// Now, find out which of published tracks belong to the streams for which we have metadata
73+
// available and construct a metadata map for a given participant based on that.
74+
for _, track := range participant.publishedTracks {
75+
trackID, streamID := track.ID(), track.StreamID()
76+
77+
if metadata, ok := streamsMetadata[track.StreamID()]; ok {
78+
metadata.Tracks[trackID] = event.CallSDPStreamMetadataTrack{}
79+
streamsMetadata[streamID] = metadata
80+
} else if metadata, ok := participant.streamMetadata[streamID]; ok {
81+
metadata.Tracks = event.CallSDPStreamMetadataTracks{trackID: event.CallSDPStreamMetadataTrack{}}
82+
streamsMetadata[streamID] = metadata
83+
}
7384
}
7485
}
7586
}

0 commit comments

Comments
 (0)