add disconnected chan to participant (#2650)

This commit is contained in:
Paul Wells
2024-04-14 12:49:13 -07:00
committed by GitHub
parent ec41d20f81
commit 7d5c991d8d
4 changed files with 77 additions and 9 deletions
+9 -2
View File
@@ -147,7 +147,8 @@ type ParticipantImpl struct {
isClosed atomic.Bool
closeReason atomic.Value // types.ParticipantCloseReason
state atomic.Value // livekit.ParticipantInfo_State
state atomic.Value // livekit.ParticipantInfo_State
disconnected chan struct{}
resSinkMu sync.Mutex
resSink routing.MessageSink
@@ -241,7 +242,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
return nil, ErrMissingGrants
}
p := &ParticipantImpl{
params: params,
params: params,
disconnected: make(chan struct{}),
pubRTCPQueue: sutils.NewOpsQueue(sutils.OpsQueueParams{
Name: "pub-rtcp",
MinSize: 64,
@@ -372,6 +374,10 @@ func (p *ParticipantImpl) IsDisconnected() bool {
return p.State() == livekit.ParticipantInfo_DISCONNECTED
}
func (p *ParticipantImpl) Disconnected() <-chan struct{} {
return p.disconnected
}
func (p *ParticipantImpl) IsIdle() bool {
// check if there are any published tracks that are subscribed
for _, t := range p.GetPublishedTracks() {
@@ -841,6 +847,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
p.UpTrackManager.Close(isExpectedToResume)
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
close(p.disconnected)
// ensure this is synchronized
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)