mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
api manager.
This commit is contained in:
45
internal/api/room/handler.go
Normal file
45
internal/api/room/handler.go
Normal file
@ -0,0 +1,45 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type RoomHandler struct {
|
||||
sessions types.SessionManager
|
||||
remote types.RemoteManager
|
||||
broadcast types.BroadcastManager
|
||||
websocket types.WebSocketHandler
|
||||
}
|
||||
|
||||
func New(
|
||||
sessions types.SessionManager,
|
||||
remote types.RemoteManager,
|
||||
broadcast types.BroadcastManager,
|
||||
websocket types.WebSocketHandler,
|
||||
) *RoomHandler {
|
||||
// Init
|
||||
|
||||
return &RoomHandler{
|
||||
sessions: sessions,
|
||||
remote: remote,
|
||||
broadcast: broadcast,
|
||||
websocket: websocket,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *RoomHandler) Router() *chi.Mux {
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Route("/resolution", func(r chi.Router) {
|
||||
r.Get("/", h.ResolutionGet)
|
||||
r.Post("/", h.ResolutionChange)
|
||||
|
||||
r.Get("/list", h.ResolutionList)
|
||||
})
|
||||
|
||||
// TODO
|
||||
|
||||
return r
|
||||
}
|
@ -1 +1,61 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
type ErrResponse struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type ResolutionStruct struct {
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Rate int `json:"rate"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ResolutionGet(w http.ResponseWriter, r *http.Request) {
|
||||
size := h.remote.GetScreenSize()
|
||||
|
||||
if size == nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
render.JSON(w, r, ErrResponse{
|
||||
Code: -1,
|
||||
Message: "Unable to get current screen resolution.",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
render.JSON(w, r, ResolutionStruct{
|
||||
Width: size.Width,
|
||||
Height: size.Height,
|
||||
Rate: int(size.Rate),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ResolutionChange(w http.ResponseWriter, r *http.Request) {
|
||||
// data := &ResolutionStruct{}
|
||||
// if err := render.Bind(r, data); err != nil {
|
||||
// render.JSON(w, r, ErrResponse{
|
||||
// Code: -1,
|
||||
// Message: "Invalid Request.",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
render.JSON(w, r, ErrResponse{
|
||||
Code: -1,
|
||||
Message: "Not implmented.",
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ResolutionList(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
render.JSON(w, r, ErrResponse{
|
||||
Code: -1,
|
||||
Message: "Not implmented.",
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user