mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 15:35:41 +00:00
HTTP DELETE of participant session (#3819)
This commit is contained in:
4
go.mod
4
go.mod
@@ -23,8 +23,8 @@ require (
|
||||
github.com/jxskiss/base62 v1.1.0
|
||||
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731
|
||||
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded
|
||||
github.com/livekit/protocol v1.39.4-0.20250724043230-34c7a0eb632f
|
||||
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c
|
||||
github.com/livekit/protocol v1.39.4-0.20250724172257-afef3ef967cc
|
||||
github.com/livekit/psrpc v0.6.1-0.20250724161801-262a822e7cd7
|
||||
github.com/mackerelio/go-osstat v0.2.5
|
||||
github.com/magefile/mage v1.15.0
|
||||
github.com/maxbrunsfeld/counterfeiter/v6 v6.11.2
|
||||
|
||||
8
go.sum
8
go.sum
@@ -167,10 +167,10 @@ github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5AT
|
||||
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
|
||||
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded h1:ylZPdnlX1RW9Z15SD4mp87vT2D2shsk0hpLJwSPcq3g=
|
||||
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
|
||||
github.com/livekit/protocol v1.39.4-0.20250724043230-34c7a0eb632f h1:kdn/KF/2IRCQCXZWvm9RxKN4u79olHRZKo2JDxr/kPw=
|
||||
github.com/livekit/protocol v1.39.4-0.20250724043230-34c7a0eb632f/go.mod h1:YlgUxAegtU8jZ0tVXoIV/4fHeHqqLvS+6JnPKDbpFPU=
|
||||
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c h1:WwEr0YBejYbKzk8LSaO9h8h0G9MnE7shyDu8yXQWmEc=
|
||||
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c/go.mod h1:kmD+AZPkWu0MaXIMv57jhNlbiSZZ/Jx4bzlxBDVmJes=
|
||||
github.com/livekit/protocol v1.39.4-0.20250724172257-afef3ef967cc h1:kF9ju/WEqtzMhI3P9hCUcgoh1mFEuq7DuWPkji6iq/M=
|
||||
github.com/livekit/protocol v1.39.4-0.20250724172257-afef3ef967cc/go.mod h1:YlgUxAegtU8jZ0tVXoIV/4fHeHqqLvS+6JnPKDbpFPU=
|
||||
github.com/livekit/psrpc v0.6.1-0.20250724161801-262a822e7cd7 h1:x50axcjXwfwnII7sMhJPyZ6f5LpPapZtsp75KJX8nIQ=
|
||||
github.com/livekit/psrpc v0.6.1-0.20250724161801-262a822e7cd7/go.mod h1:kmD+AZPkWu0MaXIMv57jhNlbiSZZ/Jx4bzlxBDVmJes=
|
||||
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
|
||||
github.com/mackerelio/go-osstat v0.2.5/go.mod h1:atxwWF+POUZcdtR1wnsUcQxTytoHG4uhl2AKKzrOajY=
|
||||
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user