handle new UpdateParticipant API, enable permission updates
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -216,10 +215,7 @@ func (r *RoomManager) StartSession(roomName string, pi routing.ParticipantInit,
|
||||
return
|
||||
}
|
||||
if pi.Metadata != "" {
|
||||
var md map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(pi.Metadata), &md); err == nil {
|
||||
participant.SetMetadata(md)
|
||||
}
|
||||
participant.SetMetadata(pi.Metadata)
|
||||
}
|
||||
|
||||
if pi.Permission != nil {
|
||||
@@ -383,16 +379,14 @@ func (r *RoomManager) handleRTCMessage(roomName, identity string, msg *livekit.R
|
||||
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
|
||||
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted)
|
||||
case *livekit.RTCNodeMessage_UpdateMetadata:
|
||||
logger.Debugw("updating metadata", "room", roomName, "participant", identity)
|
||||
var md map[string]interface{}
|
||||
if rm.UpdateMetadata.Metadata != "" {
|
||||
if err := json.Unmarshal([]byte(rm.UpdateMetadata.Metadata), &md); err != nil {
|
||||
logger.Errorw("could not update metadata", "error", err)
|
||||
return
|
||||
}
|
||||
case *livekit.RTCNodeMessage_UpdateParticipant:
|
||||
logger.Debugw("updating participant", "room", roomName, "participant", identity)
|
||||
if rm.UpdateParticipant.Metadata != "" {
|
||||
participant.SetMetadata(rm.UpdateParticipant.Metadata)
|
||||
}
|
||||
if rm.UpdateParticipant.Permission != nil {
|
||||
participant.SetPermission(rm.UpdateParticipant.Permission)
|
||||
}
|
||||
participant.SetMetadata(md)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,21 +150,21 @@ func (s *RoomService) MutePublishedTrack(ctx context.Context, req *livekit.MuteR
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoomService) UpdateParticipantMetadata(ctx context.Context, req *livekit.UpdateParticipantMetadataRequest) (*livekit.ParticipantInfo, error) {
|
||||
rtcSink, err := s.createRTCSink(ctx, req.Target.Room, req.Target.Identity)
|
||||
func (s *RoomService) UpdateParticipant(ctx context.Context, req *livekit.UpdateParticipantRequest) (*livekit.ParticipantInfo, error) {
|
||||
rtcSink, err := s.createRTCSink(ctx, req.Room, req.Identity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rtcSink.Close()
|
||||
|
||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Target.Room, req.Target.Identity)
|
||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = rtcSink.WriteMessage(&livekit.RTCNodeMessage{
|
||||
Message: &livekit.RTCNodeMessage_UpdateMetadata{
|
||||
UpdateMetadata: req,
|
||||
Message: &livekit.RTCNodeMessage_UpdateParticipant{
|
||||
UpdateParticipant: req,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -91,12 +90,8 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if claims.Metadata != nil {
|
||||
if data, err := json.Marshal(claims.Metadata); err != nil {
|
||||
logger.Warnw("unable to encode metadata", "error", err)
|
||||
} else {
|
||||
pi.Metadata = string(data)
|
||||
}
|
||||
if claims.Metadata != "" {
|
||||
pi.Metadata = claims.Metadata
|
||||
}
|
||||
|
||||
// this needs to be started first *before* using router functions on this node
|
||||
|
||||
Reference in New Issue
Block a user