properly cleanup downtracks on subscriber disconnect
This commit is contained in:
+14
-2
@@ -7,6 +7,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pion/ion-sfu/pkg/sfu"
|
||||||
"github.com/pion/ion-sfu/pkg/twcc"
|
"github.com/pion/ion-sfu/pkg/twcc"
|
||||||
"github.com/pion/rtcp"
|
"github.com/pion/rtcp"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
@@ -367,8 +368,19 @@ func (p *ParticipantImpl) Close() error {
|
|||||||
t.OnClose(nil)
|
t.OnClose(nil)
|
||||||
t.RemoveAllSubscribers()
|
t.RemoveAllSubscribers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var downtracksToClose []*sfu.DownTrack
|
||||||
|
for _, tracks := range p.subscribedTracks {
|
||||||
|
for _, st := range tracks {
|
||||||
|
downtracksToClose = append(downtracksToClose, st.DownTrack())
|
||||||
|
}
|
||||||
|
}
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
||||||
|
for _, dt := range downtracksToClose {
|
||||||
|
dt.Close()
|
||||||
|
}
|
||||||
|
|
||||||
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
|
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
|
||||||
p.subscriber.pc.OnDataChannel(nil)
|
p.subscriber.pc.OnDataChannel(nil)
|
||||||
p.subscriber.pc.OnICECandidate(nil)
|
p.subscriber.pc.OnICECandidate(nil)
|
||||||
@@ -571,7 +583,7 @@ func (p *ParticipantImpl) GetSubscribedTracks() []types.SubscribedTrack {
|
|||||||
// AddSubscribedTrack adds a track to the participant's subscribed list
|
// AddSubscribedTrack adds a track to the participant's subscribed list
|
||||||
func (p *ParticipantImpl) AddSubscribedTrack(pubId string, subTrack types.SubscribedTrack) {
|
func (p *ParticipantImpl) AddSubscribedTrack(pubId string, subTrack types.SubscribedTrack) {
|
||||||
logger.Debugw("added subscribedTrack", "srcParticipant", pubId,
|
logger.Debugw("added subscribedTrack", "srcParticipant", pubId,
|
||||||
"participant", p.Identity())
|
"participant", p.Identity(), "track", subTrack.ID())
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
p.subscribedTracks[pubId] = append(p.subscribedTracks[pubId], subTrack)
|
p.subscribedTracks[pubId] = append(p.subscribedTracks[pubId], subTrack)
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
@@ -580,7 +592,7 @@ func (p *ParticipantImpl) AddSubscribedTrack(pubId string, subTrack types.Subscr
|
|||||||
// RemoveSubscribedTrack removes a track to the participant's subscribed list
|
// RemoveSubscribedTrack removes a track to the participant's subscribed list
|
||||||
func (p *ParticipantImpl) RemoveSubscribedTrack(pubId string, subTrack types.SubscribedTrack) {
|
func (p *ParticipantImpl) RemoveSubscribedTrack(pubId string, subTrack types.SubscribedTrack) {
|
||||||
logger.Debugw("removed subscribedTrack", "srcParticipant", pubId,
|
logger.Debugw("removed subscribedTrack", "srcParticipant", pubId,
|
||||||
"participant", p.Identity())
|
"participant", p.Identity(), "track", subTrack.ID())
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
tracks := make([]types.SubscribedTrack, 0, len(p.subscribedTracks[pubId]))
|
tracks := make([]types.SubscribedTrack, 0, len(p.subscribedTracks[pubId]))
|
||||||
|
|||||||
@@ -156,6 +156,9 @@ func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error {
|
|||||||
if t.onOffer == nil {
|
if t.onOffer == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if t.pc.ConnectionState() == webrtc.PeerConnectionStateClosed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
state := t.negotiationState.Load().(int)
|
state := t.negotiationState.Load().(int)
|
||||||
// when there's an ongoing negotiation, let it finish and not disrupt its state
|
// when there's an ongoing negotiation, let it finish and not disrupt its state
|
||||||
|
|||||||
Reference in New Issue
Block a user