| 579 | * @since 4.0.0 |
| 580 | */ |
| 581 | export const makeWebSocket = (url: string | Effect.Effect<string>, options?: { |
| 582 | readonly closeCodeIsError?: ((code: number) => boolean) | undefined |
| 583 | readonly openTimeout?: Duration.Input | undefined |
| 584 | readonly protocols?: string | Array<string> | undefined |
| 585 | }): Effect.Effect<Socket, never, WebSocketConstructor> => |
| 586 | WebSocketConstructor.use((makeWs) => |
| 587 | fromWebSocket( |
| 588 | Effect.acquireRelease( |
| 589 | (typeof url === "string" ? Effect.succeed(url) : url).pipe( |
| 590 | Effect.map((url) => makeWs(url, options?.protocols)) |
| 591 | ), |
| 592 | (ws) => Effect.sync(() => ws.close(1000)) |
| 593 | ), |
| 594 | options |
| 595 | ) |
| 596 | ) |
| 597 | |
| 598 | /** |
| 599 | * Builds a `Socket` from a scoped WebSocket acquisition effect, waiting for the |