relay-transport

Guides changes to WebSocket, SSE, and encrypted relay transport internals in OpenChamber.

9.5k|1.0k|Updated Sep 11, 2025
One-click install
npx skills add https://github.com/openchamber/openchamber --skill relay-transport
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: relay-transport
Source: https://github.com/openchamber/openchamber/tree/main/.agents/skills/relay-transport
Command: npx skills add https://github.com/openchamber/openchamber --skill relay-transport

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

WebSocket and streaming features often work in direct connections but silently break when routed through OpenChamber's end-to-end encrypted relay tunnel, because WebSockets cannot send auth headers and the wire format must stay byte-compatible across two implementations.

Core Features & Use Cases

  • WebSocket Endpoint Rules: Enforces opening sockets via openRuntimeWebSocket, registering paths in both allowlists, minting oc_url_token before connecting, and preserving origin handling.
  • Wire Format Compatibility: Keeps the TypeScript client codec and JavaScript host mirror byte-compatible, including frame types, handshake negotiation, and per-direction encryption counters.
  • Reconnect Discipline: Defines exponential backoff, offline/hidden-state long caps, 4xx handling, and interruptible waits for SSE and WebSocket reconnect loops.
  • Use Case: When adding a new terminal WebSocket endpoint, follow the checklist to update ALLOWED_WS_PATHS, isUrlAuthWebSocketPath, token minting, and relay-mode testing so the feature works on mobile clients through the tunnel.

Quick Start

Ask the agent to add a new WebSocket endpoint to OpenChamber and verify it works over the encrypted relay tunnel.

Frequently Asked Questions about relay-transport

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new WebSocket endpoint that works over an encrypted relay tunnel?

Open the socket via openRuntimeWebSocket instead of new WebSocket, add the path to both ALLOWED_WS_PATHS and isUrlAuthWebSocketPath, mint the oc_url_token before connecting, and test over the actual relay rather than a direct connection.

Why does my WebSocket work on desktop but fail on mobile through the relay?

WebSockets cannot send headers, so they authenticate with a URL-scoped token passed as a query parameter. If the path is missing from the auth gate or the token is not minted, the connection gets a 401 only in relay mode.

How do I keep the TypeScript and JavaScript tunnel codecs compatible?

Frame types defined in protocol.ts must be mirrored in both tunnel-codec.ts and tunnel-codec.js, and any wire-format change must update both implementations while keeping the cross-compat test suite green.

What backoff strategy should SSE and WebSocket reconnect loops use?

Use exponential backoff based on consecutive failures, apply the long cap while offline or hidden, treat permanent 4xx as long-backoff failures, keep 408 and 429 retryable, and make waits interruptible by online and visibility events.

Why does forwarding window.location.origin cause WebSocket 403 errors on iOS?

In the iOS WKWebView with a custom scheme, window.location.origin is null or empty, so forwarding it fails the server's origin check. The relay host already presents a trusted loopback origin, so origin handling must not be modified.