mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
websocket handler simplified logging.
This commit is contained in:
parent
c2fe224562
commit
5130d94bbc
@ -1,21 +1,19 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.Profile().CanAccessClipboard {
|
||||
logger.Debug().Msg("cannot access clipboard")
|
||||
return nil
|
||||
return errors.New("cannot access clipboard")
|
||||
}
|
||||
|
||||
if !session.IsHost() {
|
||||
logger.Debug().Msg("is not the host")
|
||||
return nil
|
||||
return errors.New("is not the host")
|
||||
}
|
||||
|
||||
return h.desktop.ClipboardSetText(types.ClipboardText{
|
||||
|
@ -1,6 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
@ -26,16 +28,12 @@ func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.Profile().CanHost {
|
||||
logger.Debug().Msg("is not allowed to host")
|
||||
return nil
|
||||
return errors.New("is not allowed to host")
|
||||
}
|
||||
|
||||
if session.IsHost() {
|
||||
logger.Debug().Msg("is already the host")
|
||||
return nil
|
||||
return errors.New("is already the host")
|
||||
}
|
||||
|
||||
if !h.sessions.ImplicitHosting() {
|
||||
@ -53,6 +51,5 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
}
|
||||
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("message handler has failed")
|
||||
logger.Warn().Err(err).Msg("message handler has failed")
|
||||
}
|
||||
|
||||
return true
|
||||
|
@ -1,16 +1,15 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.KeyboardMap) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.IsHost() {
|
||||
logger.Debug().Msg("is not the host")
|
||||
return nil
|
||||
return errors.New("is not the host")
|
||||
}
|
||||
|
||||
return h.desktop.SetKeyboardMap(types.KeyboardMap{
|
||||
@ -20,11 +19,8 @@ func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.IsHost() {
|
||||
logger.Debug().Msg("is not the host")
|
||||
return nil
|
||||
return errors.New("is not the host")
|
||||
}
|
||||
|
||||
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
||||
|
@ -1,17 +1,16 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenSize) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.Profile().IsAdmin {
|
||||
logger.Debug().Msg("is not the admin")
|
||||
return nil
|
||||
return errors.New("is not the admin")
|
||||
}
|
||||
|
||||
if err := h.desktop.SetScreenSize(types.ScreenSize{
|
||||
|
@ -1,18 +1,17 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
receiver, ok := h.sessions.Get(payload.Receiver)
|
||||
if !ok {
|
||||
logger.Debug().Msg("receiver session ID not found")
|
||||
return nil
|
||||
return errors.New("receiver session ID not found")
|
||||
}
|
||||
|
||||
receiver.Send(
|
||||
|
@ -1,17 +1,16 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *message.SignalVideo) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
if !session.Profile().CanWatch {
|
||||
logger.Debug().Msg("not allowed to watch")
|
||||
return nil
|
||||
return errors.New("not allowed to watch")
|
||||
}
|
||||
|
||||
// use default first video, if not provided
|
||||
@ -37,12 +36,9 @@ func (h *MessageHandlerCtx) signalRequest(session types.Session, payload *messag
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
logger.Debug().Msg("webRTC peer does not exist")
|
||||
return nil
|
||||
return errors.New("webRTC peer does not exist")
|
||||
}
|
||||
|
||||
offer, err := peer.CreateOffer(true)
|
||||
@ -60,36 +56,27 @@ func (h *MessageHandlerCtx) signalRestart(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
logger.Debug().Msg("webRTC peer does not exist")
|
||||
return nil
|
||||
return errors.New("webRTC peer does not exist")
|
||||
}
|
||||
|
||||
return peer.SignalAnswer(payload.SDP)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalCandidate(session types.Session, payload *message.SignalCandidate) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
logger.Debug().Msg("webRTC peer does not exist")
|
||||
return nil
|
||||
return errors.New("webRTC peer does not exist")
|
||||
}
|
||||
|
||||
return peer.SignalCandidate(payload.ICECandidateInit)
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalVideo(session types.Session, payload *message.SignalVideo) error {
|
||||
logger := h.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
peer := session.GetWebRTCPeer()
|
||||
if peer == nil {
|
||||
logger.Debug().Msg("webRTC peer does not exist")
|
||||
return nil
|
||||
return errors.New("webRTC peer does not exist")
|
||||
}
|
||||
|
||||
err := peer.SetVideoID(payload.Video)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/types/event"
|
||||
"demodesk/neko/internal/types/message"
|
||||
@ -19,8 +21,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
|
||||
size := h.desktop.GetScreenSize()
|
||||
if size == nil {
|
||||
h.logger.Warn().Msg("could not get screen size")
|
||||
return nil
|
||||
return errors.New("could not get screen size")
|
||||
}
|
||||
|
||||
sessions := map[string]message.SessionData{}
|
||||
|
Loading…
Reference in New Issue
Block a user