2020-10-31 06:16:21 +13:00
|
|
|
package room
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-chi/chi"
|
2020-11-17 09:57:53 +13:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
2020-10-31 06:16:21 +13:00
|
|
|
|
|
|
|
"demodesk/neko/internal/types"
|
2020-11-17 07:37:52 +13:00
|
|
|
"demodesk/neko/internal/http/auth"
|
2020-10-31 06:16:21 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
type RoomHandler struct {
|
2020-11-17 09:57:53 +13:00
|
|
|
logger zerolog.Logger
|
2020-11-02 04:54:06 +13:00
|
|
|
sessions types.SessionManager
|
|
|
|
desktop types.DesktopManager
|
2020-11-17 09:57:53 +13:00
|
|
|
capture types.CaptureManager
|
2020-10-31 06:16:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(
|
|
|
|
sessions types.SessionManager,
|
2020-11-02 04:54:06 +13:00
|
|
|
desktop types.DesktopManager,
|
|
|
|
capture types.CaptureManager,
|
2020-10-31 06:16:21 +13:00
|
|
|
) *RoomHandler {
|
2020-11-17 09:57:53 +13:00
|
|
|
logger := log.With().
|
|
|
|
Str("module", "api").
|
|
|
|
Str("submodule", "room").
|
|
|
|
Logger()
|
2020-10-31 06:16:21 +13:00
|
|
|
|
|
|
|
return &RoomHandler{
|
2020-11-17 09:57:53 +13:00
|
|
|
logger: logger,
|
2020-11-02 04:54:06 +13:00
|
|
|
sessions: sessions,
|
|
|
|
desktop: desktop,
|
|
|
|
capture: capture,
|
2020-10-31 06:16:21 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 06:16:25 +13:00
|
|
|
func (h *RoomHandler) Route(r chi.Router) {
|
2020-11-01 00:27:55 +13:00
|
|
|
r.Route("/screen", func(r chi.Router) {
|
2020-11-15 05:51:18 +13:00
|
|
|
r.Get("/", h.ScreenConfiguration)
|
2020-11-01 00:27:55 +13:00
|
|
|
|
2020-11-17 07:37:52 +13:00
|
|
|
r.With(auth.AdminsOnly).Post("/", h.ScreenConfigurationChange)
|
|
|
|
r.With(auth.AdminsOnly).Get("/configurations", h.ScreenConfigurationsList)
|
2020-10-31 22:48:24 +13:00
|
|
|
})
|
2020-10-31 06:16:21 +13:00
|
|
|
|
2020-11-17 07:37:52 +13:00
|
|
|
r.With(auth.HostsOnly).Route("/clipboard", func(r chi.Router) {
|
2020-11-01 00:35:02 +13:00
|
|
|
r.Get("/", h.ClipboardRead)
|
|
|
|
r.Post("/", h.ClipboardWrite)
|
|
|
|
})
|
2020-11-17 10:48:20 +13:00
|
|
|
|
|
|
|
r.Route("/control", func(r chi.Router) {
|
|
|
|
r.Post("/request", h.ControlRequest)
|
|
|
|
r.Post("/release", h.ControlRelease)
|
2020-11-19 09:10:40 +13:00
|
|
|
|
|
|
|
r.With(auth.AdminsOnly).Post("/take", h.ControlTake)
|
|
|
|
r.With(auth.AdminsOnly).Post("/give", h.ControlGive)
|
2020-11-17 10:48:20 +13:00
|
|
|
})
|
2020-11-19 09:34:39 +13:00
|
|
|
|
|
|
|
r.With(auth.AdminsOnly).Route("/broadcast", func(r chi.Router) {
|
|
|
|
r.Get("/", h.BroadcastStatus)
|
|
|
|
r.Post("/start", h.BoradcastStart)
|
|
|
|
r.Post("/stop", h.BoradcastStop)
|
|
|
|
})
|
2020-10-31 06:16:21 +13:00
|
|
|
}
|