Skip to content

Function: webSocket()

webSocket<T>(url, factory): WebSocketStream<T>

Defined in: streams/webSocket.ts:32

Creates a WebSocket stream for bidirectional communication with a server.

Incoming messages from the WebSocket are emitted as stream values. Outgoing messages are sent via the .send() method. Messages sent before the connection is open are queued automatically.

Type Parameters

T

T = any

Type of messages to send and receive.

Parameters

url

string

The WebSocket URL.

factory

WebSocketFactory = ...

Optional WebSocket factory for dependency injection (useful for testing).

Returns

WebSocketStream<T>

A WebSocketStream that can be used to send and receive messages of type T.

Released under the MIT License.