Feature: Draw the remote cursor in the web desktop out of control mode
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
This commit is contained in:
1 parent
6236ed1eb4
commit
bfb17d0d25
12 files changed
+322
-65
No files matched your search
@@ -58,6 +58,7 @@ type captureHandler struct {
|
||||
online []string
|
||||
offline []string
|
||||
updates []string // formatted "id:rtt"
|
||||
cursors [][3]int // recorded {index, x, y}
|
||||
}
|
||||
|
||||
func (c *captureHandler) OnDeviceOnline(d DeviceInfo) {
|
||||
@@ -82,7 +83,11 @@ func (c *captureHandler) OnScreenFrame(_ string, _ []byte, _ bool) {}
|
||||
|
||||
func (c *captureHandler) OnResolutionChange(_ string, _, _ int) {}
|
||||
|
||||
func (c *captureHandler) OnCursorChange(_ string, _ byte) {}
|
||||
func (c *captureHandler) OnCursorChange(_ string, index byte, x, y int) {
|
||||
c.mu.Lock()
|
||||
c.cursors = append(c.cursors, [3]int{int(index), x, y})
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *captureHandler) OnClipboardText(_ string, _ string) {}
|
||||
|
||||
@@ -225,3 +230,72 @@ func TestHubConcurrent(t *testing.T) {
|
||||
t.Fatalf("after all unregisters: want 0, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The web console draws the remote cursor itself while the user is not in
|
||||
// control mode, so the hub must deliver the position reliably but without
|
||||
// relaying every ~30 Hz frame to every viewer.
|
||||
func TestPublishCursorDedupAndThrottle(t *testing.T) {
|
||||
h := New()
|
||||
c := &captureHandler{}
|
||||
h.Subscribe(c)
|
||||
h.Register(&Device{ID: "d", Name: "d"}, stubCtx())
|
||||
|
||||
// First report always goes out, even for the zero value.
|
||||
h.PublishCursor("d", 1, 10, 20)
|
||||
if len(c.cursors) != 1 || c.cursors[0] != [3]int{1, 10, 20} {
|
||||
t.Fatalf("first publish: %+v", c.cursors)
|
||||
}
|
||||
|
||||
// Identical report: suppressed.
|
||||
h.PublishCursor("d", 1, 10, 20)
|
||||
if len(c.cursors) != 1 {
|
||||
t.Fatalf("identical report should be dropped: %+v", c.cursors)
|
||||
}
|
||||
|
||||
// Position-only change inside the throttle window: suppressed.
|
||||
h.PublishCursor("d", 1, 11, 21)
|
||||
if len(c.cursors) != 1 {
|
||||
t.Fatalf("position-only change should be throttled: %+v", c.cursors)
|
||||
}
|
||||
|
||||
// Shape change bypasses the throttle.
|
||||
h.PublishCursor("d", 5, 12, 22)
|
||||
if len(c.cursors) != 2 || c.cursors[1] != [3]int{5, 12, 22} {
|
||||
t.Fatalf("shape change should be immediate: %+v", c.cursors)
|
||||
}
|
||||
|
||||
// After the window a position-only change is delivered again.
|
||||
time.Sleep(cursorMinInterval + 10*time.Millisecond)
|
||||
h.PublishCursor("d", 5, 13, 23)
|
||||
if len(c.cursors) != 3 || c.cursors[2] != [3]int{5, 13, 23} {
|
||||
t.Fatalf("post-window move: %+v", c.cursors)
|
||||
}
|
||||
|
||||
// Unknown device: no event, no panic.
|
||||
h.PublishCursor("ghost", 1, 0, 0)
|
||||
if len(c.cursors) != 3 {
|
||||
t.Fatalf("unknown device should not publish: %+v", c.cursors)
|
||||
}
|
||||
}
|
||||
|
||||
// A viewer joining while the pointer is idle must still learn its position:
|
||||
// the hub re-sends an unchanged cursor once the refresh interval passes.
|
||||
func TestPublishCursorRefreshesIdleState(t *testing.T) {
|
||||
h := New()
|
||||
c := &captureHandler{}
|
||||
h.Subscribe(c)
|
||||
h.Register(&Device{ID: "d", Name: "d"}, stubCtx())
|
||||
|
||||
h.PublishCursor("d", 3, 100, 200)
|
||||
time.Sleep(cursorRefreshInterval / 2)
|
||||
h.PublishCursor("d", 3, 100, 200) // inside the refresh window: dropped
|
||||
if len(c.cursors) != 1 {
|
||||
t.Fatalf("duplicate inside refresh window should be dropped: %+v", c.cursors)
|
||||
}
|
||||
|
||||
time.Sleep(cursorRefreshInterval/2 + 50*time.Millisecond)
|
||||
h.PublishCursor("d", 3, 100, 200) // stale: re-published for late joiners
|
||||
if len(c.cursors) != 2 || c.cursors[1] != [3]int{3, 100, 200} {
|
||||
t.Fatalf("idle refresh missing: %+v", c.cursors)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user