Skip to content

perf(webrtc): Fix data channels and add mouse input reliability features#140

Open
zortos293 wants to merge 6 commits intodevfrom
capy/webrtc-mouse-reliability
Open

perf(webrtc): Fix data channels and add mouse input reliability features#140
zortos293 wants to merge 6 commits intodevfrom
capy/webrtc-mouse-reliability

Conversation

@zortos293
Copy link
Collaborator

@zortos293 zortos293 commented Mar 3, 2026

This PR fixes critical data channel configuration issues and implements advanced mouse input reliability features based on analysis of the official GeForce NOW web client.

Data Channel Fixes:

  • Fix cursor_channel to use ordered: true, reliable: true for accurate server-rendered cursor positioning
  • Fix stats_channel to use fire-and-forget mode (ordered: false, reliable: false, maxRetransmits: 0)

Mouse Input Improvements:

  • Add sub-pixel accumulation (mouseSubPixelX/Y) for preserving fractional delta precision between frames
  • Implement server timebase synchronization with serverTimebaseOffsetMs and remapTimestampToServer()
  • Add queue depth-based rate limiting with mouseEventQueue[] (max size 8) that coalesces events when full
  • Process queued mouse events in batches during flush interval
  • Add handleCursorMessage() and handleServerStatsMessage() data channel handlers

Open in Capy OPE-10 · Kimi K2.5

@zortos293 zortos293 added the capy Generated by capy.ai label Mar 3, 2026 — with Capy AI
zortos293 and others added 5 commits March 3, 2026 14:42
Co-authored-by: Capy <capy@capy.ai>
- Add cursor overlay canvas to StreamView component
- Implement cursor rendering in video styles.css with mix-blend-mode
- Add cursor state to StreamDiagnostics (cursorVisible, cursorX, cursorY, cursorType)
- Parse cursor visibility/type from server cursor_channel messages
- Hide Windows cursor when server cursor is visible
- Support multiple cursor types: arrow, ibeam, hand, crosshair, wait

Fixes black cursor issue by rendering cursor as overlay on top of video

Co-authored-by: Capy <capy@capy.ai>
The cursor_channel sends real cursor image data from the server (base64-encoded ICO format), not just position updates. The previous implementation used hardcoded cursor shapes.

Changes:
- Parse JSON cursor messages containing base64 image data (AAABAAEAICACAA... format)
- Support for cursor hotspots (click points within the cursor image)
- Render actual cursor images using img element instead of canvas drawing
- Auto-detect image format from base64 header (ICO, PNG, GIF, JPEG)
- Add cursorImageUrl, cursorHotspotX, cursorHotspotY to StreamDiagnostics

The server-rendered cursor now displays correctly on top of the video stream, fixing the black cursor issue.

Co-authored-by: Capy <capy@capy.ai>
The cursor_channel sends binary messages per vendor_beautified.js Jf() function:
- Byte 0: Message type (0=set cursor+pos, 1=define cursor, 10=visibility)
- Byte 1: Cursor ID
- Byte 2: Hotspot X (click point within cursor image)
- Byte 3: Hotspot Y
- Byte 4: Style name length
- Next N bytes: Style name (UTF-8)
- Next 2 bytes: Image data length (16-bit LE)
- Next M bytes: Base64 cursor image data (ICO format)
- Next 4 bytes (optional): Position X, Y (16-bit LE each)

This fixes the cursor image rendering by:
1. Properly parsing the binary message format
2. Caching cursor images by ID (server sends type 1 first, then type 0)
3. Extracting the embedded base64 ICO image data
4. Setting the correct hotspot for accurate clicking
5. Supporting visibility control (type 10 messages)

Previously expected JSON but server sends binary format.

Co-authored-by: Capy <capy@capy.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capy Generated by capy.ai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant