anam-ws-proxy
v0.1.1
Published
Anam WebSocket Proxy ====================
Readme
Anam WebSocket Proxy
Small, reusable Cloudflare Workers helper that proxies a client WebSocket to Anam's signalling socket and allows your server code to inject control messages without going through the client.
Features
- Bridges Client <-> Anam signalling WebSockets
- Hooks for server-side control (
onUserMessage,onSessionEnd) - Works in Cloudflare Workers and Durable Objects
Quick Start
- Install as a workspace or local package, then import:
import { WebSocketProxyService } from 'anam-ws-proxy';
- When you accept a client WebSocket in your Worker/DO, create the proxy and connect it using Anam session info:
const proxy = new WebSocketProxyService(onUserMessage, onSessionEnd); await proxy.handleWebSocketConnection(serverSocket, { sessionId, engineHost, engineProtocol, // 'http' | 'https' signallingEndpoint, });
- To send server-initiated control messages to Anam:
proxy.sendMessageToAnam({ actionType: 'talkstream', sessionId, payload: { ... } });
Types
AnamSessionLike:{ sessionId, engineHost, engineProtocol, signallingEndpoint }
Notes
- This library intentionally has no dependency on your app framework (e.g. Hono). It only expects Cloudflare's standard WebSocket APIs.
- If you need to construct the Anam signalling URL differently, fork
connectToAnamor contribute a URL-builder hook.
