From 990cf6877bfb7d645df666c6085e6e0ca731a452 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Thu, 11 Apr 2024 11:14:15 -0700 Subject: [PATCH] backwards compatability for IsRecorder (#2647) * backwards compatability for IsRecorder * regenerate fakes --- pkg/rtc/participant.go | 7 ++ pkg/rtc/room.go | 6 +- pkg/rtc/types/interfaces.go | 1 + .../typesfakes/fake_local_participant.go | 65 +++++++++++++++++++ pkg/rtc/types/typesfakes/fake_participant.go | 65 +++++++++++++++++++ 5 files changed, 141 insertions(+), 3 deletions(-) diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index b74088629..e49e57f3a 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -332,6 +332,13 @@ func (p *ParticipantImpl) Kind() livekit.ParticipantInfo_Kind { return p.grants.GetParticipantKind() } +func (p *ParticipantImpl) IsRecorder() bool { + p.lock.RLock() + defer p.lock.RUnlock() + + return p.grants.GetParticipantKind() == livekit.ParticipantInfo_EGRESS || p.grants.Video.Recorder +} + func (p *ParticipantImpl) IsDependent() bool { p.lock.RLock() defer p.lock.RUnlock() diff --git a/pkg/rtc/room.go b/pkg/rtc/room.go index ad3fc5d18..cc8645a9a 100644 --- a/pkg/rtc/room.go +++ b/pkg/rtc/room.go @@ -417,7 +417,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me "numParticipants", len(r.participants), ) - if participant.Kind() == livekit.ParticipantInfo_EGRESS && !r.protoRoom.ActiveRecording { + if participant.IsRecorder() && !r.protoRoom.ActiveRecording { r.protoRoom.ActiveRecording = true r.protoProxy.MarkDirty(true) } else { @@ -559,10 +559,10 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity, pID livek } immediateChange := false - if p.Kind() == livekit.ParticipantInfo_EGRESS { + if p.IsRecorder() { activeRecording := false for _, op := range r.participants { - if op.Kind() == livekit.ParticipantInfo_EGRESS { + if op.IsRecorder() { activeRecording = true break } diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index ebbfe9620..57d6f3922 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -246,6 +246,7 @@ type Participant interface { State() livekit.ParticipantInfo_State CloseReason() ParticipantCloseReason Kind() livekit.ParticipantInfo_Kind + IsRecorder() bool IsDependent() bool CanSkipBroadcast() bool diff --git a/pkg/rtc/types/typesfakes/fake_local_participant.go b/pkg/rtc/types/typesfakes/fake_local_participant.go index 21f433338..351697226 100644 --- a/pkg/rtc/types/typesfakes/fake_local_participant.go +++ b/pkg/rtc/types/typesfakes/fake_local_participant.go @@ -504,6 +504,16 @@ type FakeLocalParticipant struct { isReadyReturnsOnCall map[int]struct { result1 bool } + IsRecorderStub func() bool + isRecorderMutex sync.RWMutex + isRecorderArgsForCall []struct { + } + isRecorderReturns struct { + result1 bool + } + isRecorderReturnsOnCall map[int]struct { + result1 bool + } IsSubscribedToStub func(livekit.ParticipantID) bool isSubscribedToMutex sync.RWMutex isSubscribedToArgsForCall []struct { @@ -3551,6 +3561,59 @@ func (fake *FakeLocalParticipant) IsReadyReturnsOnCall(i int, result1 bool) { }{result1} } +func (fake *FakeLocalParticipant) IsRecorder() bool { + fake.isRecorderMutex.Lock() + ret, specificReturn := fake.isRecorderReturnsOnCall[len(fake.isRecorderArgsForCall)] + fake.isRecorderArgsForCall = append(fake.isRecorderArgsForCall, struct { + }{}) + stub := fake.IsRecorderStub + fakeReturns := fake.isRecorderReturns + fake.recordInvocation("IsRecorder", []interface{}{}) + fake.isRecorderMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *FakeLocalParticipant) IsRecorderCallCount() int { + fake.isRecorderMutex.RLock() + defer fake.isRecorderMutex.RUnlock() + return len(fake.isRecorderArgsForCall) +} + +func (fake *FakeLocalParticipant) IsRecorderCalls(stub func() bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = stub +} + +func (fake *FakeLocalParticipant) IsRecorderReturns(result1 bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = nil + fake.isRecorderReturns = struct { + result1 bool + }{result1} +} + +func (fake *FakeLocalParticipant) IsRecorderReturnsOnCall(i int, result1 bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = nil + if fake.isRecorderReturnsOnCall == nil { + fake.isRecorderReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.isRecorderReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *FakeLocalParticipant) IsSubscribedTo(arg1 livekit.ParticipantID) bool { fake.isSubscribedToMutex.Lock() ret, specificReturn := fake.isSubscribedToReturnsOnCall[len(fake.isSubscribedToArgsForCall)] @@ -6415,6 +6478,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} { defer fake.isPublisherMutex.RUnlock() fake.isReadyMutex.RLock() defer fake.isReadyMutex.RUnlock() + fake.isRecorderMutex.RLock() + defer fake.isRecorderMutex.RUnlock() fake.isSubscribedToMutex.RLock() defer fake.isSubscribedToMutex.RUnlock() fake.issueFullReconnectMutex.RLock() diff --git a/pkg/rtc/types/typesfakes/fake_participant.go b/pkg/rtc/types/typesfakes/fake_participant.go index f20a4cefe..3c06229a1 100644 --- a/pkg/rtc/types/typesfakes/fake_participant.go +++ b/pkg/rtc/types/typesfakes/fake_participant.go @@ -148,6 +148,16 @@ type FakeParticipant struct { isPublisherReturnsOnCall map[int]struct { result1 bool } + IsRecorderStub func() bool + isRecorderMutex sync.RWMutex + isRecorderArgsForCall []struct { + } + isRecorderReturns struct { + result1 bool + } + isRecorderReturnsOnCall map[int]struct { + result1 bool + } KindStub func() livekit.ParticipantInfo_Kind kindMutex sync.RWMutex kindArgsForCall []struct { @@ -954,6 +964,59 @@ func (fake *FakeParticipant) IsPublisherReturnsOnCall(i int, result1 bool) { }{result1} } +func (fake *FakeParticipant) IsRecorder() bool { + fake.isRecorderMutex.Lock() + ret, specificReturn := fake.isRecorderReturnsOnCall[len(fake.isRecorderArgsForCall)] + fake.isRecorderArgsForCall = append(fake.isRecorderArgsForCall, struct { + }{}) + stub := fake.IsRecorderStub + fakeReturns := fake.isRecorderReturns + fake.recordInvocation("IsRecorder", []interface{}{}) + fake.isRecorderMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *FakeParticipant) IsRecorderCallCount() int { + fake.isRecorderMutex.RLock() + defer fake.isRecorderMutex.RUnlock() + return len(fake.isRecorderArgsForCall) +} + +func (fake *FakeParticipant) IsRecorderCalls(stub func() bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = stub +} + +func (fake *FakeParticipant) IsRecorderReturns(result1 bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = nil + fake.isRecorderReturns = struct { + result1 bool + }{result1} +} + +func (fake *FakeParticipant) IsRecorderReturnsOnCall(i int, result1 bool) { + fake.isRecorderMutex.Lock() + defer fake.isRecorderMutex.Unlock() + fake.IsRecorderStub = nil + if fake.isRecorderReturnsOnCall == nil { + fake.isRecorderReturnsOnCall = make(map[int]struct { + result1 bool + }) + } + fake.isRecorderReturnsOnCall[i] = struct { + result1 bool + }{result1} +} + func (fake *FakeParticipant) Kind() livekit.ParticipantInfo_Kind { fake.kindMutex.Lock() ret, specificReturn := fake.kindReturnsOnCall[len(fake.kindArgsForCall)] @@ -1420,6 +1483,8 @@ func (fake *FakeParticipant) Invocations() map[string][][]interface{} { defer fake.isDependentMutex.RUnlock() fake.isPublisherMutex.RLock() defer fake.isPublisherMutex.RUnlock() + fake.isRecorderMutex.RLock() + defer fake.isRecorderMutex.RUnlock() fake.kindMutex.RLock() defer fake.kindMutex.RUnlock() fake.removePublishedTrackMutex.RLock()