handle cid changes between publish intent and onTrack

This commit is contained in:
David Zhao
2021-02-02 23:55:56 -08:00
parent d117cce37b
commit 0cb09ee945
2 changed files with 19 additions and 3 deletions
+2
View File
@@ -589,4 +589,6 @@ func (c *RTCClient) SendNacks(count int) {
})
}
c.lock.Unlock()
c.PeerConn.WriteRTCP(packets)
}
+17 -3
View File
@@ -532,7 +532,7 @@ func (p *ParticipantImpl) updateState(state livekit.ParticipantInfo_State) {
func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver) {
logger.Debugw("mediaTrack added", "participant", p.Identity(), "remoteTrack", track.ID())
ti := p.popPendingTrack(track.ID())
ti := p.popPendingTrack(track.ID(), ToProtoTrackKind(track.Kind()))
if ti == nil {
return
}
@@ -552,7 +552,7 @@ func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
logger.Debugw("dataChannel added", "participant", p.Identity(), "label", dc.Label())
// data channels have numeric ids, so we use its label to identify
ti := p.popPendingTrack(dc.Label())
ti := p.popPendingTrack(dc.Label(), livekit.TrackType_DATA)
if ti == nil {
return
}
@@ -563,10 +563,24 @@ func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) {
p.handleTrackPublished(dt)
}
func (p *ParticipantImpl) popPendingTrack(clientId string) *livekit.TrackInfo {
func (p *ParticipantImpl) popPendingTrack(clientId string, kind livekit.TrackType) *livekit.TrackInfo {
p.lock.Lock()
defer p.lock.Unlock()
ti := p.pendingTracks[clientId]
// then find the first one that matches type. with MediaStreamTrack, it's possible for the client id to
// change after being added to PeerConnection
if ti == nil {
for cid, info := range p.pendingTracks {
if info.Type == kind {
ti = info
clientId = cid
break
}
}
}
// if still not found, we are done
if ti == nil {
logger.Errorw("track info not published prior to track", "clientId", clientId)
} else {