fix participant APIs when using LocalRouter (#67)
This commit is contained in:
@@ -84,7 +84,7 @@ func (r *LocalRouter) StartParticipantSignal(roomName string, pi ParticipantInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// index channels by roomName | identity
|
// index channels by roomName | identity
|
||||||
key := participantKey(roomName, pi.Identity)
|
key := ParticipantKey(roomName, pi.Identity)
|
||||||
reqChan := r.getOrCreateMessageChannel(r.requestChannels, key)
|
reqChan := r.getOrCreateMessageChannel(r.requestChannels, key)
|
||||||
resChan := r.getOrCreateMessageChannel(r.responseChannels, key)
|
resChan := r.getOrCreateMessageChannel(r.responseChannels, key)
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ func (r *RedisRouter) StartParticipantSignal(roomName string, pi ParticipantInit
|
|||||||
|
|
||||||
// create a new connection id
|
// create a new connection id
|
||||||
connectionId = utils.NewGuid("CO_")
|
connectionId = utils.NewGuid("CO_")
|
||||||
pKey := participantKey(roomName, pi.Identity)
|
pKey := ParticipantKey(roomName, pi.Identity)
|
||||||
|
|
||||||
// map signal & rtc nodes
|
// map signal & rtc nodes
|
||||||
if err = r.setParticipantSignalNode(connectionId, r.currentNode.Id); err != nil {
|
if err = r.setParticipantSignalNode(connectionId, r.currentNode.Id); err != nil {
|
||||||
@@ -172,7 +172,7 @@ func (r *RedisRouter) StartParticipantSignal(roomName string, pi ParticipantInit
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) CreateRTCSink(roomName, identity string) (MessageSink, error) {
|
func (r *RedisRouter) CreateRTCSink(roomName, identity string) (MessageSink, error) {
|
||||||
pkey := participantKey(roomName, identity)
|
pkey := ParticipantKey(roomName, identity)
|
||||||
rtcNode, err := r.getParticipantRTCNode(pkey)
|
rtcNode, err := r.getParticipantRTCNode(pkey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func GetAvailableNodes(nodes []*livekit.Node) []*livekit.Node {
|
|||||||
}).([]*livekit.Node)
|
}).([]*livekit.Node)
|
||||||
}
|
}
|
||||||
|
|
||||||
func participantKey(roomName, identity string) string {
|
func ParticipantKey(roomName, identity string) string {
|
||||||
return roomName + "|" + identity
|
return roomName + "|" + identity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
-48
@@ -66,17 +66,14 @@ func (s *RoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomReq
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(participants) > 0 {
|
if len(participants) > 0 {
|
||||||
rtcSink, err := s.roomManager.router.CreateRTCSink(req.Room, participants[0].Identity)
|
err := s.writeMessage(ctx, req.Room, participants[0].Identity, &livekit.RTCNodeMessage{
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer rtcSink.Close()
|
|
||||||
_ = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
|
||||||
Message: &livekit.RTCNodeMessage_DeleteRoom{
|
Message: &livekit.RTCNodeMessage_DeleteRoom{
|
||||||
DeleteRoom: req,
|
DeleteRoom: req,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if a room hasn't started, delete locally
|
// if a room hasn't started, delete locally
|
||||||
if err = s.roomManager.DeleteRoom(req.Room); err != nil {
|
if err = s.roomManager.DeleteRoom(req.Room); err != nil {
|
||||||
@@ -119,21 +116,14 @@ func (s *RoomService) GetParticipant(ctx context.Context, req *livekit.RoomParti
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RoomService) RemoveParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (res *livekit.RemoveParticipantResponse, err error) {
|
func (s *RoomService) RemoveParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (res *livekit.RemoveParticipantResponse, err error) {
|
||||||
if err = EnsureAdminPermission(ctx, req.Room); err != nil {
|
err = s.writeMessage(ctx, req.Room, req.Identity, &livekit.RTCNodeMessage{
|
||||||
return nil, twirpAuthError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rtcSink, err := s.createRTCSink(ctx, req.Room, req.Identity)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer rtcSink.Close()
|
|
||||||
err = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
|
||||||
Message: &livekit.RTCNodeMessage_RemoveParticipant{
|
Message: &livekit.RTCNodeMessage_RemoveParticipant{
|
||||||
RemoveParticipant: req,
|
RemoveParticipant: req,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
res = &livekit.RemoveParticipantResponse{}
|
res = &livekit.RemoveParticipantResponse{}
|
||||||
return
|
return
|
||||||
@@ -144,12 +134,6 @@ func (s *RoomService) MutePublishedTrack(ctx context.Context, req *livekit.MuteR
|
|||||||
return nil, twirpAuthError(err)
|
return nil, twirpAuthError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtcSink, err := s.createRTCSink(ctx, req.Room, req.Identity)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer rtcSink.Close()
|
|
||||||
|
|
||||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -162,7 +146,8 @@ func (s *RoomService) MutePublishedTrack(ctx context.Context, req *livekit.MuteR
|
|||||||
return nil, twirp.NotFoundError(ErrTrackNotFound.Error())
|
return nil, twirp.NotFoundError(ErrTrackNotFound.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
err = s.writeMessage(ctx, req.Room, req.Identity, &livekit.RTCNodeMessage{
|
||||||
|
ParticipantKey: routing.ParticipantKey(req.Room, req.Identity),
|
||||||
Message: &livekit.RTCNodeMessage_MuteTrack{
|
Message: &livekit.RTCNodeMessage_MuteTrack{
|
||||||
MuteTrack: req,
|
MuteTrack: req,
|
||||||
},
|
},
|
||||||
@@ -180,47 +165,33 @@ func (s *RoomService) MutePublishedTrack(ctx context.Context, req *livekit.MuteR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RoomService) UpdateParticipant(ctx context.Context, req *livekit.UpdateParticipantRequest) (*livekit.ParticipantInfo, error) {
|
func (s *RoomService) UpdateParticipant(ctx context.Context, req *livekit.UpdateParticipantRequest) (*livekit.ParticipantInfo, error) {
|
||||||
if err := EnsureAdminPermission(ctx, req.Room); err != nil {
|
err := s.writeMessage(ctx, req.Room, req.Identity, &livekit.RTCNodeMessage{
|
||||||
return nil, twirpAuthError(err)
|
Message: &livekit.RTCNodeMessage_UpdateParticipant{
|
||||||
}
|
UpdateParticipant: req,
|
||||||
|
},
|
||||||
rtcSink, err := s.createRTCSink(ctx, req.Room, req.Identity)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rtcSink.Close()
|
|
||||||
|
|
||||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
|
||||||
Message: &livekit.RTCNodeMessage_UpdateParticipant{
|
|
||||||
UpdateParticipant: req,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
participant.Metadata = req.Metadata
|
participant.Metadata = req.Metadata
|
||||||
return participant, nil
|
return participant, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RoomService) UpdateSubscriptions(ctx context.Context, req *livekit.UpdateSubscriptionsRequest) (*livekit.UpdateSubscriptionsResponse, error) {
|
func (s *RoomService) UpdateSubscriptions(ctx context.Context, req *livekit.UpdateSubscriptionsRequest) (*livekit.UpdateSubscriptionsResponse, error) {
|
||||||
if err := EnsureAdminPermission(ctx, req.Room); err != nil {
|
err := s.writeMessage(ctx, req.Room, req.Identity, &livekit.RTCNodeMessage{
|
||||||
return nil, twirpAuthError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rtcSink, err := s.createRTCSink(ctx, req.Room, req.Identity)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rtcSink.Close()
|
|
||||||
|
|
||||||
err = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
|
||||||
Message: &livekit.RTCNodeMessage_UpdateSubscriptions{
|
Message: &livekit.RTCNodeMessage_UpdateSubscriptions{
|
||||||
UpdateSubscriptions: req,
|
UpdateSubscriptions: req,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &livekit.UpdateSubscriptionsResponse{}, nil
|
return &livekit.UpdateSubscriptionsResponse{}, nil
|
||||||
}
|
}
|
||||||
@@ -237,3 +208,14 @@ func (s *RoomService) createRTCSink(ctx context.Context, room, identity string)
|
|||||||
|
|
||||||
return s.roomManager.router.CreateRTCSink(room, identity)
|
return s.roomManager.router.CreateRTCSink(room, identity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *RoomService) writeMessage(ctx context.Context, room, identity string, msg *livekit.RTCNodeMessage) error {
|
||||||
|
rtcSink, err := s.createRTCSink(ctx, room, identity)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rtcSink.Close()
|
||||||
|
|
||||||
|
msg.ParticipantKey = routing.ParticipantKey(room, identity)
|
||||||
|
return rtcSink.WriteMessage(msg)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user