From f9b62073ef88cc21b0539b4b6c57c65ab2143c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 29 Nov 2020 15:58:26 +0100 Subject: [PATCH] add control reset. --- internal/api/room/control.go | 18 ++++++++++++++++++ internal/api/room/handler.go | 1 + 2 files changed, 19 insertions(+) diff --git a/internal/api/room/control.go b/internal/api/room/control.go index 7539ae26..05d7fd55 100644 --- a/internal/api/room/control.go +++ b/internal/api/room/control.go @@ -106,3 +106,21 @@ func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) { utils.HttpSuccess(w) } + +func (h *RoomHandler) controlReset(w http.ResponseWriter, r *http.Request) { + host := h.sessions.GetHost() + if host == nil { + utils.HttpSuccess(w) + return + } + + h.sessions.ClearHost() + + h.sessions.Broadcast( + message.Control{ + Event: event.CONTROL_RELEASE, + ID: host.ID(), + }, nil) + + utils.HttpSuccess(w) +} diff --git a/internal/api/room/handler.go b/internal/api/room/handler.go index cca2b044..a073f7a0 100644 --- a/internal/api/room/handler.go +++ b/internal/api/room/handler.go @@ -58,6 +58,7 @@ func (h *RoomHandler) Route(r chi.Router) { r.With(auth.AdminsOnly).Post("/take", h.controlTake) r.With(auth.AdminsOnly).Post("/give", h.controlGive) + r.With(auth.AdminsOnly).Post("/reset", h.controlReset) }) r.Route("/screen", func(r chi.Router) {