Screen frames are captured without the pointer composed in (GDI SRCCOPY, DXGI), so browsers only ever knew the cursor's shape index and could show a cursor just in control mode, where the local pointer stands in for the remote one. Both servers now relay the cursor position that every per-frame header already carries: shape changes go out immediately, position changes at most every 50 ms, and an unchanged cursor is re-sent once a second so a viewer that joins while the pointer is idle still learns where it is. The page hides the local pointer and draws the remote cursor at its true position while out of control mode; entering control mode restores exactly the old behaviour (remote-shaped CSS cursor on desktop, touchpad pointer on touch). A server that never sends x/y leaves the page on its previous fallback. The C++ server broadcasts from the per-frame path, so header-only frames keep a static desktop's cursor fresh; the Go hub dedups and throttles before fanning out. Tests cover the throttle/refresh rules and the relayed payload. Co-Authored-By: deepseek-flash
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package web
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// The non-controlling browser draws the remote cursor itself, so the relayed
|
|
// "cursor" message must carry the position, not just the shape index. Without
|
|
// x/y an older page still works (it ignores unknown fields), but the new
|
|
// overlay has nothing to place.
|
|
func TestOnCursorChangeCarriesPosition(t *testing.T) {
|
|
c := &wsClient{
|
|
send: make(chan wsMsg, 4),
|
|
closed: make(chan struct{}),
|
|
token: "tok",
|
|
watchIDs: map[string]struct{}{"42": {}},
|
|
}
|
|
h := &wsHub{clients: map[*wsClient]struct{}{c: {}}}
|
|
|
|
h.OnCursorChange("42", 5, 1280, 720)
|
|
|
|
var msg struct {
|
|
Cmd string `json:"cmd"`
|
|
ID string `json:"id"`
|
|
Index int `json:"index"`
|
|
X *int `json:"x"`
|
|
Y *int `json:"y"`
|
|
}
|
|
m := <-c.send
|
|
if m.binary {
|
|
t.Fatal("cursor message must be a text frame")
|
|
}
|
|
if err := json.Unmarshal(m.data, &msg); err != nil {
|
|
t.Fatalf("unmarshal %s: %v", m.data, err)
|
|
}
|
|
if msg.Cmd != "cursor" || msg.ID != "42" || msg.Index != 5 {
|
|
t.Fatalf("message = %+v", msg)
|
|
}
|
|
if msg.X == nil || msg.Y == nil || *msg.X != 1280 || *msg.Y != 720 {
|
|
t.Fatalf("position missing: x=%v y=%v (raw %s)", msg.X, msg.Y, m.data)
|
|
}
|
|
|
|
// A viewer not watching the device must not receive anything.
|
|
other := &wsClient{
|
|
send: make(chan wsMsg, 1),
|
|
closed: make(chan struct{}),
|
|
token: "tok",
|
|
watchIDs: map[string]struct{}{"7": {}},
|
|
}
|
|
h.clients[other] = struct{}{}
|
|
h.OnCursorChange("42", 5, 1, 1)
|
|
select {
|
|
case <-other.send:
|
|
t.Fatal("non-watching client received a cursor message")
|
|
default:
|
|
}
|
|
}
|