HTTP DELETE of participant session (#3819)

This commit is contained in:
Raja Subramanian
2025-07-24 23:02:45 +05:30
committed by GitHub
parent 01de0e365f
commit a7ce138239
5 changed files with 83 additions and 8 deletions
+2 -2
View File
@@ -32,13 +32,13 @@ type signallingv2 struct {
params Signallingv2Params
signalCache *protosignalling.Signalv2Cache
signalCache *protosignalling.Signalv2ServerMessageCache
}
func NewSignallingv2(params Signallingv2Params) ParticipantSignalling {
return &signallingv2{
params: params,
signalCache: protosignalling.NewSignalv2Cache(protosignalling.Signalv2CacheParams{
signalCache: protosignalling.NewSignalv2ServerMessageCache(protosignalling.SignalCacheParams{
Logger: params.Logger,
}),
}
+21
View File
@@ -224,3 +224,24 @@ func (s signalv2ParticipantService) RelaySignalv2Participant(ctx context.Context
WireMessage: wireMessage,
}, nil
}
func (s signalv2ParticipantService) RelaySignalv2ParticipantDeleteSession(
ctx context.Context,
req *rpc.RelaySignalv2ParticipantDeleteSessionRequest,
) (*emptypb.Empty, error) {
room := s.RoomManager.GetRoom(ctx, livekit.RoomName(req.Room))
if room == nil {
return nil, ErrRoomNotFound
}
lp := room.GetParticipantByID(livekit.ParticipantID(req.ParticipantId))
if lp != nil {
room.RemoveParticipant(
lp.Identity(),
lp.ID(),
types.ParticipantCloseReasonClientRequestLeave,
)
}
return &emptypb.Empty{}, nil
}
+54
View File
@@ -75,6 +75,7 @@ func (s *RTCv2Service) SetupRoutes(mux *http.ServeMux) {
mux.HandleFunc("POST "+cRTCv2Path, s.handlePost)
mux.HandleFunc("GET "+cRTCv2Path, s.validate)
mux.HandleFunc("PATCH "+cRTCv2ParticipantIDPath, s.handleParticipantPatch)
mux.HandleFunc("DELETE "+cRTCv2ParticipantIDPath, s.handleParticipantDelete)
}
func (s *RTCv2Service) validateInternal(
@@ -293,6 +294,59 @@ func (s *RTCv2Service) handleParticipantPatch(w http.ResponseWriter, r *http.Req
w.WriteHeader(http.StatusOK)
}
func (s *RTCv2Service) handleParticipantDelete(w http.ResponseWriter, r *http.Request) {
claims := GetGrants(r.Context())
if claims == nil || claims.Video == nil {
HandleErrorJson(w, r, http.StatusUnauthorized, rtc.ErrPermissionDenied)
return
}
roomName, err := EnsureJoinPermission(r.Context())
if err != nil {
HandleErrorJson(w, r, http.StatusUnauthorized, err)
return
}
if roomName == "" {
HandleErrorJson(w, r, http.StatusUnauthorized, ErrNoRoomName)
return
}
participantIdentity := livekit.ParticipantIdentity(claims.Identity)
if participantIdentity == "" {
HandleErrorJson(w, r, http.StatusUnauthorized, ErrIdentityEmpty)
return
}
pID := livekit.ParticipantID(r.PathValue("participant_id"))
if pID == "" {
HandleErrorJson(w, r, http.StatusBadRequest, ErrParticipantSidEmpty)
return
}
_, err = s.signalv2ParticipantClient.RelaySignalv2ParticipantDeleteSession(
r.Context(),
s.topicFormatter.ParticipantTopic(r.Context(), roomName, participantIdentity),
&rpc.RelaySignalv2ParticipantDeleteSessionRequest{
Room: string(roomName),
ParticipantIdentity: string(participantIdentity),
ParticipantId: string(pID),
},
)
if err != nil {
HandleErrorJson(w, r, http.StatusBadRequest, err)
return
}
logger.Debugw(
"participant deleted",
"room", roomName,
"participant", participantIdentity,
"pID", pID,
)
w.WriteHeader(http.StatusOK)
}
// ---------------------------------------
func getWireMessage(r *http.Request) (*livekit.Signalv2WireMessage, error) {