mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add customized WebRTC send functions.
This commit is contained in:
parent
c54703d7d7
commit
af3a28274d
@ -5,9 +5,11 @@ import "github.com/pion/webrtc/v3"
|
||||
type WebRTCPeer interface {
|
||||
SignalAnswer(sdp string) error
|
||||
SignalCandidate(candidate webrtc.ICECandidateInit) error
|
||||
SetVideoID(videoID string) error
|
||||
|
||||
Send(data []byte) error
|
||||
SetVideoID(videoID string) error
|
||||
SendCursorPosition(x, y int) error
|
||||
SendCursorImage(cur *CursorImage) error
|
||||
|
||||
Destroy() error
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,6 @@ func (webrtc_peer *WebRTCPeerCtx) SetVideoID(videoID string) error {
|
||||
return webrtc_peer.changeVideo(videoID)
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) Send(data []byte) error {
|
||||
if webrtc_peer.dataChannel == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return webrtc_peer.dataChannel.Send(data)
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
|
||||
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
|
||||
return nil
|
||||
|
75
internal/webrtc/send.go
Normal file
75
internal/webrtc/send.go
Normal file
@ -0,0 +1,75 @@
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
OP_CURSOR_POSITION = 0x01
|
||||
OP_CURSOR_IMAGE = 0x02
|
||||
)
|
||||
|
||||
type PayloadCursorPosition struct {
|
||||
PayloadHeader
|
||||
X uint16
|
||||
Y uint16
|
||||
}
|
||||
|
||||
type PayloadCursorImage struct {
|
||||
PayloadHeader
|
||||
Width uint16
|
||||
Height uint16
|
||||
Xhot uint16
|
||||
Yhot uint16
|
||||
Uri string
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) SendCursorPosition(x, y int) error {
|
||||
if webrtc_peer.dataChannel == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
data := PayloadCursorPosition{
|
||||
PayloadHeader: PayloadHeader{
|
||||
Event: OP_CURSOR_POSITION,
|
||||
Length: 7,
|
||||
},
|
||||
X: uint16(x),
|
||||
Y: uint16(y),
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
binary.Write(&buffer, binary.LittleEndian, data)
|
||||
return webrtc_peer.dataChannel.Send(buffer.Bytes())
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) SendCursorImage(cur *types.CursorImage) error {
|
||||
if webrtc_peer.dataChannel == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
uri, err := utils.GetCursorImageURI(cur)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := PayloadCursorImage{
|
||||
PayloadHeader: PayloadHeader{
|
||||
Event: OP_CURSOR_IMAGE,
|
||||
Length: uint16(11 + len(uri)),
|
||||
},
|
||||
Width: cur.Width,
|
||||
Height: cur.Height,
|
||||
Xhot: cur.Xhot,
|
||||
Yhot: cur.Yhot,
|
||||
Uri: uri,
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
binary.Write(&buffer, binary.LittleEndian, data)
|
||||
return webrtc_peer.dataChannel.Send(buffer.Bytes())
|
||||
}
|
Loading…
Reference in New Issue
Block a user