@noodleseed/one 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/author-loop.d.ts.map +1 -1
- package/dist/commands/author-loop.js +2 -2
- package/dist/commands/author-loop.js.map +1 -1
- package/dist/commands/catalog-dispatch.d.ts.map +1 -1
- package/dist/commands/catalog-dispatch.js +21 -2
- package/dist/commands/catalog-dispatch.js.map +1 -1
- package/dist/commands/deploy-ops.d.ts.map +1 -1
- package/dist/commands/deploy-ops.js +28 -11
- package/dist/commands/deploy-ops.js.map +1 -1
- package/dist/first-run.d.ts +11 -0
- package/dist/first-run.d.ts.map +1 -1
- package/dist/first-run.js +19 -4
- package/dist/first-run.js.map +1 -1
- package/dist/project-scaffold-templates.d.ts +11 -0
- package/dist/project-scaffold-templates.d.ts.map +1 -0
- package/dist/project-scaffold-templates.js +359 -0
- package/dist/project-scaffold-templates.js.map +1 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +1 -323
- package/dist/project.js.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/validate.d.ts +12 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +11 -0
- package/dist/validate.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.d.ts.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js +6 -9
- package/node_modules/@noodle-borg/agent-kit/dist/skill-content.js.map +1 -1
- package/node_modules/@noodle-borg/agent-kit/package.json +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.d.ts +3 -3
- package/node_modules/@noodle-borg/authoring/dist/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.js +1 -1
- package/node_modules/@noodle-borg/authoring/dist/index.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts +302 -7
- package/node_modules/@noodle-borg/authoring/dist/react/components.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/components.js +39 -7
- package/node_modules/@noodle-borg/authoring/dist/react/components.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts +4 -2
- package/node_modules/@noodle-borg/authoring/dist/react/index.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.js +2 -1
- package/node_modules/@noodle-borg/authoring/dist/react/index.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts +2618 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.d.ts.map +1 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js +110 -0
- package/node_modules/@noodle-borg/authoring/dist/react/semantic-components.js.map +1 -0
- package/node_modules/@noodle-borg/authoring/dist/react.d.ts +2 -2
- package/node_modules/@noodle-borg/authoring/dist/react.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react.js +1 -1
- package/node_modules/@noodle-borg/authoring/dist/react.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.d.ts +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.js +14 -1
- package/node_modules/@noodle-borg/authoring/dist/recording.js.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/server.d.ts +25 -2
- package/node_modules/@noodle-borg/authoring/dist/server.d.ts.map +1 -1
- package/node_modules/@noodle-borg/authoring/dist/server.js +7 -3
- package/node_modules/@noodle-borg/authoring/dist/server.js.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/compile.d.ts.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/compile.js +20 -8
- package/node_modules/@noodle-borg/compiler/dist/compile.js.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts +2 -0
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.d.ts.map +1 -1
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js +6 -0
- package/node_modules/@noodle-borg/compiler/dist/manifest/schema.js.map +1 -1
- package/node_modules/@noodle-borg/connector-http/package.json +1 -1
- package/node_modules/@noodle-borg/protocol/dist/mapping.d.ts.map +1 -1
- package/node_modules/@noodle-borg/protocol/dist/mapping.js +8 -0
- package/node_modules/@noodle-borg/protocol/dist/mapping.js.map +1 -1
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +15 -21
- package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +15 -21
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +8 -2
- package/node_modules/hono/dist/cjs/helper/css/common.js +3 -1
- package/node_modules/hono/dist/cjs/helper/css/index.js +9 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +8 -14
- package/node_modules/hono/dist/cjs/jsx/components.js +41 -21
- package/node_modules/hono/dist/cjs/jsx/context.js +131 -5
- package/node_modules/hono/dist/cjs/jsx/streaming.js +9 -7
- package/node_modules/hono/dist/cjs/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +2 -2
- package/node_modules/hono/dist/cjs/utils/body.js +12 -4
- package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
- package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
- package/node_modules/hono/dist/helper/css/common.js +3 -1
- package/node_modules/hono/dist/helper/css/index.js +9 -1
- package/node_modules/hono/dist/jsx/base.js +15 -15
- package/node_modules/hono/dist/jsx/components.js +42 -22
- package/node_modules/hono/dist/jsx/context.js +129 -5
- package/node_modules/hono/dist/jsx/streaming.js +10 -8
- package/node_modules/hono/dist/middleware/cors/index.js +2 -5
- package/node_modules/hono/dist/middleware/serve-static/index.js +2 -2
- package/node_modules/hono/dist/types/adapter/aws-lambda/handler.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +1 -3
- package/node_modules/hono/dist/types/jsx/context.d.ts +39 -0
- package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
- package/node_modules/hono/dist/utils/body.js +12 -4
- package/node_modules/hono/dist/utils/buffer.js +2 -1
- package/node_modules/hono/dist/validator/validator.js +3 -3
- package/node_modules/hono/package.json +9 -10
- package/node_modules/tailwindcss/dist/chunk-HMCCH6MG.mjs +1 -0
- package/node_modules/tailwindcss/dist/default-theme.mjs +1 -1
- package/node_modules/tailwindcss/dist/lib.js +13 -13
- package/node_modules/tailwindcss/dist/lib.mjs +18 -18
- package/node_modules/tailwindcss/package.json +2 -2
- package/node_modules/undici/README.md +3 -2
- package/node_modules/undici/docs/docs/api/Agent.md +248 -44
- package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
- package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
- package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
- package/node_modules/undici/docs/docs/api/Client.md +365 -178
- package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
- package/node_modules/undici/docs/docs/api/Connector.md +118 -36
- package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
- package/node_modules/undici/docs/docs/api/Cookies.md +125 -47
- package/node_modules/undici/docs/docs/api/Debug.md +34 -18
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
- package/node_modules/undici/docs/docs/api/Dispatcher.md +479 -1093
- package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
- package/node_modules/undici/docs/docs/api/Errors.md +503 -40
- package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
- package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
- package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
- package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
- package/node_modules/undici/docs/docs/api/Interceptors.md +355 -0
- package/node_modules/undici/docs/docs/api/MockAgent.md +314 -322
- package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
- package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
- package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
- package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
- package/node_modules/undici/docs/docs/api/MockPool.md +299 -263
- package/node_modules/undici/docs/docs/api/Pool.md +235 -43
- package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
- package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
- package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
- package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
- package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
- package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
- package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -186
- package/node_modules/undici/docs/docs/api/Util.md +68 -11
- package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
- package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
- package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
- package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
- package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
- package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
- package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
- package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
- package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
- package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
- package/node_modules/undici/docs/docs/index.md +779 -0
- package/node_modules/undici/docs/docs/site.json +125 -0
- package/node_modules/undici/docs/docs/type-map.json +79 -0
- package/node_modules/undici/lib/api/api-request.js +7 -1
- package/node_modules/undici/lib/api/readable.js +47 -2
- package/node_modules/undici/lib/core/errors.js +20 -0
- package/node_modules/undici/lib/core/request.js +1 -1
- package/node_modules/undici/lib/core/util.js +24 -1
- package/node_modules/undici/lib/dispatcher/client-h1.js +92 -1
- package/node_modules/undici/lib/dispatcher/client-h2.js +322 -118
- package/node_modules/undici/lib/dispatcher/client.js +6 -2
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +1 -0
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +42 -7
- package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +4 -2
- package/node_modules/undici/lib/handler/redirect-handler.js +1 -0
- package/node_modules/undici/lib/handler/retry-handler.js +57 -19
- package/node_modules/undici/lib/util/cache.js +8 -2
- package/node_modules/undici/lib/web/cookies/parse.js +20 -27
- package/node_modules/undici/lib/web/cookies/util.js +1 -1
- package/node_modules/undici/lib/web/eventsource/eventsource.js +7 -18
- package/node_modules/undici/lib/web/eventsource/util.js +32 -1
- package/node_modules/undici/lib/web/fetch/body.js +43 -0
- package/node_modules/undici/lib/web/fetch/constants.js +1 -1
- package/node_modules/undici/lib/web/fetch/index.js +11 -2
- package/node_modules/undici/lib/web/fetch/request.js +1 -0
- package/node_modules/undici/lib/web/fetch/util.js +4 -1
- package/node_modules/undici/lib/web/websocket/receiver.js +20 -3
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
- package/node_modules/undici/lib/web/websocket/websocket.js +3 -1
- package/node_modules/undici/package.json +1 -1
- package/node_modules/undici/types/client.d.ts +6 -1
- package/node_modules/undici/types/cookies.d.ts +1 -1
- package/node_modules/undici/types/errors.d.ts +10 -0
- package/node_modules/undici/types/fetch.d.ts +1 -0
- package/node_modules/undici/types/handlers.d.ts +2 -0
- package/node_modules/undici/types/proxy-agent.d.ts +7 -0
- package/package.json +4 -4
- package/react/styles.css +510 -5
- package/react/styles.source.css +850 -0
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- package/node_modules/tailwindcss/dist/chunk-XVOTX5KS.mjs +0 -1
|
@@ -1,141 +1,536 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WebSocket
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!--introduced_in=v5.15.0-->
|
|
4
|
+
<!--type=module-->
|
|
5
|
+
<!-- source_link=lib/web/websocket/websocket.js -->
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
> Stability: 2 - Stable
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
The `WebSocket` API provides a way to manage a WebSocket connection to a
|
|
10
|
+
server, allowing bidirectional communication. It follows the
|
|
11
|
+
[WHATWG WebSocket specification][] and [RFC 6455][], and is intended to be
|
|
12
|
+
interchangeable with the global `WebSocket` available in browsers.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
```mjs
|
|
15
|
+
import { WebSocket } from 'undici'
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
* **protocol** `string | string[] | WebSocketInit` (optional) - Subprotocol(s) to request the server use, or a [`Dispatcher`](/docs/docs/api/Dispatcher.md).
|
|
17
|
+
const ws = new WebSocket('wss://echo.websocket.events')
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
ws.addEventListener('open', () => {
|
|
20
|
+
ws.send('Hello, world!')
|
|
21
|
+
})
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
ws.addEventListener('message', (event) => {
|
|
24
|
+
console.log('received:', event.data)
|
|
25
|
+
})
|
|
26
|
+
```
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
In addition to the standard `WebSocket` interface, this module exports the
|
|
29
|
+
streams-based [`WebSocketStream`][] and [`WebSocketError`][] APIs, as well as a
|
|
30
|
+
[`ping()`][] helper for sending ping frames.
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
## Class: `WebSocket`
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
<!-- YAML
|
|
35
|
+
added: v5.15.0
|
|
36
|
+
-->
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
import { WebSocket, ProxyAgent } from 'undici'
|
|
38
|
+
* Extends: {EventTarget}
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
The `WebSocket` object represents a single WebSocket connection. Constructing a
|
|
41
|
+
`WebSocket` immediately begins the opening handshake; the connection cannot be
|
|
42
|
+
reused once it has been closed.
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
### `new WebSocket(url[, protocols])`
|
|
45
|
+
|
|
46
|
+
<!-- YAML
|
|
47
|
+
added: v5.15.0
|
|
48
|
+
-->
|
|
49
|
+
|
|
50
|
+
* `url` {URL|string} The URL of the server to connect to. Must use the `ws:`
|
|
51
|
+
or `wss:` scheme.
|
|
52
|
+
* `protocols` {string|string[]|WebSocketInit} A single subprotocol, a list of
|
|
53
|
+
subprotocols to negotiate with the server, or a `WebSocketInit` object.
|
|
54
|
+
**Default:** `[]`.
|
|
55
|
+
* `protocols` {string|string[]} Subprotocol(s) to request the server use.
|
|
56
|
+
**Default:** `[]`.
|
|
57
|
+
* `dispatcher` {Dispatcher} The dispatcher used to open the connection.
|
|
58
|
+
**Default:** the global dispatcher.
|
|
59
|
+
* `headers` {HeadersInit|null} Additional headers to send with the handshake
|
|
60
|
+
request. (optional)
|
|
36
61
|
|
|
37
|
-
|
|
62
|
+
Creates a new `WebSocket` and begins connecting to `url`. The second argument
|
|
63
|
+
may be a string or array of subprotocols, or a `WebSocketInit` object. The
|
|
64
|
+
object form is an undici extension and is not available in browsers; it allows a
|
|
65
|
+
custom `dispatcher` and additional `headers` to be supplied.
|
|
38
66
|
|
|
39
|
-
|
|
67
|
+
If a value in `protocols` is repeated or is not a valid subprotocol name, the
|
|
68
|
+
constructor throws a `SyntaxError` `DOMException`.
|
|
69
|
+
|
|
70
|
+
```mjs
|
|
40
71
|
import { WebSocket } from 'undici'
|
|
41
72
|
|
|
42
73
|
const ws = new WebSocket('wss://echo.websocket.events', ['echo', 'chat'])
|
|
43
74
|
```
|
|
44
75
|
|
|
45
|
-
|
|
76
|
+
To route the connection through a custom dispatcher, such as a
|
|
77
|
+
[`ProxyAgent`][], pass a `WebSocketInit` object:
|
|
46
78
|
|
|
47
|
-
|
|
79
|
+
```mjs
|
|
80
|
+
import { WebSocket, ProxyAgent } from 'undici'
|
|
48
81
|
|
|
49
|
-
|
|
50
|
-
> this will happen by enabling HTTP/2 connections as the default behavior of Undici's Agent as well the global dispatcher.
|
|
51
|
-
> Stay tuned to the changelog for more information.
|
|
82
|
+
const dispatcher = new ProxyAgent('http://localhost:8080')
|
|
52
83
|
|
|
53
|
-
|
|
84
|
+
const ws = new WebSocket('wss://echo.websocket.events', {
|
|
85
|
+
dispatcher,
|
|
86
|
+
protocols: ['echo', 'chat']
|
|
87
|
+
})
|
|
88
|
+
```
|
|
54
89
|
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
WebSocket over HTTP/2 is experimental and may change in the future. It can be
|
|
91
|
+
enabled by passing a dispatcher configured with `allowH2`:
|
|
57
92
|
|
|
58
|
-
|
|
93
|
+
```mjs
|
|
94
|
+
import { WebSocket, Agent } from 'undici'
|
|
95
|
+
|
|
96
|
+
const dispatcher = new Agent({ allowH2: true })
|
|
59
97
|
|
|
60
98
|
const ws = new WebSocket('wss://echo.websocket.events', {
|
|
61
|
-
dispatcher
|
|
99
|
+
dispatcher,
|
|
62
100
|
protocols: ['echo', 'chat']
|
|
63
101
|
})
|
|
64
102
|
```
|
|
65
103
|
|
|
66
|
-
|
|
104
|
+
### `websocket.close([code[, reason]])`
|
|
105
|
+
|
|
106
|
+
<!-- YAML
|
|
107
|
+
added: v5.15.0
|
|
108
|
+
-->
|
|
67
109
|
|
|
68
|
-
|
|
110
|
+
* `code` {number} The status code explaining why the connection is being
|
|
111
|
+
closed. **Default:** `null`.
|
|
112
|
+
* `reason` {string} A human-readable string explaining why the connection is
|
|
113
|
+
being closed. **Default:** `''`.
|
|
69
114
|
|
|
70
|
-
|
|
115
|
+
Starts the closing handshake. The `code` is clamped to an unsigned 16-bit
|
|
116
|
+
integer; when omitted, no status code is sent. The `reason` is encoded as
|
|
117
|
+
UTF-8 and must not exceed 123 bytes.
|
|
71
118
|
|
|
72
|
-
|
|
119
|
+
```mjs
|
|
120
|
+
ws.close(1000, 'Done')
|
|
121
|
+
```
|
|
73
122
|
|
|
74
|
-
|
|
123
|
+
### `websocket.send(data)`
|
|
75
124
|
|
|
76
|
-
|
|
77
|
-
|
|
125
|
+
<!-- YAML
|
|
126
|
+
added: v5.15.0
|
|
127
|
+
-->
|
|
78
128
|
|
|
79
|
-
|
|
129
|
+
* `data` {string|ArrayBuffer|TypedArray|DataView|Blob} The data to enqueue for
|
|
130
|
+
transmission.
|
|
80
131
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
132
|
+
Enqueues `data` to be transmitted to the server. String data is sent as a text
|
|
133
|
+
frame; `ArrayBuffer`, any `TypedArray`, `DataView`, and `Blob` values are sent
|
|
134
|
+
as binary frames. The number of bytes queued is added to
|
|
135
|
+
[`websocket.bufferedAmount`][].
|
|
84
136
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
137
|
+
If [`websocket.readyState`][] is `CONNECTING`, an `InvalidStateError`
|
|
138
|
+
`DOMException` is thrown. If the connection is closing or already closed, the
|
|
139
|
+
call is silently ignored.
|
|
88
140
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
141
|
+
```mjs
|
|
142
|
+
ws.send('a text message')
|
|
143
|
+
ws.send(new Uint8Array([1, 2, 3]))
|
|
144
|
+
```
|
|
92
145
|
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}
|
|
146
|
+
### `websocket.readyState`
|
|
96
147
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
writer.write('Hello, world!')
|
|
101
|
-
writer.releaseLock()
|
|
102
|
-
}
|
|
148
|
+
<!-- YAML
|
|
149
|
+
added: v5.15.0
|
|
150
|
+
-->
|
|
103
151
|
|
|
104
|
-
|
|
152
|
+
* Type: {number}
|
|
105
153
|
|
|
106
|
-
|
|
154
|
+
The current state of the connection. One of the numeric constants
|
|
155
|
+
`WebSocket.CONNECTING` (`0`), `WebSocket.OPEN` (`1`),
|
|
156
|
+
`WebSocket.CLOSING` (`2`), or `WebSocket.CLOSED` (`3`). This property is
|
|
157
|
+
read-only.
|
|
107
158
|
|
|
108
|
-
|
|
159
|
+
### `websocket.bufferedAmount`
|
|
160
|
+
|
|
161
|
+
<!-- YAML
|
|
162
|
+
added: v5.15.0
|
|
163
|
+
-->
|
|
164
|
+
|
|
165
|
+
* Type: {number}
|
|
166
|
+
|
|
167
|
+
The number of bytes of data that have been queued using
|
|
168
|
+
[`websocket.send()`][] but not yet transmitted to the network. This value
|
|
169
|
+
resets to `0` once all queued data is sent. This property is read-only.
|
|
170
|
+
|
|
171
|
+
### `websocket.url`
|
|
172
|
+
|
|
173
|
+
<!-- YAML
|
|
174
|
+
added: v5.15.0
|
|
175
|
+
-->
|
|
176
|
+
|
|
177
|
+
* Type: {string}
|
|
178
|
+
|
|
179
|
+
The absolute URL of the WebSocket as resolved during construction. This
|
|
180
|
+
property is read-only.
|
|
181
|
+
|
|
182
|
+
### `websocket.extensions`
|
|
183
|
+
|
|
184
|
+
<!-- YAML
|
|
185
|
+
added: v5.15.0
|
|
186
|
+
-->
|
|
187
|
+
|
|
188
|
+
* Type: {string}
|
|
189
|
+
|
|
190
|
+
The extensions negotiated by the server, taken from the
|
|
191
|
+
`Sec-WebSocket-Extensions` response header. Empty until the connection is
|
|
192
|
+
established. This property is read-only.
|
|
193
|
+
|
|
194
|
+
### `websocket.protocol`
|
|
195
|
+
|
|
196
|
+
<!-- YAML
|
|
197
|
+
added: v5.15.0
|
|
198
|
+
-->
|
|
199
|
+
|
|
200
|
+
* Type: {string}
|
|
201
|
+
|
|
202
|
+
The subprotocol selected by the server, taken from the
|
|
203
|
+
`Sec-WebSocket-Protocol` response header. Empty until the connection is
|
|
204
|
+
established and only set when a subprotocol was negotiated. This property is
|
|
205
|
+
read-only.
|
|
206
|
+
|
|
207
|
+
### `websocket.binaryType`
|
|
208
|
+
|
|
209
|
+
<!-- YAML
|
|
210
|
+
added: v5.15.0
|
|
211
|
+
-->
|
|
212
|
+
|
|
213
|
+
* Type: {string} **Default:** `'blob'`.
|
|
214
|
+
|
|
215
|
+
Controls the type used to represent binary data delivered by the
|
|
216
|
+
[`'message'`][] event. Must be either `'blob'` (binary frames are exposed as a
|
|
217
|
+
`Blob`) or `'arraybuffer'` (binary frames are exposed as an `ArrayBuffer`).
|
|
218
|
+
Assigning any other value resets it to `'blob'`.
|
|
219
|
+
|
|
220
|
+
### `websocket.onopen`
|
|
221
|
+
|
|
222
|
+
<!-- YAML
|
|
223
|
+
added: v5.15.0
|
|
224
|
+
-->
|
|
225
|
+
|
|
226
|
+
* Type: {Function|null} **Default:** `null`.
|
|
227
|
+
|
|
228
|
+
An event handler for the [`'open'`][] event. Setting this property replaces any
|
|
229
|
+
previously registered `onopen` handler.
|
|
230
|
+
|
|
231
|
+
### `websocket.onerror`
|
|
232
|
+
|
|
233
|
+
<!-- YAML
|
|
234
|
+
added: v5.15.0
|
|
235
|
+
-->
|
|
236
|
+
|
|
237
|
+
* Type: {Function|null} **Default:** `null`.
|
|
238
|
+
|
|
239
|
+
An event handler for the [`'error'`][] event. Setting this property replaces any
|
|
240
|
+
previously registered `onerror` handler.
|
|
241
|
+
|
|
242
|
+
### `websocket.onclose`
|
|
243
|
+
|
|
244
|
+
<!-- YAML
|
|
245
|
+
added: v5.15.0
|
|
246
|
+
-->
|
|
247
|
+
|
|
248
|
+
* Type: {Function|null} **Default:** `null`.
|
|
249
|
+
|
|
250
|
+
An event handler for the [`'close'`][] event. Setting this property replaces any
|
|
251
|
+
previously registered `onclose` handler.
|
|
252
|
+
|
|
253
|
+
### `websocket.onmessage`
|
|
254
|
+
|
|
255
|
+
<!-- YAML
|
|
256
|
+
added: v5.15.0
|
|
257
|
+
-->
|
|
258
|
+
|
|
259
|
+
* Type: {Function|null} **Default:** `null`.
|
|
260
|
+
|
|
261
|
+
An event handler for the [`'message'`][] event. Setting this property replaces
|
|
262
|
+
any previously registered `onmessage` handler.
|
|
263
|
+
|
|
264
|
+
### Event: `'open'`
|
|
265
|
+
|
|
266
|
+
<!-- YAML
|
|
267
|
+
added: v5.21.0
|
|
268
|
+
-->
|
|
269
|
+
|
|
270
|
+
Emitted when the WebSocket connection is established. After this event,
|
|
271
|
+
[`websocket.readyState`][] is `OPEN` and data may be sent with
|
|
272
|
+
[`websocket.send()`][]. The listener receives an `Event`.
|
|
273
|
+
|
|
274
|
+
### Event: `'message'`
|
|
275
|
+
|
|
276
|
+
<!-- YAML
|
|
277
|
+
added: v7.0.0
|
|
278
|
+
-->
|
|
279
|
+
|
|
280
|
+
Emitted when a message is received from the server. The listener receives a
|
|
281
|
+
`MessageEvent` whose `data` property is a `string` for text frames, and either a
|
|
282
|
+
`Blob` or an `ArrayBuffer` for binary frames depending on
|
|
283
|
+
[`websocket.binaryType`][]. The event's `origin` is the origin of
|
|
284
|
+
[`websocket.url`][].
|
|
109
285
|
|
|
110
|
-
|
|
111
|
-
Arguments:
|
|
286
|
+
### Event: `'error'`
|
|
112
287
|
|
|
113
|
-
|
|
114
|
-
|
|
288
|
+
<!-- YAML
|
|
289
|
+
added: v7.0.0
|
|
290
|
+
-->
|
|
115
291
|
|
|
116
|
-
|
|
292
|
+
Emitted when the connection is terminated abnormally, for example when no close
|
|
293
|
+
frame was received before the underlying transport was lost. The listener
|
|
294
|
+
receives an `ErrorEvent`.
|
|
117
295
|
|
|
118
|
-
###
|
|
296
|
+
### Event: `'close'`
|
|
119
297
|
|
|
120
|
-
|
|
298
|
+
<!-- YAML
|
|
299
|
+
added: v7.0.0
|
|
300
|
+
-->
|
|
301
|
+
|
|
302
|
+
Emitted when the connection is closed. The listener receives a `CloseEvent`
|
|
303
|
+
whose `code` and `reason` describe why the connection closed, and whose
|
|
304
|
+
`wasClean` property is `true` only when the closing handshake completed in both
|
|
305
|
+
directions.
|
|
306
|
+
|
|
307
|
+
## `ping(websocket[, payload])`
|
|
308
|
+
|
|
309
|
+
<!-- YAML
|
|
310
|
+
added: v7.12.0
|
|
311
|
+
-->
|
|
312
|
+
|
|
313
|
+
* `websocket` {WebSocket} The WebSocket to send the ping frame on.
|
|
314
|
+
* `payload` {Buffer} Optional payload to include in the ping frame. Must not
|
|
315
|
+
exceed 125 bytes. **Default:** `undefined`.
|
|
316
|
+
|
|
317
|
+
Sends a ping control frame to the server. A conforming server replies with a
|
|
318
|
+
pong frame containing the same payload, which can be used to keep the connection
|
|
319
|
+
alive or to verify that it is still active.
|
|
320
|
+
|
|
321
|
+
The frame is only sent when the connection is open; if it is connecting,
|
|
322
|
+
closing, or closed, the call is a no-op. A `TypeError` is thrown if `payload`
|
|
323
|
+
is not a `Buffer` or is larger than 125 bytes.
|
|
324
|
+
|
|
325
|
+
```mjs
|
|
121
326
|
import { WebSocket, ping } from 'undici'
|
|
122
327
|
|
|
123
328
|
const ws = new WebSocket('wss://echo.websocket.events')
|
|
124
329
|
|
|
125
330
|
ws.addEventListener('open', () => {
|
|
126
|
-
// Send ping with no payload
|
|
127
331
|
ping(ws)
|
|
128
|
-
|
|
129
|
-
// Send ping with payload
|
|
130
|
-
const payload = Buffer.from('hello')
|
|
131
|
-
ping(ws, payload)
|
|
332
|
+
ping(ws, Buffer.from('hello'))
|
|
132
333
|
})
|
|
133
334
|
```
|
|
134
335
|
|
|
135
|
-
|
|
336
|
+
## Class: `WebSocketStream`
|
|
337
|
+
|
|
338
|
+
<!-- YAML
|
|
339
|
+
added: v7.0.0
|
|
340
|
+
-->
|
|
341
|
+
|
|
342
|
+
> Stability: 1 - Experimental
|
|
343
|
+
|
|
344
|
+
`WebSocketStream` is a streams-based alternative to the event-based
|
|
345
|
+
[`WebSocket`][] interface, exposing a connection as a pair of `ReadableStream`
|
|
346
|
+
and `WritableStream` objects. See [MDN][MDN WebSocketStream] for background.
|
|
347
|
+
|
|
348
|
+
Constructing a `WebSocketStream` for the first time emits an
|
|
349
|
+
`ExperimentalWarning` with the code `UNDICI-WSS`.
|
|
350
|
+
|
|
351
|
+
### `new WebSocketStream(url[, options])`
|
|
352
|
+
|
|
353
|
+
<!-- YAML
|
|
354
|
+
added: v7.0.0
|
|
355
|
+
-->
|
|
356
|
+
|
|
357
|
+
> Stability: 1 - Experimental
|
|
358
|
+
|
|
359
|
+
* `url` {URL|string} The URL of the server to connect to.
|
|
360
|
+
* `options` {WebSocketStreamOptions}
|
|
361
|
+
* `protocols` {string|string[]} Subprotocol(s) to request the server use.
|
|
362
|
+
**Default:** `[]`.
|
|
363
|
+
* `signal` {AbortSignal|null} An `AbortSignal` that aborts the opening
|
|
364
|
+
handshake and rejects [`webSocketStream.opened`][] and
|
|
365
|
+
[`webSocketStream.closed`][] when triggered. **Default:** `null`.
|
|
366
|
+
|
|
367
|
+
Creates a new `WebSocketStream` and begins connecting to `url`. As with
|
|
368
|
+
[`new WebSocket()`][], a repeated or invalid subprotocol causes a `SyntaxError`
|
|
369
|
+
`DOMException` to be thrown.
|
|
370
|
+
|
|
371
|
+
```mjs
|
|
372
|
+
import { WebSocketStream } from 'undici'
|
|
373
|
+
|
|
374
|
+
const stream = new WebSocketStream('wss://echo.websocket.events')
|
|
375
|
+
const { readable, writable } = await stream.opened
|
|
376
|
+
|
|
377
|
+
const writer = writable.getWriter()
|
|
378
|
+
await writer.write('Hello, world!')
|
|
379
|
+
writer.releaseLock()
|
|
380
|
+
|
|
381
|
+
const reader = readable.getReader()
|
|
382
|
+
const { value } = await reader.read()
|
|
383
|
+
console.log('received:', value)
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### `webSocketStream.url`
|
|
387
|
+
|
|
388
|
+
<!-- YAML
|
|
389
|
+
added: v5.15.0
|
|
390
|
+
-->
|
|
391
|
+
|
|
392
|
+
> Stability: 1 - Experimental
|
|
393
|
+
|
|
394
|
+
* Type: {string}
|
|
395
|
+
|
|
396
|
+
The serialized URL of the WebSocket. This property is read-only.
|
|
397
|
+
|
|
398
|
+
### `webSocketStream.opened`
|
|
399
|
+
|
|
400
|
+
<!-- YAML
|
|
401
|
+
added: v5.15.0
|
|
402
|
+
-->
|
|
403
|
+
|
|
404
|
+
> Stability: 1 - Experimental
|
|
405
|
+
|
|
406
|
+
* Type: {Promise} Fulfills once the connection is established.
|
|
407
|
+
|
|
408
|
+
A promise that resolves with an object describing the open connection, or
|
|
409
|
+
rejects if the connection could not be established. The fulfillment value has
|
|
410
|
+
the following shape:
|
|
411
|
+
|
|
412
|
+
* `extensions` {string} The negotiated extensions.
|
|
413
|
+
* `protocol` {string} The negotiated subprotocol.
|
|
414
|
+
* `readable` {ReadableStream} A stream of incoming messages. Text frames are
|
|
415
|
+
delivered as strings and binary frames as `Uint8Array` chunks.
|
|
416
|
+
* `writable` {WritableStream} A stream for sending messages. Writing a string
|
|
417
|
+
sends a text frame; writing a `BufferSource` sends a binary frame.
|
|
418
|
+
|
|
419
|
+
### `webSocketStream.closed`
|
|
420
|
+
|
|
421
|
+
<!-- YAML
|
|
422
|
+
added: v5.15.0
|
|
423
|
+
-->
|
|
424
|
+
|
|
425
|
+
> Stability: 1 - Experimental
|
|
426
|
+
|
|
427
|
+
* Type: {Promise} Fulfills once the connection is closed cleanly.
|
|
428
|
+
|
|
429
|
+
A promise that resolves with a `WebSocketCloseInfo` object when the connection
|
|
430
|
+
closes cleanly, or rejects with a [`WebSocketError`][] when it closes
|
|
431
|
+
abnormally. The fulfillment value has the following shape:
|
|
432
|
+
|
|
433
|
+
* `closeCode` {number} The status code the connection was closed with.
|
|
434
|
+
* `reason` {string} The reason the connection was closed with.
|
|
435
|
+
|
|
436
|
+
### `webSocketStream.close([closeInfo])`
|
|
437
|
+
|
|
438
|
+
<!-- YAML
|
|
439
|
+
added: v5.15.0
|
|
440
|
+
-->
|
|
441
|
+
|
|
442
|
+
> Stability: 1 - Experimental
|
|
443
|
+
|
|
444
|
+
* `closeInfo` {Object}
|
|
445
|
+
* `closeCode` {number} The status code to close with.
|
|
446
|
+
* `reason` {string} The reason to close with. **Default:** `''`.
|
|
447
|
+
|
|
448
|
+
Starts the closing handshake. When `closeInfo` is omitted, the connection is
|
|
449
|
+
closed without a status code.
|
|
450
|
+
|
|
451
|
+
## Class: `WebSocketError`
|
|
452
|
+
|
|
453
|
+
<!-- YAML
|
|
454
|
+
added: v7.0.0
|
|
455
|
+
-->
|
|
456
|
+
|
|
457
|
+
> Stability: 1 - Experimental
|
|
458
|
+
|
|
459
|
+
* Extends: {DOMException}
|
|
460
|
+
|
|
461
|
+
An error type used by [`WebSocketStream`][] to report close information. It is
|
|
462
|
+
used to reject [`webSocketStream.closed`][] when the connection closes
|
|
463
|
+
abnormally, and may be passed to a stream's abort or cancel operations to close
|
|
464
|
+
the connection with a specific code and reason.
|
|
465
|
+
|
|
466
|
+
### `new WebSocketError([message[, init]])`
|
|
467
|
+
|
|
468
|
+
<!-- YAML
|
|
469
|
+
added: v7.0.0
|
|
470
|
+
-->
|
|
471
|
+
|
|
472
|
+
> Stability: 1 - Experimental
|
|
473
|
+
|
|
474
|
+
* `message` {string} A human-readable description of the error.
|
|
475
|
+
**Default:** `''`.
|
|
476
|
+
* `init` {Object}
|
|
477
|
+
* `closeCode` {number} The status code to associate with the error.
|
|
478
|
+
* `reason` {string} The reason to associate with the error.
|
|
479
|
+
**Default:** `''`.
|
|
480
|
+
|
|
481
|
+
Creates a new `WebSocketError`. If `reason` is non-empty but no `closeCode` is
|
|
482
|
+
given, `closeCode` defaults to `1000` ("Normal Closure"). The `closeCode` and
|
|
483
|
+
`reason` are validated, so an out-of-range code or an over-long reason throws.
|
|
484
|
+
|
|
485
|
+
### `webSocketError.closeCode`
|
|
486
|
+
|
|
487
|
+
<!-- YAML
|
|
488
|
+
added: v5.15.0
|
|
489
|
+
-->
|
|
490
|
+
|
|
491
|
+
> Stability: 1 - Experimental
|
|
492
|
+
|
|
493
|
+
* Type: {number|null}
|
|
494
|
+
|
|
495
|
+
The status code associated with the error, or `null` if none was set. This
|
|
496
|
+
property is read-only.
|
|
497
|
+
|
|
498
|
+
### `webSocketError.reason`
|
|
499
|
+
|
|
500
|
+
<!-- YAML
|
|
501
|
+
added: v5.15.0
|
|
502
|
+
-->
|
|
503
|
+
|
|
504
|
+
> Stability: 1 - Experimental
|
|
505
|
+
|
|
506
|
+
* Type: {string}
|
|
507
|
+
|
|
508
|
+
The reason associated with the error. This property is read-only.
|
|
509
|
+
|
|
510
|
+
## Read more
|
|
136
511
|
|
|
137
|
-
|
|
512
|
+
* [MDN: WebSocket][]
|
|
513
|
+
* [RFC 6455][]
|
|
514
|
+
* [WHATWG WebSocket specification][]
|
|
138
515
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
516
|
+
[MDN WebSocketStream]: https://developer.mozilla.org/docs/Web/API/WebSocketStream
|
|
517
|
+
[MDN: WebSocket]: https://developer.mozilla.org/docs/Web/API/WebSocket
|
|
518
|
+
[RFC 6455]: https://www.rfc-editor.org/rfc/rfc6455
|
|
519
|
+
[WHATWG WebSocket specification]: https://websockets.spec.whatwg.org/
|
|
520
|
+
[`'close'`]: #event-close
|
|
521
|
+
[`'error'`]: #event-error
|
|
522
|
+
[`'message'`]: #event-message
|
|
523
|
+
[`'open'`]: #event-open
|
|
524
|
+
[`ProxyAgent`]: ProxyAgent.md#class-proxyagent
|
|
525
|
+
[`WebSocket`]: #class-websocket
|
|
526
|
+
[`WebSocketError`]: #class-websocketerror
|
|
527
|
+
[`WebSocketStream`]: #class-websocketstream
|
|
528
|
+
[`new WebSocket()`]: #new-websocketurl-protocols
|
|
529
|
+
[`ping()`]: #pingwebsocket-payload
|
|
530
|
+
[`webSocketStream.closed`]: #websocketstreamclosed
|
|
531
|
+
[`webSocketStream.opened`]: #websocketstreamopened
|
|
532
|
+
[`websocket.bufferedAmount`]: #websocketbufferedamount
|
|
533
|
+
[`websocket.binaryType`]: #websocketbinarytype
|
|
534
|
+
[`websocket.readyState`]: #websocketreadystate
|
|
535
|
+
[`websocket.send()`]: #websocketsenddata
|
|
536
|
+
[`websocket.url`]: #websocketurl
|