feat(webrtc): add admin option to mute other participants
This commit is contained in:
@@ -7,27 +7,32 @@ import (
|
||||
|
||||
"git.dustin.coffee/hobokenchicken/dumpsterChat/internal/gateway"
|
||||
"git.dustin.coffee/hobokenchicken/dumpsterChat/internal/middleware"
|
||||
"git.dustin.coffee/hobokenchicken/dumpsterChat/internal/permissions"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
db *sql.DB
|
||||
client *Client
|
||||
hub *gateway.Hub
|
||||
db *sql.DB
|
||||
client *Client
|
||||
hub *gateway.Hub
|
||||
checker *permissions.Checker
|
||||
}
|
||||
|
||||
func NewHandler(db *sql.DB, client *Client, hub *gateway.Hub) *Handler {
|
||||
return &Handler{
|
||||
db: db,
|
||||
client: client,
|
||||
hub: hub,
|
||||
db: db,
|
||||
client: client,
|
||||
hub: hub,
|
||||
checker: permissions.NewChecker(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) RegisterRoutes(r chi.Router) {
|
||||
r.Use(middleware.RequireAuth)
|
||||
r.Post("/token", h.GetToken)
|
||||
r.Get("/rooms/{roomID}/participants", h.GetParticipants)
|
||||
r.Post("/rooms/{roomID}/participants/{userID}/mute", h.MuteParticipant)
|
||||
}
|
||||
|
||||
type tokenRequest struct {
|
||||
@@ -148,3 +153,53 @@ func (h *Handler) GetParticipants(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
|
||||
// @Summary Mute a participant
|
||||
// @Description Mute a participant's tracks in a voice room (requires MUTE_MEMBERS permission)
|
||||
// @Tags voice
|
||||
// @Security SessionAuth
|
||||
// @Param roomID path string true "Room ID"
|
||||
// @Param userID path string true "User ID (Identity)"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Router /voice/rooms/{roomID}/participants/{userID}/mute [post]
|
||||
func (h *Handler) MuteParticipant(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := chi.URLParam(r, "roomID")
|
||||
targetIdentity := chi.URLParam(r, "userID")
|
||||
|
||||
userID, ok := middleware.UserIDFromContext(r.Context())
|
||||
if !ok {
|
||||
http.Error(w, `{"error":"unauthorized"}`, http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// Find the server_id for this channel to check permissions.
|
||||
var serverID string
|
||||
err := h.db.QueryRowContext(r.Context(), `SELECT server_id FROM channels WHERE id = $1`, roomID).Scan(&serverID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
http.Error(w, `{"error":"room not found or not a server channel"}`, http.StatusNotFound)
|
||||
} else {
|
||||
http.Error(w, `{"error":"database error"}`, http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
hasPerm, err := h.checker.CheckChannelPermission(r.Context(), serverID, userID, roomID, permissions.MUTE_MEMBERS)
|
||||
if err != nil {
|
||||
http.Error(w, `{"error":"failed to check permissions"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !hasPerm {
|
||||
http.Error(w, `{"error":"forbidden: missing MUTE_MEMBERS permission"}`, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.client.MuteParticipant(roomID, targetIdentity); err != nil {
|
||||
http.Error(w, `{"error":"failed to mute participant"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user