File tree Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * WebSocket adapter for Node.js environment. Build on top of `npm:ws`.
2
+ * Client WebSocket adapter for Node.js (and Bun). Wrapper over the [`npm:ws`](https://www.npmjs.com/package/ws).
3
+ *
4
+ * @example Use with `Client`
5
+ *
6
+ * ```ts
7
+ * import ws from '@iroha/client-web-socket-node'
8
+ * import { Client, type CreateClientParams } from '@iroha/client'
9
+ *
10
+ * function createClient(params: CreateClientParams) {
11
+ * const client = new Client({
12
+ * ...params,
13
+ *
14
+ * // provide WebSocket adapter here
15
+ * ws,
16
+ * })
17
+ * }
18
+ * ```
19
+ *
20
+ * @example Use with `WebSocketAPI`
3
21
*
4
- * @example
5
22
* ```ts
6
23
* import ws from '@iroha/client-web-socket-node'
7
24
* import { WebSocketAPI } from '@iroha/client'
Original file line number Diff line number Diff line change 3
3
*
4
4
* The primary functionality is exposed via the {@linkcode Client}.
5
5
*
6
+ * ## WebSocket Support
7
+ *
8
+ * Some APIs (e.g. {@linkcode Client#events}, {@linkcode Client#blocks}) require {@link WebSocket} support.
9
+ *
10
+ * WebSocket is not supported uniformly across environments, so adapters are used to provide a consistent interface.
11
+ *
12
+ * In Deno and browsers, no setup is needed - the adapter over the native {@link WebSocket} is used by default.
13
+ * In Node and Bun, you **must** explicitly provide a compatible WebSocket adapter.
14
+ *
15
+ * You can also implement your own by conforming to the {@linkcode [web-socket].IsomorphicWebSocketAdapter} interface.
16
+ *
17
+ * In summary:
18
+ *
19
+ * | Environment | Adapter |
20
+ * | - | - |
21
+ * | Deno, Web (browsers) | Native adapter used by default ({@linkcode [web-socket].nativeWS}) |
22
+ * | Node, Bun | Use [`@iroha/client-web-socket-node`](https://jsr.io/@iroha/client-web-socket-node) |
23
+ * | Custom | Implement {@linkcode [web-socket].IsomorphicWebSocketAdapter} |
24
+ *
25
+ * ### Example: using `@iroha/client-web-socket-node`
26
+ *
27
+ * ```ts
28
+ * import ws from '@iroha/client-web-socket-node'
29
+ * import { Client, type CreateClientParams } from '@iroha/client'
30
+ *
31
+ * function createClient(params: CreateClientParams) {
32
+ * const client = new Client({
33
+ * ...params,
34
+ *
35
+ * // provide WebSocket adapter here
36
+ * ws,
37
+ * })
38
+ * }
39
+ * ```
40
+ *
6
41
* @example Construct a client with a random account
7
42
* ```ts
8
43
* import { Client } from '@iroha/client'
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ async function handleIncomingData(data: any): Promise<IncomingData> {
10
10
throw new Error ( 'Unable to parse incoming data' )
11
11
}
12
12
13
+ /**
14
+ * Implementation of {@linkcode IsomorphicWebSocketAdapter} based on the native {@link WebSocket}.
15
+ */
13
16
const adapter : IsomorphicWebSocketAdapter = {
14
17
initWebSocket : ( params ) => {
15
18
const socket = new WebSocket ( params . url )
You can’t perform that action at this time.
0 commit comments