NodeSocket unstable
Node.js socket constructors and layers for Effect sockets.
This module re-exports the shared Node socket support for TCP connections,
Unix domain socket connections, and Node Duplex streams. It also provides
WebSocket client layers backed by Node's global WebSocket.
Layers
layerWebSocket
unstable Since v4.0.0 Source
Creates a Socket.Socket layer for a WebSocket URL using the Node WebSocket
constructor layer, honoring protocol, handshake-header, open-timeout, and
high-water-mark options.
Signature
declare const layerWebSocket: (url: string | Effect.Effect<string>, options?: { readonly headers?: Readonly<Record<string, string>>; readonly highWaterMark?: number; readonly openTimeout?: Duration.Input; readonly protocols?: string | Array<string>;}) => Layer.Layer<Socket.Socket, never, never>layerWebSocketConstructor
unstable Since v4.0.0 Source
Provides a Socket.WebSocketConstructor backed by Node's global
WebSocket.
Details
Handshake headers and subprotocols in client options objects are passed to
the constructor as Node's WebSocketInit.
Gotchas
Use NodeWS.layerWebSocketConstructor if any of these matter:
- Reads cannot be paused, so incoming frames are buffered without limit, or
fail the socket with a
SocketReadErroronce a configuredhighWaterMarkis exceeded. - A custom
Hostheader is ignored. - Outgoing messages are not compressed.
Signature
declare const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor>