-
-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Problem Statement
Description
Currently, the useRemoteConnection.ts hook only tracks basic connection states (connected or disconnected).
In a LAN-based remote input tool like Rein, even minor network congestion can lead to frustrating input lag. Currently, users have no way of knowing if "laggy" movement is caused by:
- Network Latency: Poor Wi-Fi signal or interference.
- Host Performance: CPU spikes on the desktop computer.
- Connection Drops: Stale WebSocket connections that haven't explicitly closed.
Technical Overview:
- Frontend (
useRemoteConnection.ts):- Implement a timer to send a
{ type: 'ping', timestamp: Date.now() }message every 2-3 seconds. - Calculate the Round-Trip Time (RTT) once the
pongresponse is received.
- Implement a timer to send a
- Backend (
websocket.ts):- Add a listener to respond immediately to
pingmessages with apongmessage containing the original timestamp.
- Add a listener to respond immediately to
- UI Implementation:
- Display the latency (e.g.,
Ping: 12ms) in thetrackpad.tsxorControlBar.tsxcomponent. - Visual cue: Use colors (Green for <50ms, Yellow for 50-150ms, Red for >150ms) to help users diagnose connection quality at a glance.
- Display the latency (e.g.,
Proposed Solution
I propose implementing a simple heartbeat (ping/pong) mechanism to provide real-time latency feedback in the UI.
Alternatives Considered
Native WebSocket Pings: While the WebSocket protocol supports native ping/pong frames, they are not exposed to the browser's JavaScript API. An application-level implementation is the most reliable way to measure latency in this context.
Additional Context
Providing transparency into connection quality will significantly improve the user experience, especially when using Rein in environments with unstable Wi-Fi. It helps developers and users quickly identify whether performance issues are network-related or hardware-related.
Checklist
- I have searched for existing feature requests to avoid duplicates