mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 21:18:19 +00:00
Fix: Return NotFoundErr instead of Unavailable when the participant does not exist in UpdateParticipant. (#3543)
* Check if Participant exists when update metadata * Change Test cases * type smuggle oss participant check into roomstore * tidy --------- Co-authored-by: Paul Wells <paulwe@gmail.com>
This commit is contained in:
co-authored by
Paul Wells
parent
75d0e18e4a
commit
97fcb82a77
@@ -52,6 +52,10 @@ type ServiceStore interface {
|
||||
ListParticipants(ctx context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error)
|
||||
}
|
||||
|
||||
type OSSServiceStore interface {
|
||||
HasParticipant(context.Context, livekit.RoomName, livekit.ParticipantIdentity) (bool, error)
|
||||
}
|
||||
|
||||
//counterfeiter:generate . EgressStore
|
||||
type EgressStore interface {
|
||||
StoreEgress(ctx context.Context, info *livekit.EgressInfo) error
|
||||
|
||||
@@ -153,6 +153,11 @@ func (s *LocalStore) LoadParticipant(_ context.Context, roomName livekit.RoomNam
|
||||
return participant, nil
|
||||
}
|
||||
|
||||
func (s *LocalStore) HasParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (bool, error) {
|
||||
p, err := s.LoadParticipant(ctx, roomName, identity)
|
||||
return p != nil, utils.ScreenError(err, ErrParticipantNotFound)
|
||||
}
|
||||
|
||||
func (s *LocalStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
|
||||
@@ -314,6 +314,11 @@ func (s *RedisStore) LoadParticipant(_ context.Context, roomName livekit.RoomNam
|
||||
return &pi, nil
|
||||
}
|
||||
|
||||
func (s *RedisStore) HasParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (bool, error) {
|
||||
p, err := s.LoadParticipant(ctx, roomName, identity)
|
||||
return p != nil, utils.ScreenError(err, ErrParticipantNotFound)
|
||||
}
|
||||
|
||||
func (s *RedisStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
|
||||
key := RoomParticipantsPrefix + string(roomName)
|
||||
items, err := s.rc.HVals(s.ctx, key).Result()
|
||||
|
||||
@@ -238,6 +238,15 @@ func (s *RoomService) UpdateParticipant(ctx context.Context, req *livekit.Update
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
if os, ok := s.roomStore.(OSSServiceStore); ok {
|
||||
found, err := os.HasParticipant(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !found {
|
||||
return nil, ErrParticipantNotFound
|
||||
}
|
||||
}
|
||||
|
||||
res, err := s.participantClient.UpdateParticipant(ctx, s.topicFormatter.ParticipantTopic(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)), req)
|
||||
RecordResponse(ctx, res)
|
||||
return res, err
|
||||
|
||||
Reference in New Issue
Block a user