The best way to control Claude Code, Codex and more from any computer or phone

main
ts 37 lines 1.1 KB
Raw
1 /**
2 * Re-exports the `ws` package and provides a WebSocket client layer backed by
3 * it. `NodeSocket` clients use Node's global `WebSocket` and do not load `ws`.
4 *
5 * @stability unstable
6 * @since 4.1.0
7 */
8 import { WebSocket } from "@effect/platform-node-shared/NodeWS"
9 import * as Layer from "effect/Layer"
10 import * as Socket from "effect/socket/Socket"
11
12 /**
13 * @since 4.1.0
14 */
15 export * from "@effect/platform-node-shared/NodeWS"
16
17 /**
18 * Provides a `Socket.WebSocketConstructor` backed by the `ws` package.
19 *
20 * **Details**
21 *
22 * Supports handshake headers alongside subprotocols, and pauses reads once
23 * buffered frames reach the `Socket.fromWebSocket` `highWaterMark` (64 KiB by
24 * default).
25 *
26 * @stability unstable
27 * @category layers
28 * @since 4.1.0
29 */
30 export const layerWebSocketConstructor: Layer.Layer<
31 Socket.WebSocketConstructor
32 > = Layer.succeed(Socket.WebSocketConstructor)((url, options) => {
33 if (options === undefined || typeof options === "string" || Array.isArray(options)) {
34 return new WebSocket(url, options)
35 }
36 return new WebSocket(url, options.protocols, { headers: options.headers })
37 })