Skip to content

Commit

Permalink
Do not force reconnect on resume if there is a pending track (#2081)
Browse files Browse the repository at this point in the history
* Do not force reconnect on resume if there is a pending track

* move GetPendingTrack -> LocalParticipant
  • Loading branch information
boks1971 committed Sep 17, 2023
1 parent 97048a9 commit 019ad88
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/rtc/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,19 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
return ti
}

func (p *ParticipantImpl) GetPendingTrack(trackID livekit.TrackID) *livekit.TrackInfo {
p.pendingTracksLock.RLock()
defer p.pendingTracksLock.RUnlock()

for _, t := range p.pendingTracks {
if livekit.TrackID(t.trackInfos[0].Sid) == trackID {
return t.trackInfos[0]
}
}

return nil
}

func (p *ParticipantImpl) sendTrackPublished(cid string, ti *livekit.TrackInfo) {
p.pubLogger.Debugw("sending track published", "cid", cid, "trackInfo", ti.String())
_ = p.writeMessage(&livekit.SignalResponse{
Expand Down
4 changes: 4 additions & 0 deletions pkg/rtc/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ func (r *Room) SyncState(participant types.LocalParticipant, state *livekit.Sync
break
}
}
if !found {
// is there a pending track?
found = participant.GetPendingTrack(livekit.TrackID(ti.Sid)) != nil
}
if !found {
pLogger.Warnw("unknown track during resume", nil, "trackID", ti.Sid)
shouldReconnect = true
Expand Down
3 changes: 2 additions & 1 deletion pkg/rtc/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type Participant interface {
SetMetadata(metadata string)

IsPublisher() bool
GetPublishedTrack(sid livekit.TrackID) MediaTrack
GetPublishedTrack(trackID livekit.TrackID) MediaTrack
GetPublishedTracks() []MediaTrack
RemovePublishedTrack(track MediaTrack, willBeResumed bool, shouldClose bool)

Expand Down Expand Up @@ -315,6 +315,7 @@ type LocalParticipant interface {
GetICEConnectionType() ICEConnectionType
GetBufferFactory() *buffer.Factory
GetPlayoutDelayConfig() *livekit.PlayoutDelay
GetPendingTrack(trackID livekit.TrackID) *livekit.TrackInfo

SetResponseSink(sink routing.MessageSink)
CloseSignalConnection(reason SignallingCloseReason)
Expand Down
74 changes: 74 additions & 0 deletions pkg/rtc/types/typesfakes/fake_local_participant.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 019ad88

Please sign in to comment.