WebRTC ping over data channel (#23)

* add datachannel ping to webrtc.

* add ping pong decode func.
This commit is contained in:
Miroslav Šedivý
2023-01-20 23:08:27 +01:00
committed by GitHub
parent ba0dea8022
commit 813a0da30c
4 changed files with 63 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package payload
import "math"
const (
OP_MOVE = 0x01
OP_SCROLL = 0x02
@ -7,6 +9,7 @@ const (
OP_KEY_UP = 0x04
OP_BTN_DOWN = 0x05
OP_BTN_UP = 0x06
OP_PING = 0x07
)
type Move struct {
@ -28,3 +31,15 @@ type Key struct {
Key uint32
}
type Ping struct {
Header
// client's timestamp split into two uint32
ClientTs1 uint32
ClientTs2 uint32
}
func (p Ping) ClientTs() uint64 {
return (uint64(p.ClientTs1) * uint64(math.MaxUint32)) + uint64(p.ClientTs2)
}

View File

@ -1,8 +1,11 @@
package payload
import "math"
const (
OP_CURSOR_POSITION = 0x01
OP_CURSOR_IMAGE = 0x02
OP_PONG = 0x03
)
type CursorPosition struct {
@ -20,3 +23,15 @@ type CursorImage struct {
Xhot uint16
Yhot uint16
}
type Pong struct {
Ping
// server's timestamp split into two uint32
ServerTs1 uint32
ServerTs2 uint32
}
func (p Pong) ServerTs() uint64 {
return (uint64(p.ServerTs1) * uint64(math.MaxUint32)) + uint64(p.ServerTs2)
}