Synclets logoSynclets

createWsClientTransport

The createWsClientTransport function wraps a WebSocket in a WsClientTransport implementation.

createWsClientTransport<WebSocketType>(
  webSocket: WebSocketType,
  options?: TransportOptions,
): WsClientTransport<WebSocketType>
TypeDescription
webSocketWebSocketType

The WebSocket instance to wrap (browser WebSocket or ws WebSocket).

options?TransportOptions

Optional TransportOptions for configuring the transport.

returnsWsClientTransport<WebSocketType>

A WsClientTransport instance for WebSocket communication.

This transport enables real-time synchronization over network connections, allowing Synclets to communicate across different machines, processes, or browser tabs. It handles automatic reconnection, packet fragmentation for large payloads, and bidirectional communication.

The client transport can only connect to servers created with createWsBroker (or another Synclet running WsBrokerTransport). It is suitable for browser environments (using the Web API WebSocket) and Node.js (using the 'ws' package).

Since

v0.0.0