neko/internal/api/room/handler.go

64 lines
1.5 KiB
Go
Raw Normal View History

2020-10-30 18:16:21 +01:00
package room
import (
"github.com/go-chi/chi"
"demodesk/neko/internal/types"
2020-11-16 19:37:52 +01:00
"demodesk/neko/internal/http/auth"
2020-10-30 18:16:21 +01:00
)
type RoomHandler struct {
sessions types.SessionManager
desktop types.DesktopManager
capture types.CaptureManager
2020-10-30 18:16:21 +01:00
}
func New(
sessions types.SessionManager,
2020-11-01 16:54:06 +01:00
desktop types.DesktopManager,
capture types.CaptureManager,
2020-10-30 18:16:21 +01:00
) *RoomHandler {
// Init
2020-10-30 18:16:21 +01:00
return &RoomHandler{
sessions: sessions,
desktop: desktop,
capture: capture,
2020-10-30 18:16:21 +01:00
}
}
2020-11-14 18:16:25 +01:00
func (h *RoomHandler) Route(r chi.Router) {
2020-11-18 21:56:42 +01:00
r.With(auth.AdminsOnly).Route("/broadcast", func(r chi.Router) {
2020-11-18 22:35:50 +01:00
r.Get("/", h.broadcastStatus)
r.Post("/start", h.boradcastStart)
r.Post("/stop", h.boradcastStop)
2020-10-31 10:48:24 +01:00
})
2020-10-30 18:16:21 +01:00
2020-11-16 19:37:52 +01:00
r.With(auth.HostsOnly).Route("/clipboard", func(r chi.Router) {
2020-11-18 22:35:50 +01:00
r.Get("/", h.clipboardRead)
r.Post("/", h.clipboardWrite)
2020-10-31 12:35:02 +01:00
})
2020-11-16 22:48:20 +01:00
2020-11-18 21:56:42 +01:00
r.With(auth.HostsOnly).Route("/keyboard", func(r chi.Router) {
2020-11-18 22:35:50 +01:00
r.Post("/layout", h.keyboardLayoutSet)
r.Post("/modifiers", h.keyboardModifiersSet)
2020-11-18 21:56:42 +01:00
})
2020-11-16 22:48:20 +01:00
r.Route("/control", func(r chi.Router) {
2020-11-18 23:14:28 +01:00
r.Get("/", h.controlStatus)
2020-11-18 22:35:50 +01:00
r.Post("/request", h.controlRequest)
r.Post("/release", h.controlRelease)
2020-11-18 22:35:50 +01:00
r.With(auth.AdminsOnly).Post("/take", h.controlTake)
r.With(auth.AdminsOnly).Post("/give", h.controlGive)
2020-11-29 15:58:26 +01:00
r.With(auth.AdminsOnly).Post("/reset", h.controlReset)
2020-11-16 22:48:20 +01:00
})
2020-11-18 21:56:42 +01:00
r.Route("/screen", func(r chi.Router) {
2020-11-18 22:35:50 +01:00
r.Get("/", h.screenConfiguration)
2020-11-18 21:53:06 +01:00
2020-11-18 22:35:50 +01:00
r.With(auth.AdminsOnly).Post("/", h.screenConfigurationChange)
r.With(auth.AdminsOnly).Get("/configurations", h.screenConfigurationsList)
2020-11-18 21:53:06 +01:00
})
2020-10-30 18:16:21 +01:00
}