Skip to main content

Input Data Channels

CloudGaming uses dedicated WebRTC data channels to transmit user input from the client to the host with minimal latency. Each input type uses an optimized channel configuration based on its reliability requirements.

Channel Configuration

keyPressChannel (Keyboard Input)

The keyboard channel uses ordered, reliable delivery to ensure no key events are lost or received out of order.
Source: Client/html-server/index.html:1369 Why ordered and reliable?
  • Key sequences must be preserved (e.g., Ctrl+C)
  • Missing key events cause stuck keys
  • Order matters for text input and shortcuts

mouseChannel (Mouse Input)

The mouse channel uses unordered, unreliable delivery with no retransmissions for lowest possible latency.
Source: Client/html-server/index.html:1370 Why unordered and unreliable?
  • Mouse movements are rapidly superseded by newer positions
  • Retransmitting old mouse positions causes lag
  • Missing one mouse event is imperceptible
  • Immediate delivery is more important than reliability

Message Schemas

Keyboard Events

All keyboard messages include these fields:
Schema Constants (Host/InputSchema.h:5-22):

Example: Keydown Event

Client code (Client/html-server/index.html:1527):

Example: Keyup Event

Client code (Client/html-server/index.html:1536):

Mouse Events

All mouse messages include these fields:
Schema Constants (Host/InputSchema.h:11-21):

Example: Mouse Move

Client code with throttling (Client/html-server/index.html:1031-1046):

Example: Mouse Button Events

Client code (Client/html-server/index.html:1545-1578):

Host-Side Processing

Keyboard Processing

The host receives keyboard events through a blocking queue for deterministic processing (Host/KeyInputHandler.cpp:518-686):

Mouse Processing

The mouse handler processes events with priority elevation for low latency (Host/MouseInputHandler.cpp:440-716):

Input Injection

Windows SendInput API

Both keyboard and mouse events are injected using the Windows SendInput API for system-level control (Host/KeyInputHandler.cpp:407-516, Host/MouseInputHandler.cpp:204-438):

Performance Optimizations

Mouse Move Coalescing

The host coalesces rapid mouse move events to reduce processing overhead (Host/MouseInputHandler.cpp:27-75):

Thread Priority Elevation

The mouse processing thread runs at elevated priority to minimize input latency (Host/MouseInputHandler.cpp:443-449):

State Management

Key State Tracking

Both client and host maintain key state to prevent duplicate events: Client (Client/html-server/index.html:715-717):
Host (Host/KeyInputHandler.cpp:44-48):

Cleanup on Disconnect

When the connection closes, all held keys/buttons are automatically released (Host/KeyInputHandler.cpp:689-714, Host/MouseInputHandler.cpp:695-716):

Best Practices

Client-Side

  1. Always check channel state before sending:
  2. Throttle mouse moves to reasonable rate (8ms = 125Hz):
  3. Prevent default events to avoid browser interference:
  4. Track state locally to filter duplicates:

Host-Side

  1. Use blocking queues for deterministic event ordering
  2. Validate all input before injection
  3. Clamp coordinates to screen bounds
  4. Release all input on cleanup
  5. Use scancode injection for layout independence
  6. Elevate thread priority for time-sensitive input