BrowserSocket
Browser WebSocket layers for Effect sockets.
layerWebSocket creates a Socket.Socket connected to a WebSocket URL using the browser WebSocket constructor. layerWebSocketConstructor provides only the browser-backed constructor service for lower-level socket code.
Layers
layerWebSocket
Added in v4.0.0
Source
Signature
declare function layerWebSocket(
url: string,
options?: {
readonly closeCodeIsError?: (code: number) => boolean;
},
): Layer<Socket>;layerWebSocketConstructor
Added in v4.0.0
Source
Layer that provides a WebSocketConstructor service backed by globalThis.WebSocket.
Signature
declare const layerWebSocketConstructor: Layer.Layer<Socket.WebSocketConstructor>;
Creates a
Socketlayer connected to the given URL using the browserWebSocketconstructor.When to use
Use when you need browser code to satisfy the platform socket service from a URL without wiring the browser constructor service separately.
Details
Delegates socket construction to
Socket.makeWebSocketand provides the browser-backedWebSocketConstructorservice.Gotchas
Browser WebSocket rules still control URL schemes, mixed-content blocking, cookies, authentication, origin checks, subprotocols, and extensions. Close events are errors unless
closeCodeIsErrorclassifies the close code as clean.See
layerWebSocketConstructorfor providing only the browser constructor service