API reference › @evolu/common › WebSocket

WebSocket with auto-reconnect.

Core

NameDescription
CreateWebSocketDepDependency wrapper for CreateWebSocket.
WebSocketWebSocket with auto-reconnect.
WebSocketCloseEventWhat a WebSocket reports when a connection closes.
WebSocketOptionsOptions for creating WebSocket.
CreateWebSocketTask that creates a WebSocket.
WebSocketReadyStateWebSocket connection states.
createWebSocketCreate a new WebSocket.
webSocketReconnectScheduleDefault WebSocket reconnect schedule.

Errors

NameDescription
WebSocketConnectErrorAn error that occurs when a connection cannot be established due to a network error. Fires before onclose.
WebSocketConnectionCloseErrorAn error that occurs when the connection is closed by the server.
WebSocketConnectionErrorAn error that occurs when an established connection encounters an issue (e.g., failure to send data). Fires before onclose.
WebSocketCreateErrorAn error that occurs when the platform's WebSocket constructor throws, for example for a URL it rejects, a ws: URL on an https: page, or a Content Security Policy that blocks the URL. These fail the same way on every attempt, so the WebSocket stops connecting. The thrown value is not always an Error.
WebSocketReconnectErrorThe error WebSocket.reconnect settles the current connection with.
WebSocketSendErrorAn error that occurs when trying to send data but WebSocket is not available or is in the CONNECTING state.
WebSocketErrorAny error reported by a WebSocket, including exhausted reconnect retries.
WebSocketRetryErrorErrors that trigger a reconnect attempt under webSocketReconnectSchedule.

Testing

NameDescription
TestCreateWebSocketAn inspectable in-memory CreateWebSocket for testing by testCreateWebSocket.
TestSetupWebSocketA native WebSocket prepared for integration tests by testSetupWebSocket.
testCreateWebSocketCreates TestCreateWebSocket.
testSetupWebSocketOpens a native WebSocket and returns TestSetupWebSocket.