NodeSocketServer.ts
NodeSocketServer.ts overview
Section titled “NodeSocketServer.ts overview”Node socket server adapters for Effect’s unstable socket server API.
This module turns node:net TCP or Unix-domain servers and ws WebSocket
servers into scoped SocketServer.SocketServer services. Use the TCP
constructors when handlers should receive a Socket.Socket backed by a Node
net.Socket; use the WebSocket constructors when handlers should receive a
Socket.Socket backed by ws and have access to the per-connection
WebSocket and IncomingMessage services.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Creates a scoped TCP SocketServer from a Node net.Server, starts
listening with the supplied options, queues pending connections until run
is called, and closes the server when the scope ends.
Signature
declare const make: ( options: Net.ServerOpts & Net.ListenOptions) => Effect.Effect< { readonly address: SocketServer.Address readonly run: <R, E, _>( handler: (socket: Socket.Socket) => Effect.Effect<_, E, R> ) => Effect.Effect<never, SocketServer.SocketServerError, R> }, SocketServer.SocketServerError, Scope.Scope>Since v4.0.0
makeWebSocket
Section titled “makeWebSocket”Creates a scoped WebSocket SocketServer backed by the ws package,
providing the WebSocket and its Node IncomingMessage to connection
handlers and closing the server when the scope ends.
Signature
declare const makeWebSocket: ( options: NodeWS.ServerOptions<typeof NodeWS.WebSocket, typeof Http.IncomingMessage>) => Effect.Effect<SocketServer.SocketServer["Service"], SocketServer.SocketServerError, Scope.Scope>Since v4.0.0
layers
Section titled “layers”Provides a TCP SocketServer by creating and managing a scoped Node
net.Server with the supplied server and listen options.
Signature
declare const layer: ( options: Net.ServerOpts & Net.ListenOptions) => Layer.Layer<SocketServer.SocketServer, SocketServer.SocketServerError>Since v4.0.0
layerWebSocket
Section titled “layerWebSocket”Provides a WebSocket SocketServer backed by the ws package and managed
with the supplied server options.
Signature
declare const layerWebSocket: ( options: NodeSocket.NodeWS.ServerOptions<typeof NodeSocket.NodeWS.WebSocket, typeof Http.IncomingMessage>) => Layer.Layer<SocketServer.SocketServer, SocketServer.SocketServerError>Since v4.0.0
services
Section titled “services”IncomingMessage (class)
Section titled “IncomingMessage (class)”Service tag for the Node IncomingMessage associated with the current
WebSocket server connection.
Signature
declare class IncomingMessageSince v4.0.0