update participant to support signal broadcast skipping (#1657)
* update participant to support signal broadcast skipping * cleanup * lock * feedback * order * update requireBroadcast in SetPermissions
This commit is contained in:
+18
-2
@@ -131,6 +131,7 @@ type ParticipantImpl struct {
|
|||||||
// keeps track of unpublished tracks in order to reuse trackID
|
// keeps track of unpublished tracks in order to reuse trackID
|
||||||
unpublishedTracks []*livekit.TrackInfo
|
unpublishedTracks []*livekit.TrackInfo
|
||||||
|
|
||||||
|
requireBroadcast bool
|
||||||
// queued participant updates before join response is sent
|
// queued participant updates before join response is sent
|
||||||
// guarded by updateLock
|
// guarded by updateLock
|
||||||
queuedUpdates []*livekit.ParticipantInfo
|
queuedUpdates []*livekit.ParticipantInfo
|
||||||
@@ -324,6 +325,7 @@ func (p *ParticipantImpl) SetMetadata(metadata string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.grants.Metadata = metadata
|
p.grants.Metadata = metadata
|
||||||
|
p.requireBroadcast = p.requireBroadcast || metadata != ""
|
||||||
p.dirty.Store(true)
|
p.dirty.Store(true)
|
||||||
|
|
||||||
onParticipantUpdate := p.onParticipantUpdate
|
onParticipantUpdate := p.onParticipantUpdate
|
||||||
@@ -364,6 +366,9 @@ func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermissio
|
|||||||
canSubscribe := video.GetCanSubscribe()
|
canSubscribe := video.GetCanSubscribe()
|
||||||
onParticipantUpdate := p.onParticipantUpdate
|
onParticipantUpdate := p.onParticipantUpdate
|
||||||
onClaimsChanged := p.onClaimsChanged
|
onClaimsChanged := p.onClaimsChanged
|
||||||
|
|
||||||
|
isPublisher := canPublish && p.TransportManager.IsPublisherEstablished()
|
||||||
|
p.requireBroadcast = p.requireBroadcast || isPublisher
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
|
|
||||||
// publish permission has been revoked then remove offending tracks
|
// publish permission has been revoked then remove offending tracks
|
||||||
@@ -390,7 +395,7 @@ func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermissio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update isPublisher attribute
|
// update isPublisher attribute
|
||||||
p.isPublisher.Store(canPublish && p.TransportManager.IsPublisherEstablished())
|
p.isPublisher.Store(isPublisher)
|
||||||
|
|
||||||
if onParticipantUpdate != nil {
|
if onParticipantUpdate != nil {
|
||||||
onParticipantUpdate(p)
|
onParticipantUpdate(p)
|
||||||
@@ -401,6 +406,12 @@ func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermissio
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ParticipantImpl) CanSkipBroadcast() bool {
|
||||||
|
p.lock.RLock()
|
||||||
|
defer p.lock.RUnlock()
|
||||||
|
return !p.requireBroadcast
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ParticipantImpl) ToProtoWithVersion() (*livekit.ParticipantInfo, utils.TimedVersion) {
|
func (p *ParticipantImpl) ToProtoWithVersion() (*livekit.ParticipantInfo, utils.TimedVersion) {
|
||||||
v := p.version.Load()
|
v := p.version.Load()
|
||||||
piv := p.timedVersion.Load()
|
piv := p.timedVersion.Load()
|
||||||
@@ -1081,10 +1092,11 @@ func (p *ParticipantImpl) setupUpTrackManager() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack) {
|
p.UpTrackManager.OnPublishedTrackUpdated(func(track types.MediaTrack) {
|
||||||
p.dirty.Store(true)
|
|
||||||
p.lock.RLock()
|
p.lock.RLock()
|
||||||
onTrackUpdated := p.onTrackUpdated
|
onTrackUpdated := p.onTrackUpdated
|
||||||
p.lock.RUnlock()
|
p.lock.RUnlock()
|
||||||
|
|
||||||
|
p.dirty.Store(true)
|
||||||
if onTrackUpdated != nil {
|
if onTrackUpdated != nil {
|
||||||
onTrackUpdated(p, track)
|
onTrackUpdated(p, track)
|
||||||
}
|
}
|
||||||
@@ -1134,6 +1146,10 @@ func (p *ParticipantImpl) updateState(state livekit.ParticipantInfo_State) {
|
|||||||
|
|
||||||
func (p *ParticipantImpl) setIsPublisher(isPublisher bool) {
|
func (p *ParticipantImpl) setIsPublisher(isPublisher bool) {
|
||||||
if p.isPublisher.Swap(isPublisher) != isPublisher {
|
if p.isPublisher.Swap(isPublisher) != isPublisher {
|
||||||
|
p.lock.Lock()
|
||||||
|
p.requireBroadcast = true
|
||||||
|
p.lock.Unlock()
|
||||||
|
|
||||||
p.dirty.Store(true)
|
p.dirty.Store(true)
|
||||||
|
|
||||||
// trigger update as well if participant is already fully connected
|
// trigger update as well if participant is already fully connected
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ type Participant interface {
|
|||||||
Identity() livekit.ParticipantIdentity
|
Identity() livekit.ParticipantIdentity
|
||||||
State() livekit.ParticipantInfo_State
|
State() livekit.ParticipantInfo_State
|
||||||
|
|
||||||
|
CanSkipBroadcast() bool
|
||||||
ToProto() *livekit.ParticipantInfo
|
ToProto() *livekit.ParticipantInfo
|
||||||
|
|
||||||
SetName(name string)
|
SetName(name string)
|
||||||
|
|||||||
@@ -89,6 +89,16 @@ type FakeLocalParticipant struct {
|
|||||||
canPublishSourceReturnsOnCall map[int]struct {
|
canPublishSourceReturnsOnCall map[int]struct {
|
||||||
result1 bool
|
result1 bool
|
||||||
}
|
}
|
||||||
|
CanSkipBroadcastStub func() bool
|
||||||
|
canSkipBroadcastMutex sync.RWMutex
|
||||||
|
canSkipBroadcastArgsForCall []struct {
|
||||||
|
}
|
||||||
|
canSkipBroadcastReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
canSkipBroadcastReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
CanSubscribeStub func() bool
|
CanSubscribeStub func() bool
|
||||||
canSubscribeMutex sync.RWMutex
|
canSubscribeMutex sync.RWMutex
|
||||||
canSubscribeArgsForCall []struct {
|
canSubscribeArgsForCall []struct {
|
||||||
@@ -340,10 +350,6 @@ type FakeLocalParticipant struct {
|
|||||||
identityReturnsOnCall map[int]struct {
|
identityReturnsOnCall map[int]struct {
|
||||||
result1 livekit.ParticipantIdentity
|
result1 livekit.ParticipantIdentity
|
||||||
}
|
}
|
||||||
InvalidateVersionStub func()
|
|
||||||
invalidateVersionMutex sync.RWMutex
|
|
||||||
invalidateVersionArgsForCall []struct {
|
|
||||||
}
|
|
||||||
IsClosedStub func() bool
|
IsClosedStub func() bool
|
||||||
isClosedMutex sync.RWMutex
|
isClosedMutex sync.RWMutex
|
||||||
isClosedArgsForCall []struct {
|
isClosedArgsForCall []struct {
|
||||||
@@ -1202,6 +1208,59 @@ func (fake *FakeLocalParticipant) CanPublishSourceReturnsOnCall(i int, result1 b
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) CanSkipBroadcast() bool {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
ret, specificReturn := fake.canSkipBroadcastReturnsOnCall[len(fake.canSkipBroadcastArgsForCall)]
|
||||||
|
fake.canSkipBroadcastArgsForCall = append(fake.canSkipBroadcastArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.CanSkipBroadcastStub
|
||||||
|
fakeReturns := fake.canSkipBroadcastReturns
|
||||||
|
fake.recordInvocation("CanSkipBroadcast", []interface{}{})
|
||||||
|
fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) CanSkipBroadcastCallCount() int {
|
||||||
|
fake.canSkipBroadcastMutex.RLock()
|
||||||
|
defer fake.canSkipBroadcastMutex.RUnlock()
|
||||||
|
return len(fake.canSkipBroadcastArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) CanSkipBroadcastCalls(stub func() bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) CanSkipBroadcastReturns(result1 bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = nil
|
||||||
|
fake.canSkipBroadcastReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeLocalParticipant) CanSkipBroadcastReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = nil
|
||||||
|
if fake.canSkipBroadcastReturnsOnCall == nil {
|
||||||
|
fake.canSkipBroadcastReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.canSkipBroadcastReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) CanSubscribe() bool {
|
func (fake *FakeLocalParticipant) CanSubscribe() bool {
|
||||||
fake.canSubscribeMutex.Lock()
|
fake.canSubscribeMutex.Lock()
|
||||||
ret, specificReturn := fake.canSubscribeReturnsOnCall[len(fake.canSubscribeArgsForCall)]
|
ret, specificReturn := fake.canSubscribeReturnsOnCall[len(fake.canSubscribeArgsForCall)]
|
||||||
@@ -2537,30 +2596,6 @@ func (fake *FakeLocalParticipant) IdentityReturnsOnCall(i int, result1 livekit.P
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) InvalidateVersion() {
|
|
||||||
fake.invalidateVersionMutex.Lock()
|
|
||||||
fake.invalidateVersionArgsForCall = append(fake.invalidateVersionArgsForCall, struct {
|
|
||||||
}{})
|
|
||||||
stub := fake.InvalidateVersionStub
|
|
||||||
fake.recordInvocation("InvalidateVersion", []interface{}{})
|
|
||||||
fake.invalidateVersionMutex.Unlock()
|
|
||||||
if stub != nil {
|
|
||||||
fake.InvalidateVersionStub()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) InvalidateVersionCallCount() int {
|
|
||||||
fake.invalidateVersionMutex.RLock()
|
|
||||||
defer fake.invalidateVersionMutex.RUnlock()
|
|
||||||
return len(fake.invalidateVersionArgsForCall)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) InvalidateVersionCalls(stub func()) {
|
|
||||||
fake.invalidateVersionMutex.Lock()
|
|
||||||
defer fake.invalidateVersionMutex.Unlock()
|
|
||||||
fake.InvalidateVersionStub = stub
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fake *FakeLocalParticipant) IsClosed() bool {
|
func (fake *FakeLocalParticipant) IsClosed() bool {
|
||||||
fake.isClosedMutex.Lock()
|
fake.isClosedMutex.Lock()
|
||||||
ret, specificReturn := fake.isClosedReturnsOnCall[len(fake.isClosedArgsForCall)]
|
ret, specificReturn := fake.isClosedReturnsOnCall[len(fake.isClosedArgsForCall)]
|
||||||
@@ -5405,6 +5440,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.canPublishDataMutex.RUnlock()
|
defer fake.canPublishDataMutex.RUnlock()
|
||||||
fake.canPublishSourceMutex.RLock()
|
fake.canPublishSourceMutex.RLock()
|
||||||
defer fake.canPublishSourceMutex.RUnlock()
|
defer fake.canPublishSourceMutex.RUnlock()
|
||||||
|
fake.canSkipBroadcastMutex.RLock()
|
||||||
|
defer fake.canSkipBroadcastMutex.RUnlock()
|
||||||
fake.canSubscribeMutex.RLock()
|
fake.canSubscribeMutex.RLock()
|
||||||
defer fake.canSubscribeMutex.RUnlock()
|
defer fake.canSubscribeMutex.RUnlock()
|
||||||
fake.claimGrantsMutex.RLock()
|
fake.claimGrantsMutex.RLock()
|
||||||
@@ -5457,8 +5494,6 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.iDMutex.RUnlock()
|
defer fake.iDMutex.RUnlock()
|
||||||
fake.identityMutex.RLock()
|
fake.identityMutex.RLock()
|
||||||
defer fake.identityMutex.RUnlock()
|
defer fake.identityMutex.RUnlock()
|
||||||
fake.invalidateVersionMutex.RLock()
|
|
||||||
defer fake.invalidateVersionMutex.RUnlock()
|
|
||||||
fake.isClosedMutex.RLock()
|
fake.isClosedMutex.RLock()
|
||||||
defer fake.isClosedMutex.RUnlock()
|
defer fake.isClosedMutex.RUnlock()
|
||||||
fake.isDisconnectedMutex.RLock()
|
fake.isDisconnectedMutex.RLock()
|
||||||
|
|||||||
@@ -10,6 +10,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type FakeParticipant struct {
|
type FakeParticipant struct {
|
||||||
|
CanSkipBroadcastStub func() bool
|
||||||
|
canSkipBroadcastMutex sync.RWMutex
|
||||||
|
canSkipBroadcastArgsForCall []struct {
|
||||||
|
}
|
||||||
|
canSkipBroadcastReturns struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
|
canSkipBroadcastReturnsOnCall map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
}
|
||||||
CloseStub func(bool, types.ParticipantCloseReason) error
|
CloseStub func(bool, types.ParticipantCloseReason) error
|
||||||
closeMutex sync.RWMutex
|
closeMutex sync.RWMutex
|
||||||
closeArgsForCall []struct {
|
closeArgsForCall []struct {
|
||||||
@@ -197,6 +207,59 @@ type FakeParticipant struct {
|
|||||||
invocationsMutex sync.RWMutex
|
invocationsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) CanSkipBroadcast() bool {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
ret, specificReturn := fake.canSkipBroadcastReturnsOnCall[len(fake.canSkipBroadcastArgsForCall)]
|
||||||
|
fake.canSkipBroadcastArgsForCall = append(fake.canSkipBroadcastArgsForCall, struct {
|
||||||
|
}{})
|
||||||
|
stub := fake.CanSkipBroadcastStub
|
||||||
|
fakeReturns := fake.canSkipBroadcastReturns
|
||||||
|
fake.recordInvocation("CanSkipBroadcast", []interface{}{})
|
||||||
|
fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
return stub()
|
||||||
|
}
|
||||||
|
if specificReturn {
|
||||||
|
return ret.result1
|
||||||
|
}
|
||||||
|
return fakeReturns.result1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) CanSkipBroadcastCallCount() int {
|
||||||
|
fake.canSkipBroadcastMutex.RLock()
|
||||||
|
defer fake.canSkipBroadcastMutex.RUnlock()
|
||||||
|
return len(fake.canSkipBroadcastArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) CanSkipBroadcastCalls(stub func() bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) CanSkipBroadcastReturns(result1 bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = nil
|
||||||
|
fake.canSkipBroadcastReturns = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeParticipant) CanSkipBroadcastReturnsOnCall(i int, result1 bool) {
|
||||||
|
fake.canSkipBroadcastMutex.Lock()
|
||||||
|
defer fake.canSkipBroadcastMutex.Unlock()
|
||||||
|
fake.CanSkipBroadcastStub = nil
|
||||||
|
if fake.canSkipBroadcastReturnsOnCall == nil {
|
||||||
|
fake.canSkipBroadcastReturnsOnCall = make(map[int]struct {
|
||||||
|
result1 bool
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fake.canSkipBroadcastReturnsOnCall[i] = struct {
|
||||||
|
result1 bool
|
||||||
|
}{result1}
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeParticipant) Close(arg1 bool, arg2 types.ParticipantCloseReason) error {
|
func (fake *FakeParticipant) Close(arg1 bool, arg2 types.ParticipantCloseReason) error {
|
||||||
fake.closeMutex.Lock()
|
fake.closeMutex.Lock()
|
||||||
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
ret, specificReturn := fake.closeReturnsOnCall[len(fake.closeArgsForCall)]
|
||||||
@@ -1165,6 +1228,8 @@ func (fake *FakeParticipant) UpdateVideoLayersReturnsOnCall(i int, result1 error
|
|||||||
func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
func (fake *FakeParticipant) Invocations() map[string][][]interface{} {
|
||||||
fake.invocationsMutex.RLock()
|
fake.invocationsMutex.RLock()
|
||||||
defer fake.invocationsMutex.RUnlock()
|
defer fake.invocationsMutex.RUnlock()
|
||||||
|
fake.canSkipBroadcastMutex.RLock()
|
||||||
|
defer fake.canSkipBroadcastMutex.RUnlock()
|
||||||
fake.closeMutex.RLock()
|
fake.closeMutex.RLock()
|
||||||
defer fake.closeMutex.RUnlock()
|
defer fake.closeMutex.RUnlock()
|
||||||
fake.debugInfoMutex.RLock()
|
fake.debugInfoMutex.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user