Refactor participant metadata updates to avoid duplication (#1679)
* Refactor participant metadata updates to avoid duplication * generated fakes
This commit is contained in:
@@ -649,6 +649,15 @@ func (r *Room) SetMetadata(metadata string) {
|
|||||||
r.protoProxy.MarkDirty(true)
|
r.protoProxy.MarkDirty(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Room) UpdateParticipantMetadata(participant types.LocalParticipant, name string, metadata string) {
|
||||||
|
if metadata != "" {
|
||||||
|
participant.SetMetadata(metadata)
|
||||||
|
}
|
||||||
|
if name != "" {
|
||||||
|
participant.SetName(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Room) sendRoomUpdate() {
|
func (r *Room) sendRoomUpdate() {
|
||||||
roomInfo := r.ToProto()
|
roomInfo := r.ToProto()
|
||||||
// Send update to participants
|
// Send update to participants
|
||||||
|
|||||||
@@ -76,12 +76,7 @@ func HandleParticipantSignal(room types.Room, participant types.LocalParticipant
|
|||||||
|
|
||||||
case *livekit.SignalRequest_UpdateMetadata:
|
case *livekit.SignalRequest_UpdateMetadata:
|
||||||
if participant.ClaimGrants().Video.GetCanUpdateOwnMetadata() {
|
if participant.ClaimGrants().Video.GetCanUpdateOwnMetadata() {
|
||||||
if msg.UpdateMetadata.Metadata != "" {
|
room.UpdateParticipantMetadata(participant, msg.UpdateMetadata.Name, msg.UpdateMetadata.Metadata)
|
||||||
participant.SetMetadata(msg.UpdateMetadata.Metadata)
|
|
||||||
}
|
|
||||||
if msg.UpdateMetadata.Name != "" {
|
|
||||||
participant.SetName(msg.UpdateMetadata.Name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ func (m *SubscriptionManager) reconcileWorker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SubscriptionManager) hasCapcityForSubscription(kind livekit.TrackType) bool {
|
func (m *SubscriptionManager) hasCapacityForSubscription(kind livekit.TrackType) bool {
|
||||||
switch kind {
|
switch kind {
|
||||||
case livekit.TrackType_VIDEO:
|
case livekit.TrackType_VIDEO:
|
||||||
if m.params.SubscriptionLimitVideo > 0 && m.subscribedVideoCount.Load() >= m.params.SubscriptionLimitVideo {
|
if m.params.SubscriptionLimitVideo > 0 && m.subscribedVideoCount.Load() >= m.params.SubscriptionLimitVideo {
|
||||||
@@ -413,7 +413,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
return ErrNoSubscribePermission
|
return ErrNoSubscribePermission
|
||||||
}
|
}
|
||||||
|
|
||||||
if kind, ok := s.getKind(); ok && !m.hasCapcityForSubscription(kind) {
|
if kind, ok := s.getKind(); ok && !m.hasCapacityForSubscription(kind) {
|
||||||
return ErrSubscriptionLimitExceeded
|
return ErrSubscriptionLimitExceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +445,7 @@ func (m *SubscriptionManager) subscribe(s *trackSubscription) error {
|
|||||||
return ErrTrackNotFound
|
return ErrTrackNotFound
|
||||||
}
|
}
|
||||||
s.trySetKind(track.Kind())
|
s.trySetKind(track.Kind())
|
||||||
if !m.hasCapcityForSubscription(track.Kind()) {
|
if !m.hasCapacityForSubscription(track.Kind()) {
|
||||||
return ErrSubscriptionLimitExceeded
|
return ErrSubscriptionLimitExceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -357,6 +357,7 @@ type Room interface {
|
|||||||
UpdateVideoLayers(participant Participant, updateVideoLayers *livekit.UpdateVideoLayers) error
|
UpdateVideoLayers(participant Participant, updateVideoLayers *livekit.UpdateVideoLayers) error
|
||||||
ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) MediaResolverResult
|
ResolveMediaTrackForSubscriber(subIdentity livekit.ParticipantIdentity, trackID livekit.TrackID) MediaResolverResult
|
||||||
GetLocalParticipants() []LocalParticipant
|
GetLocalParticipants() []LocalParticipant
|
||||||
|
UpdateParticipantMetadata(participant LocalParticipant, name string, metadata string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediaTrack represents a media track
|
// MediaTrack represents a media track
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ type FakeRoom struct {
|
|||||||
syncStateReturnsOnCall map[int]struct {
|
syncStateReturnsOnCall map[int]struct {
|
||||||
result1 error
|
result1 error
|
||||||
}
|
}
|
||||||
|
UpdateParticipantMetadataStub func(types.LocalParticipant, string, string)
|
||||||
|
updateParticipantMetadataMutex sync.RWMutex
|
||||||
|
updateParticipantMetadataArgsForCall []struct {
|
||||||
|
arg1 types.LocalParticipant
|
||||||
|
arg2 string
|
||||||
|
arg3 string
|
||||||
|
}
|
||||||
UpdateSubscriptionPermissionStub func(types.LocalParticipant, *livekit.SubscriptionPermission) error
|
UpdateSubscriptionPermissionStub func(types.LocalParticipant, *livekit.SubscriptionPermission) error
|
||||||
updateSubscriptionPermissionMutex sync.RWMutex
|
updateSubscriptionPermissionMutex sync.RWMutex
|
||||||
updateSubscriptionPermissionArgsForCall []struct {
|
updateSubscriptionPermissionArgsForCall []struct {
|
||||||
@@ -497,6 +504,40 @@ func (fake *FakeRoom) SyncStateReturnsOnCall(i int, result1 error) {
|
|||||||
}{result1}
|
}{result1}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) UpdateParticipantMetadata(arg1 types.LocalParticipant, arg2 string, arg3 string) {
|
||||||
|
fake.updateParticipantMetadataMutex.Lock()
|
||||||
|
fake.updateParticipantMetadataArgsForCall = append(fake.updateParticipantMetadataArgsForCall, struct {
|
||||||
|
arg1 types.LocalParticipant
|
||||||
|
arg2 string
|
||||||
|
arg3 string
|
||||||
|
}{arg1, arg2, arg3})
|
||||||
|
stub := fake.UpdateParticipantMetadataStub
|
||||||
|
fake.recordInvocation("UpdateParticipantMetadata", []interface{}{arg1, arg2, arg3})
|
||||||
|
fake.updateParticipantMetadataMutex.Unlock()
|
||||||
|
if stub != nil {
|
||||||
|
fake.UpdateParticipantMetadataStub(arg1, arg2, arg3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) UpdateParticipantMetadataCallCount() int {
|
||||||
|
fake.updateParticipantMetadataMutex.RLock()
|
||||||
|
defer fake.updateParticipantMetadataMutex.RUnlock()
|
||||||
|
return len(fake.updateParticipantMetadataArgsForCall)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) UpdateParticipantMetadataCalls(stub func(types.LocalParticipant, string, string)) {
|
||||||
|
fake.updateParticipantMetadataMutex.Lock()
|
||||||
|
defer fake.updateParticipantMetadataMutex.Unlock()
|
||||||
|
fake.UpdateParticipantMetadataStub = stub
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *FakeRoom) UpdateParticipantMetadataArgsForCall(i int) (types.LocalParticipant, string, string) {
|
||||||
|
fake.updateParticipantMetadataMutex.RLock()
|
||||||
|
defer fake.updateParticipantMetadataMutex.RUnlock()
|
||||||
|
argsForCall := fake.updateParticipantMetadataArgsForCall[i]
|
||||||
|
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *FakeRoom) UpdateSubscriptionPermission(arg1 types.LocalParticipant, arg2 *livekit.SubscriptionPermission) error {
|
func (fake *FakeRoom) UpdateSubscriptionPermission(arg1 types.LocalParticipant, arg2 *livekit.SubscriptionPermission) error {
|
||||||
fake.updateSubscriptionPermissionMutex.Lock()
|
fake.updateSubscriptionPermissionMutex.Lock()
|
||||||
ret, specificReturn := fake.updateSubscriptionPermissionReturnsOnCall[len(fake.updateSubscriptionPermissionArgsForCall)]
|
ret, specificReturn := fake.updateSubscriptionPermissionReturnsOnCall[len(fake.updateSubscriptionPermissionArgsForCall)]
|
||||||
@@ -683,6 +724,8 @@ func (fake *FakeRoom) Invocations() map[string][][]interface{} {
|
|||||||
defer fake.simulateScenarioMutex.RUnlock()
|
defer fake.simulateScenarioMutex.RUnlock()
|
||||||
fake.syncStateMutex.RLock()
|
fake.syncStateMutex.RLock()
|
||||||
defer fake.syncStateMutex.RUnlock()
|
defer fake.syncStateMutex.RUnlock()
|
||||||
|
fake.updateParticipantMetadataMutex.RLock()
|
||||||
|
defer fake.updateParticipantMetadataMutex.RUnlock()
|
||||||
fake.updateSubscriptionPermissionMutex.RLock()
|
fake.updateSubscriptionPermissionMutex.RLock()
|
||||||
defer fake.updateSubscriptionPermissionMutex.RUnlock()
|
defer fake.updateSubscriptionPermissionMutex.RUnlock()
|
||||||
fake.updateSubscriptionsMutex.RLock()
|
fake.updateSubscriptionsMutex.RLock()
|
||||||
|
|||||||
@@ -590,12 +590,7 @@ func (r *RoomManager) handleRTCMessage(ctx context.Context, roomName livekit.Roo
|
|||||||
}
|
}
|
||||||
pLogger.Debugw("updating participant", "metadata", rm.UpdateParticipant.Metadata,
|
pLogger.Debugw("updating participant", "metadata", rm.UpdateParticipant.Metadata,
|
||||||
"permission", rm.UpdateParticipant.Permission)
|
"permission", rm.UpdateParticipant.Permission)
|
||||||
if rm.UpdateParticipant.Name != "" {
|
room.UpdateParticipantMetadata(participant, rm.UpdateParticipant.Name, rm.UpdateParticipant.Metadata)
|
||||||
participant.SetName(rm.UpdateParticipant.Name)
|
|
||||||
}
|
|
||||||
if rm.UpdateParticipant.Metadata != "" {
|
|
||||||
participant.SetMetadata(rm.UpdateParticipant.Metadata)
|
|
||||||
}
|
|
||||||
if rm.UpdateParticipant.Permission != nil {
|
if rm.UpdateParticipant.Permission != nil {
|
||||||
participant.SetPermission(rm.UpdateParticipant.Permission)
|
participant.SetPermission(rm.UpdateParticipant.Permission)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user