API reference › @evolu/common › WebSocket › WebSocketUrl

const WebSocketUrl: brand(
  "WebSocketUrl",
  Url,
  (value: string) =>
    isWebSocketUrl(value)
      ? ok()
      : err<WebSocketUrlError>({ type: "WebSocketUrl", value }),
  formatWebSocketUrlError,
);

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

Url that a WebSocket connects to, such as wss://free.evoluhq.com/.

Its scheme is ws: or wss:. It can have a query, such as the ownerId that createOwnerWebSocketTransport adds. It has no fragment, which the WebSocket constructor rejects, and no username or password, which browsers and Node.js send only after the server asks for them, and React Native on Android never.

Each label of its host has 1 to 63 characters and the host at most 253, as DNS allows. Its host, path, and query have only the characters java.net.URI allows there, with every % followed by two hex digits, and its port is not 0. React Native on Android checks the URL with java.net.URI and OkHttp, which throw natively for a longer label, another character, or port 0.

Like Url, WebSocketUrl does not normalize; use WebSocketUrlFromString to convert other spellings, such as user input.

Example

import { assertErr, assertOk, WebSocketUrl } from "@evolu/common";

assertOk(
  WebSocketUrl.fromUnknown("wss://free.evoluhq.com/"),
  "wss://free.evoluhq.com/",
);

assertErr(WebSocketUrl.fromUnknown("wss://free.evoluhq.com/#sync"), {
  type: "WebSocketUrl",
  value: "wss://free.evoluhq.com/#sync",
});