Adapters

crossws allows integrating your WebSocket hooks with different runtimes and platforms using built-in adapters. Each runtime has a specific method of integrating WebSocket. Once integrated, will work consistently even if you change the runtime.

See Adapters section to learn more about all available built-in adapters.

Shared options

Every adapter accepts these options in addition to its runtime-specific ones.

idleTimeout

Close a connection that has stayed idle — no incoming messages and no pong replies — for roughly this many seconds. This reclaims peers whose transport died silently ("half-open" sockets: laptop sleep, NAT/mobile idle timeout, power loss, a cut cable) without the TCP stack ever delivering a FIN/RST, which would otherwise leak forever (the peer, and anything it owns such as a proxied upstream connection).

It maps to each runtime's liveness mechanism behind one consistent knob:

  • Node — the ws library has no built-in liveness, so crossws pings each peer on this interval and terminates any that miss the pong.
  • Bun / Deno / uWebSockets / Bunny — mapped to the runtime's native WebSocket idle timeout, which also auto-sends keepalive pings.

Terminated peers surface through the normal close hook (Node reports code 1006), so close/error teardown runs unchanged.

Defaults to 30 (seconds) on every runtime. 30s stays under the common ~60s reverse-proxy / load-balancer idle timeout (so idle-but-alive connections aren't dropped) while reclaiming dead sockets promptly; pings are a few bytes and standards clients auto-pong, so a live connection is never disconnected. Set to 0 to disable.