Skip to content

Replace Socket.IO with custom WebSocket client (RemoteSlideSocket) - #2

Merged
InventivetalentDev merged 1 commit into
masterfrom
claude/vigilant-hopper-kca5oz
Sep 10, 2026
Merged

InventivetalentDev merged 1 commit into
masterfrom
claude/vigilant-hopper-kca5oz

Conversation

@InventivetalentDev

Copy link
Copy Markdown
Member

Summary

This PR replaces the Socket.IO dependency with a lightweight custom WebSocket client implementation called RemoteSlideSocket. The new client is designed to work across multiple environments (website, Chrome extension, bookmarklet) without requiring a module system.

Key Changes

  • New file: rs-socket.js - A standalone WebSocket client (~264 lines) that implements:

    • Event-based API matching the previous Socket.IO interface (on, off, emit)
    • Automatic reconnection with exponential backoff
    • Built-in heartbeat mechanism with latency tracking
    • Proper handling of server-side rejections (4xxx WebSocket codes)
    • No external dependencies; ships as a plain script
  • pageController.js updates:

    • Replaced Socket.IO initialization with new RemoteSlideSocket()
    • Removed the manual init event handshake; connection is now opened directly via socket.connect()
    • Added handler for the new rejected event to detect when another page takes over the session
    • Simplified event emissions: changed from socket.emit("_forward", {event: "...", data: {...}}) to direct socket.emit("eventName", {data: {...}})
    • Removed manual latency tracking code; the socket now handles heartbeats internally and reports latency via the latency event

Notable Implementation Details

  • The RemoteSlideSocket exposes a global variable (no module system) to support injection into different execution contexts
  • Heartbeat frames are sent every 2 seconds with a 10-second timeout to detect dead connections
  • Server rejections (4xxx codes) are distinguished from disconnections and are not retried
  • The socket automatically cleans up timers and event handlers on disconnect
  • All handler errors are caught and logged to prevent one failing handler from affecting others

https://claude.ai/code/session_01GfhNPpQzAKM2dMhYp66gLk

remote-sli.de now runs as a Cloudflare Worker and speaks JSON over a plain
WebSocket instead of the Socket.IO protocol. rs-socket.js is the small
client for that: it joins a session by URL (/ws/<session>?as=host), keeps
a heartbeat that the server answers without waking up, reports the round
trip as "latency", and reconnects with backoff unless the server rejected
the connection outright (close codes 4xxx, e.g. session not found).

pageController.js uses it in place of the socket.io bundle. The "init
start" handshake is gone - the role and session are part of the URL, so
the server answers with init success/not_found straight away - and the
"_forward" wrapper is gone as well: application events are emitted under
their own name and the server relays anything it does not handle itself.
The connection is opened at the end of the file, once every handler is
registered.

The extension and the bookmarklet both load rs-socket.js ahead of this
file, so the socket.io copies they carried can go.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GfhNPpQzAKM2dMhYp66gLk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants