handle use webrtc logger.

This commit is contained in:
Miroslav Šedivý 2023-04-17 00:47:34 +02:00
parent e8aab98012
commit c2b29ccf21
2 changed files with 10 additions and 6 deletions

View File

@ -9,11 +9,15 @@ import (
"github.com/demodesk/neko/internal/webrtc/payload"
"github.com/demodesk/neko/pkg/types"
"github.com/pion/webrtc/v3"
"github.com/rs/zerolog"
)
func (manager *WebRTCManagerCtx) handle(data []byte, dataChannel *webrtc.DataChannel, session types.Session) error {
// add session id to logger context
logger := manager.logger.With().Str("session_id", session.ID()).Logger()
func (manager *WebRTCManagerCtx) handle(
logger zerolog.Logger, data []byte,
dataChannel *webrtc.DataChannel,
session types.Session,
) error {
isHost := session.IsHost()
//
// parse header
@ -38,7 +42,7 @@ func (manager *WebRTCManagerCtx) handle(data []byte, dataChannel *webrtc.DataCha
}
x, y := int(payload.X), int(payload.Y)
if session.IsHost() {
if isHost {
// handle active cursor movement
manager.desktop.Move(x, y)
manager.curPosition.Set(x, y)
@ -87,7 +91,7 @@ func (manager *WebRTCManagerCtx) handle(data []byte, dataChannel *webrtc.DataCha
}
// continue only if session is host
if !session.IsHost() {
if !isHost {
return nil
}

View File

@ -562,7 +562,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
})
dataChannel.OnMessage(func(message webrtc.DataChannelMessage) {
if err := manager.handle(message.Data, dataChannel, session); err != nil {
if err := manager.handle(logger, message.Data, dataChannel, session); err != nil {
logger.Err(err).Msg("data handle failed")
}
})