mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
handle use webrtc logger.
This commit is contained in:
parent
e8aab98012
commit
c2b29ccf21
@ -9,11 +9,15 @@ import (
|
|||||||
"github.com/demodesk/neko/internal/webrtc/payload"
|
"github.com/demodesk/neko/internal/webrtc/payload"
|
||||||
"github.com/demodesk/neko/pkg/types"
|
"github.com/demodesk/neko/pkg/types"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) handle(data []byte, dataChannel *webrtc.DataChannel, session types.Session) error {
|
func (manager *WebRTCManagerCtx) handle(
|
||||||
// add session id to logger context
|
logger zerolog.Logger, data []byte,
|
||||||
logger := manager.logger.With().Str("session_id", session.ID()).Logger()
|
dataChannel *webrtc.DataChannel,
|
||||||
|
session types.Session,
|
||||||
|
) error {
|
||||||
|
isHost := session.IsHost()
|
||||||
|
|
||||||
//
|
//
|
||||||
// parse header
|
// parse header
|
||||||
@ -38,7 +42,7 @@ func (manager *WebRTCManagerCtx) handle(data []byte, dataChannel *webrtc.DataCha
|
|||||||
}
|
}
|
||||||
|
|
||||||
x, y := int(payload.X), int(payload.Y)
|
x, y := int(payload.X), int(payload.Y)
|
||||||
if session.IsHost() {
|
if isHost {
|
||||||
// handle active cursor movement
|
// handle active cursor movement
|
||||||
manager.desktop.Move(x, y)
|
manager.desktop.Move(x, y)
|
||||||
manager.curPosition.Set(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
|
// continue only if session is host
|
||||||
if !session.IsHost() {
|
if !isHost {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
|
|||||||
})
|
})
|
||||||
|
|
||||||
dataChannel.OnMessage(func(message webrtc.DataChannelMessage) {
|
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")
|
logger.Err(err).Msg("data handle failed")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user