@orkestrel/websocket 0.0.10 → 0.0.12
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/README.md +18 -8
- package/dist/src/server/index.cjs +458 -226
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +404 -147
- package/dist/src/server/index.d.ts +404 -147
- package/dist/src/server/index.js +453 -223
- package/dist/src/server/index.js.map +1 -1
- package/package.json +19 -16
package/README.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# @orkestrel/websocket
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
> The server-native bidirectional transport: a lean, typed wrapper over a raw upgraded
|
|
4
|
+
> `node:stream` Duplex socket that speaks only the RFC 6455 wire protocol, owning the
|
|
5
|
+
> handshake, the masked and unmasked frame codec, ping and pong, and the close handshake,
|
|
6
|
+
> and surfacing every message on an owned `emitter`.
|
|
7
|
+
|
|
8
|
+
Take the socket a `node:http` upgrade handler gives you, pass it to the
|
|
9
|
+
`createNodeWebSocket` function, and read every message off the returned handle's
|
|
10
|
+
`emitter`. Its sole runtime dependency is `@orkestrel/emitter`, which supplies that
|
|
11
|
+
typed emitter. Part of the `@orkestrel` line.
|
|
7
12
|
|
|
8
13
|
## Install
|
|
9
14
|
|
|
@@ -13,7 +18,7 @@ npm install @orkestrel/websocket
|
|
|
13
18
|
|
|
14
19
|
## Requirements
|
|
15
20
|
|
|
16
|
-
- Node.js >=
|
|
21
|
+
- Node.js >= 22.12.0
|
|
17
22
|
- Ships dual ESM + CommonJS builds (see `exports` in `package.json`)
|
|
18
23
|
- Server-only — a single Node-native surface
|
|
19
24
|
|
|
@@ -24,12 +29,17 @@ import { createServer } from 'node:http'
|
|
|
24
29
|
import { createNodeWebSocket } from '@orkestrel/websocket'
|
|
25
30
|
|
|
26
31
|
// A node:http server hands every upgrade request a raw socket; this wrapper takes it
|
|
27
|
-
// from there. Passing the client's `sec-websocket-key` selects
|
|
32
|
+
// from there. Passing the client's `sec-websocket-key` selects server mode — the
|
|
28
33
|
// wrapper writes the 101 handshake, marks the connection open, and decodes frames.
|
|
29
34
|
createServer().on('upgrade', (request, socket, head) => {
|
|
35
|
+
const key = request.headers['sec-websocket-key']
|
|
36
|
+
if (typeof key !== 'string') {
|
|
37
|
+
socket.destroy()
|
|
38
|
+
return
|
|
39
|
+
}
|
|
30
40
|
const ws = createNodeWebSocket({
|
|
31
41
|
socket,
|
|
32
|
-
key
|
|
42
|
+
key, // present => server mode + 101 handshake
|
|
33
43
|
head, // any bytes that arrived bundled with the upgrade request
|
|
34
44
|
on: { message: (text) => ws.send(`echo: ${text}`) }, // wire listeners at construction
|
|
35
45
|
})
|
|
@@ -42,7 +52,7 @@ createServer().on('upgrade', (request, socket, head) => {
|
|
|
42
52
|
|
|
43
53
|
The full API — factories, the `NodeWebSocket` class, the pure codec helpers,
|
|
44
54
|
constants, and types — is documented in
|
|
45
|
-
[`guides/
|
|
55
|
+
[`guides/websocket.md`](https://github.com/orkestrel/websocket/blob/main/guides/websocket.md).
|
|
46
56
|
|
|
47
57
|
## Package
|
|
48
58
|
|