Add Moving participant to another room (#3648)
* Add Moving participant to another room it is implemented in cloud only since the destination room can exist in different node with the source room * Update pkg/service/errors.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * rename * test panic * fake LocalParticipantHelper * revert delete line --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -219,7 +219,7 @@ func EnsureSIPCallPermission(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnsureForwardPermission(ctx context.Context, source livekit.RoomName, destination livekit.RoomName) error {
|
||||
func EnsureDestRoomPermission(ctx context.Context, source livekit.RoomName, destination livekit.RoomName) error {
|
||||
claims := GetGrants(ctx)
|
||||
if claims == nil || claims.Video == nil {
|
||||
return ErrPermissionDenied
|
||||
|
||||
@@ -30,7 +30,7 @@ var (
|
||||
ErrAttributeExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "attribute size exceeds limits")
|
||||
ErrRoomNameExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "room name length exceeds limits")
|
||||
ErrParticipantIdentityExceedsLimits = psrpc.NewErrorf(psrpc.InvalidArgument, "participant identity length exceeds limits")
|
||||
ErrForwardToSameRoom = psrpc.NewErrorf(psrpc.InvalidArgument, "cannot forward to the same room")
|
||||
ErrDestinationSameAsSourceRoom = psrpc.NewErrorf(psrpc.InvalidArgument, "destination room cannot be the same as source room")
|
||||
ErrOperationFailed = psrpc.NewErrorf(psrpc.Internal, "operation cannot be completed")
|
||||
ErrParticipantNotFound = psrpc.NewErrorf(psrpc.NotFound, "participant does not exist")
|
||||
ErrRoomNotFound = psrpc.NewErrorf(psrpc.NotFound, "requested room does not exist")
|
||||
|
||||
@@ -444,17 +444,14 @@ func (r *RoomManager) StartSession(
|
||||
AdaptiveStream: pi.AdaptiveStream,
|
||||
AllowTCPFallback: allowFallback,
|
||||
TURNSEnabled: r.config.IsTURNSEnabled(),
|
||||
GetParticipantInfo: func(pID livekit.ParticipantID) *livekit.ParticipantInfo {
|
||||
if p := room.GetParticipantByID(pID); p != nil {
|
||||
return p.ToProto()
|
||||
}
|
||||
return nil
|
||||
ParticipantHelper: &roomManagerParticipantHelper{
|
||||
room: room,
|
||||
codecRegressionThreshold: r.config.Video.CodecRegressionThreshold,
|
||||
},
|
||||
ReconnectOnPublicationError: reconnectOnPublicationError,
|
||||
ReconnectOnSubscriptionError: reconnectOnSubscriptionError,
|
||||
ReconnectOnDataChannelError: reconnectOnDataChannelError,
|
||||
VersionGenerator: r.versionGenerator,
|
||||
TrackResolver: room.ResolveMediaTrackForSubscriber,
|
||||
SubscriberAllowPause: subscriberAllowPause,
|
||||
SubscriptionLimitAudio: r.config.Limit.SubscriptionLimitAudio,
|
||||
SubscriptionLimitVideo: r.config.Limit.SubscriptionLimitVideo,
|
||||
@@ -466,9 +463,6 @@ func (r *RoomManager) StartSession(
|
||||
DataChannelMaxBufferedAmount: r.config.RTC.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: r.config.RTC.DatachannelSlowThreshold,
|
||||
FireOnTrackBySdp: true,
|
||||
ShouldRegressCodec: func() bool {
|
||||
return r.config.Video.CodecRegressionThreshold == 0 || room.GetParticipantCount() < r.config.Video.CodecRegressionThreshold
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1019,3 +1013,31 @@ func iceServerForStunServers(servers []string) *livekit.ICEServer {
|
||||
}
|
||||
return iceServer
|
||||
}
|
||||
|
||||
type roomManagerParticipantHelper struct {
|
||||
room *rtc.Room
|
||||
codecRegressionThreshold int
|
||||
}
|
||||
|
||||
func (h *roomManagerParticipantHelper) GetParticipantInfo(pID livekit.ParticipantID) *livekit.ParticipantInfo {
|
||||
if p := h.room.GetParticipantByID(pID); p != nil {
|
||||
return p.ToProto()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *roomManagerParticipantHelper) GetRegionSettings(ip string) *livekit.RegionSettings {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *roomManagerParticipantHelper) GetSubscriberForwarderState(lp types.LocalParticipant) (map[livekit.TrackID]*livekit.RTPForwarderState, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (h *roomManagerParticipantHelper) ResolveMediaTrack(lp types.LocalParticipant, trackID livekit.TrackID) types.MediaResolverResult {
|
||||
return h.room.ResolveMediaTrackForSubscriber(lp, trackID)
|
||||
}
|
||||
|
||||
func (h *roomManagerParticipantHelper) ShouldRegressCodec() bool {
|
||||
return h.codecRegressionThreshold == 0 || h.room.GetParticipantCount() < h.codecRegressionThreshold
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
@@ -322,12 +321,12 @@ func (s *RoomService) ForwardParticipant(ctx context.Context, req *livekit.Forwa
|
||||
|
||||
roomName := livekit.RoomName(req.Room)
|
||||
AppendLogFields(ctx, "room", roomName, "participant", req.Identity)
|
||||
if err := EnsureForwardPermission(ctx, roomName, livekit.RoomName(req.DestinationRoom)); err != nil {
|
||||
if err := EnsureDestRoomPermission(ctx, roomName, livekit.RoomName(req.DestinationRoom)); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
if req.Room == req.DestinationRoom {
|
||||
return nil, twirp.InvalidArgumentError(ErrForwardToSameRoom.Error(), "")
|
||||
return nil, twirp.InvalidArgumentError(ErrDestinationSameAsSourceRoom.Error(), "")
|
||||
}
|
||||
|
||||
res, err := s.participantClient.ForwardParticipant(ctx, s.topicFormatter.ParticipantTopic(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)), req)
|
||||
@@ -336,7 +335,21 @@ func (s *RoomService) ForwardParticipant(ctx context.Context, req *livekit.Forwa
|
||||
}
|
||||
|
||||
func (s *RoomService) MoveParticipant(ctx context.Context, req *livekit.MoveParticipantRequest) (*livekit.MoveParticipantResponse, error) {
|
||||
return nil, errors.New("unimplemented")
|
||||
RecordRequest(ctx, req)
|
||||
|
||||
roomName := livekit.RoomName(req.Room)
|
||||
AppendLogFields(ctx, "room", roomName, "participant", req.Identity)
|
||||
if err := EnsureDestRoomPermission(ctx, roomName, livekit.RoomName(req.DestinationRoom)); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
if req.Room == req.DestinationRoom {
|
||||
return nil, twirp.InvalidArgumentError(ErrDestinationSameAsSourceRoom.Error(), "")
|
||||
}
|
||||
|
||||
res, err := s.participantClient.MoveParticipant(ctx, s.topicFormatter.ParticipantTopic(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)), req)
|
||||
RecordResponse(ctx, res)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func redactCreateRoomRequest(req *livekit.CreateRoomRequest) *livekit.CreateRoomRequest {
|
||||
|
||||
@@ -227,13 +227,13 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
loggerFields := []any{
|
||||
"participant", pi.Identity,
|
||||
"room", roomName,
|
||||
"remote", false,
|
||||
}
|
||||
if pi.ID != "" {
|
||||
loggerFields = append(loggerFields, "pID", pi.ID)
|
||||
}
|
||||
pLogger := utils.GetLogger(r.Context()).WithValues(loggerFields...)
|
||||
pLogger, loggerResolver := utils.GetLogger(r.Context()).WithValues(loggerFields...).WithDeferredValues()
|
||||
loggerResolver("room", roomName)
|
||||
|
||||
// give it a few attempts to start session
|
||||
var cr connectionResult
|
||||
@@ -263,7 +263,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
pLogger = pLogger.WithValues("connID", cr.ConnectionID)
|
||||
if !pi.Reconnect && initialResponse.GetJoin() != nil {
|
||||
pi.ID = livekit.ParticipantID(initialResponse.GetJoin().GetParticipant().GetSid())
|
||||
pLogger = pLogger.WithValues("pID", pi.ID)
|
||||
loggerResolver("pID", pi.ID)
|
||||
}
|
||||
|
||||
signalStats := telemetry.NewBytesSignalStats(r.Context(), s.telemetry)
|
||||
@@ -372,6 +372,9 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
signalStats.ResolveRoom(m.RoomUpdate.GetRoom())
|
||||
case *livekit.SignalResponse_Update:
|
||||
pLogger.Debugw("sending participant update", "participantUpdate", m)
|
||||
case *livekit.SignalResponse_RoomMoved:
|
||||
loggerResolver("room", m.RoomMoved.GetRoom(), "pID", m.RoomMoved.GetParticipant().GetSid())
|
||||
pLogger.Debugw("sending room moved", "roomMoved", m)
|
||||
}
|
||||
|
||||
if count, err := sigConn.WriteResponse(res); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user