mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package webrtc
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
|
|
"gitlab.com/demodesk/neko/server/internal/webrtc/payload"
|
|
"gitlab.com/demodesk/neko/server/pkg/types"
|
|
)
|
|
|
|
func (peer *WebRTCPeerCtx) SendCursorPosition(x, y int) error {
|
|
peer.mu.Lock()
|
|
defer peer.mu.Unlock()
|
|
|
|
if peer.dataChannel == nil {
|
|
return types.ErrWebRTCDataChannelNotFound
|
|
}
|
|
|
|
data := payload.CursorPosition{
|
|
Header: payload.Header{
|
|
Event: payload.OP_CURSOR_POSITION,
|
|
Length: 7,
|
|
},
|
|
X: uint16(x),
|
|
Y: uint16(y),
|
|
}
|
|
|
|
buffer := &bytes.Buffer{}
|
|
if err := binary.Write(buffer, binary.BigEndian, data); err != nil {
|
|
return err
|
|
}
|
|
|
|
return peer.dataChannel.Send(buffer.Bytes())
|
|
}
|
|
|
|
func (peer *WebRTCPeerCtx) SendCursorImage(cur *types.CursorImage, img []byte) error {
|
|
peer.mu.Lock()
|
|
defer peer.mu.Unlock()
|
|
|
|
if peer.dataChannel == nil {
|
|
return types.ErrWebRTCDataChannelNotFound
|
|
}
|
|
|
|
data := payload.CursorImage{
|
|
Header: payload.Header{
|
|
Event: payload.OP_CURSOR_IMAGE,
|
|
Length: uint16(11 + len(img)),
|
|
},
|
|
Width: cur.Width,
|
|
Height: cur.Height,
|
|
Xhot: cur.Xhot,
|
|
Yhot: cur.Yhot,
|
|
}
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
if err := binary.Write(buffer, binary.BigEndian, data); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := binary.Write(buffer, binary.BigEndian, img); err != nil {
|
|
return err
|
|
}
|
|
|
|
return peer.dataChannel.Send(buffer.Bytes())
|
|
}
|