add disconnected chan to participant (#2650)
This commit is contained in:
@@ -147,7 +147,8 @@ type ParticipantImpl struct {
|
|||||||
isClosed atomic.Bool
|
isClosed atomic.Bool
|
||||||
closeReason atomic.Value // types.ParticipantCloseReason
|
closeReason atomic.Value // types.ParticipantCloseReason
|
||||||
|
|
||||||
state atomic.Value // livekit.ParticipantInfo_State
|
state atomic.Value // livekit.ParticipantInfo_State
|
||||||
|
disconnected chan struct{}
|
||||||
|
|
||||||
resSinkMu sync.Mutex
|
resSinkMu sync.Mutex
|
||||||
resSink routing.MessageSink
|
resSink routing.MessageSink
|
||||||
@@ -241,7 +242,8 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
|
|||||||
return nil, ErrMissingGrants
|
return nil, ErrMissingGrants
|
||||||
}
|
}
|
||||||
p := &ParticipantImpl{
|
p := &ParticipantImpl{
|
||||||
params: params,
|
params: params,
|
||||||
|
disconnected: make(chan struct{}),
|
||||||
pubRTCPQueue: sutils.NewOpsQueue(sutils.OpsQueueParams{
|
pubRTCPQueue: sutils.NewOpsQueue(sutils.OpsQueueParams{
|
||||||
Name: "pub-rtcp",
|
Name: "pub-rtcp",
|
||||||
MinSize: 64,
|
MinSize: 64,
|
||||||
@@ -372,6 +374,10 @@ func (p *ParticipantImpl) IsDisconnected() bool {
|
|||||||
return p.State() == livekit.ParticipantInfo_DISCONNECTED
|
return p.State() == livekit.ParticipantInfo_DISCONNECTED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) Disconnected() <-chan struct{} {
|
||||||
|
return p.disconnected
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) IsIdle() bool {
|
func (p *ParticipantImpl) IsIdle() bool {
|
||||||
// check if there are any published tracks that are subscribed
|
// check if there are any published tracks that are subscribed
|
||||||
for _, t := range p.GetPublishedTracks() {
|
for _, t := range p.GetPublishedTracks() {
|
||||||
@@ -841,6 +847,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
|
|||||||
p.UpTrackManager.Close(isExpectedToResume)
|
p.UpTrackManager.Close(isExpectedToResume)
|
||||||
|
|
||||||
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
|
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
|
||||||
|
close(p.disconnected)
|
||||||
|
|
||||||
// ensure this is synchronized
|
// ensure this is synchronized
|
||||||
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
|
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ type LocalParticipant interface {
|
|||||||
IsClosed() bool
|
IsClosed() bool
|
||||||
IsReady() bool
|
IsReady() bool
|
||||||
IsDisconnected() bool
|
IsDisconnected() bool
|
||||||
|
Disconnected() <-chan struct{}
|
||||||
IsIdle() bool
|
IsIdle() bool
|
||||||
SubscriberAsPrimary() bool
|
SubscriberAsPrimary() bool
|
||||||
GetClientInfo() *livekit.ClientInfo
|
GetClientInfo() *livekit.ClientInfo
|
||||||
|
|||||||
@@ -168,6 +168,16 @@ type FakeLocalParticipant struct {
|
|||||||
debugInfoReturnsOnCall map[int]struct {
|
debugInfoReturnsOnCall map[int]struct {
|
||||||
result1 map[string]interface{}
|
result1 map[string]interface{}
|
||||||
}
|
}
|
||||||
|
DisconnectedStub func() <-chan struct{}
|
||||||
|
disconnectedMutex sync.RWMutex
|
||||||
|
disconnectedArgsForCall []struct {
|
||||||
|
}
|
||||||
|
disconnectedReturns struct {
|
||||||
|
result1 <-chan struct{}
|
||||||
|
}
|
||||||
|
disconnectedReturnsOnCall map[int]struct {
|
||||||
|
result1 <-chan struct{}
|
||||||
|
}
|
||||||
GetAdaptiveStreamStub func() bool
|
GetAdaptiveStreamStub func() bool
|
||||||
getAdaptiveStreamMutex sync.RWMutex
|
getAdaptiveStreamMutex sync.RWMutex
|
||||||
getAdaptiveStreamArgsForCall []struct {
|
getAdaptiveStreamArgsForCall []struct {
|
||||||
@@ -1770,6 +1780,59 @@ func (fake *FakeLocalParticipant) DebugInfoReturnsOnCall(i int, result1 map[stri
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) Disconnected() <-chan struct{} {
|
||||||
|
fake.disconnectedMutex.Lock()
|
||||||
|
ret, specificReturn := fake.disconnectedReturnsOnCall[len(fake.disconnectedArgsForCall)]
|
||||||
|
fake.disconnectedArgsForCall = append(fake.disconnectedArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.DisconnectedStub
|
||||||
|
fakeReturns := fake.disconnectedReturns
|
||||||
|
fake.recordInvocation("Disconnected", []interface{}{})
|
||||||
|
fake.disconnectedMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) DisconnectedCallCount() int {
|
||||||
|
fake.disconnectedMutex.RLock()
|
||||||
|
defer fake.disconnectedMutex.RUnlock()
|
||||||
|
return len(fake.disconnectedArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) DisconnectedCalls(stub func() <-chan struct{}) {
|
||||||
|
fake.disconnectedMutex.Lock()
|
||||||
|
defer fake.disconnectedMutex.Unlock()
|
||||||
|
fake.DisconnectedStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) DisconnectedReturns(result1 <-chan struct{}) {
|
||||||
|
fake.disconnectedMutex.Lock()
|
||||||
|
defer fake.disconnectedMutex.Unlock()
|
||||||
|
fake.DisconnectedStub = nil
|
||||||
|
fake.disconnectedReturns = struct {
|
||||||
|
result1 <-chan struct{}
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) DisconnectedReturnsOnCall(i int, result1 <-chan struct{}) {
|
||||||
|
fake.disconnectedMutex.Lock()
|
||||||
|
defer fake.disconnectedMutex.Unlock()
|
||||||
|
fake.DisconnectedStub = nil
|
||||||
|
if fake.disconnectedReturnsOnCall == nil {
|
||||||
|
fake.disconnectedReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 <-chan struct{}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.disconnectedReturnsOnCall[i] = struct {
|
||||||
|
result1 <-chan struct{}
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) GetAdaptiveStream() bool {
|
func (fake *FakeLocalParticipant) GetAdaptiveStream() bool {
|
||||||
fake.getAdaptiveStreamMutex.Lock()
|
fake.getAdaptiveStreamMutex.Lock()
|
||||||
ret, specificReturn := fake.getAdaptiveStreamReturnsOnCall[len(fake.getAdaptiveStreamArgsForCall)]
|
ret, specificReturn := fake.getAdaptiveStreamReturnsOnCall[len(fake.getAdaptiveStreamArgsForCall)]
|
||||||
@@ -6408,6 +6471,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.connectedAtMutex.RUnlock()
|
defer fake.connectedAtMutex.RUnlock()
|
||||||
fake.debugInfoMutex.RLock()
|
fake.debugInfoMutex.RLock()
|
||||||
defer fake.debugInfoMutex.RUnlock()
|
defer fake.debugInfoMutex.RUnlock()
|
||||||
|
fake.disconnectedMutex.RLock()
|
||||||
|
defer fake.disconnectedMutex.RUnlock()
|
||||||
fake.getAdaptiveStreamMutex.RLock()
|
fake.getAdaptiveStreamMutex.RLock()
|
||||||
defer fake.getAdaptiveStreamMutex.RUnlock()
|
defer fake.getAdaptiveStreamMutex.RUnlock()
|
||||||
fake.getAudioLevelMutex.RLock()
|
fake.getAudioLevelMutex.RLock()
|
||||||
|
|||||||
@@ -620,15 +620,10 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
|||||||
_ = r.refreshToken(participant)
|
_ = r.refreshToken(participant)
|
||||||
tokenTicker := time.NewTicker(tokenRefreshInterval)
|
tokenTicker := time.NewTicker(tokenRefreshInterval)
|
||||||
defer tokenTicker.Stop()
|
defer tokenTicker.Stop()
|
||||||
stateCheckTicker := time.NewTicker(time.Millisecond * 500)
|
|
||||||
defer stateCheckTicker.Stop()
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stateCheckTicker.C:
|
case <-participant.Disconnected():
|
||||||
// periodic check to ensure participant didn't become disconnected
|
return
|
||||||
if participant.IsDisconnected() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case <-tokenTicker.C:
|
case <-tokenTicker.C:
|
||||||
// refresh token with the first API Key/secret pair
|
// refresh token with the first API Key/secret pair
|
||||||
if err := r.refreshToken(participant); err != nil {
|
if err := r.refreshToken(participant); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user