API reference / @evolu/common / WebSocket / createWebSocket

Variable: createWebSocket

const createWebSocket: CreateWebSocket;

Defined in: packages/common/src/WebSocket.ts:144

Create a new WebSocket.

The default behavior is that WebSocket tries to reconnect repeatedly in case the application is offline, because online events (both web and native) are not reliable. Once it connects and the connection is closed, it tries to reconnect again. Retrying the connection can be controlled using the retryOptions retryable predicate.

How Binary Messages Work in WebSockets

The Server Chooses the Message Type:

  • Text (0x1) → Sent as UTF-8 encoded text (always received as a string in the browser).
  • Binary (0x2) → Sent as raw binary data (received as a Blob or ArrayBuffer, depending on binaryType).

The Client's binaryType Controls How Binary Data is Processed:

  • If the server sends a text frame (0x1), the browser always delivers event.data as a string, regardless of binaryType.

  • If the server sends a binary frame (0x2), the browser delivers event.data as:

    • A Blob (default: "blob")
    • An ArrayBuffer ("arraybuffer")

Example

TODO:

Was this page helpful?