Pullboard
A work board that lives in your git repo. Agents pick up the next task, another agent checks it, and you barely explain a thing. Local, open source, no account.
翻譯準備中
ZERO-DEPENDENCY WebSocket SERVER for Node — RFC 6455 framing over node:http's `upgrade` event, on node:http/net/crypto/events and nothing else. Node 22 ships a WebSocket CLIENT (the `WebSocket` global
翻譯準備中
開發工具TypeScript · PythonGitHub @Particle-Academy上線中營運者未確認
試用過了嗎? 點一下就好,不需要登入。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證A WebSocket server for Node with zero runtime dependencies. Node ships a WebSocket client and no server; this is the server half -- RFC 6455 framing over node:http's upgrade event, with authorisation before the 101.
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗A WebSocket server for Node, with zero runtime dependencies.
Node 22 ships a WebSocket client — the WebSocket global, from undici — and
no server. This is the other half: RFC 6455 framing over node:http's upgrade
event, built on node:http, node:net, node:crypto and node:events and
nothing else.
npm install @particle-academy/fancy-ws
import { createServer } from 'node:http';
import { attachWebSocketServer } from '@particle-academy/fancy-ws';
const http = createServer();
const ws = attachWebSocketServer(http, { path: '/remote' });
ws.on('connection', (socket, request, verified) => {
socket.on('message', (data, isBinary) => {
if (!isBinary) {
socket.send(JSON.stringify({ echo: JSON.parse(data as string) }));
}
});
socket.on('close', (code, reason) => console.log('gone', code, reason));
});
ws.heartbeat(30_000);
http.listen(7421);
It shares the server, so plain HTTP routes on the same port keep working.
verify runs during the handshake, so a refusal is a plain HTTP response
rather than an open-then-close.
const ws = attachWebSocketServer(http, {
path: '/pair',
verify: async (req) => {
const pin = new URL(req.url ?? '/', 'http://local').searchParams.get('pin');
if (!pin) return 401; // any 4xx/5xx status
const session = await pins.claim(pin);
if (!session) return 403;
return { session }; // handed to `connection`
},
});
ws.on('connection', (socket, _req, { session }) => { /* already authorised */ });
verify returns | result |
|---|---|
true | accept; verified is {} |
| an object | accept; the object becomes verified |
false | refuse with 403 |
| a number | refuse with that status |
| throws | 500, and the error is emitted on the server's error event |
Why before and not after. An accept-then-close hands an unauthenticated peer a live frame parser, however briefly, and forces the client to tell "authorised" from "refused" by interpreting a close code. A 401 is something every HTTP client already understands.
One measured caveat if the client is Node's own: on a refused handshake, Node
v22.23.2 fires error and no close, and leaves readyState at
CONNECTING forever. A consumer waiting on close to learn the handshake
failed waits indefinitely — listen for error. This is a deviation from the
WHATWG spec's "fail the WebSocket connection", so it may change; the suite
asserts the current behaviour so a fix surfaces as a test failure here rather
than as a surprise in a consumer.
socket.send('text'); // or a Uint8Array for binary
socket.send(bytes); // returns false if not OPEN -- never throws
socket.close(1000, 'done');
socket.terminate(); // no handshake; reports 1006
socket.ping();
socket.readyState; // 0/1/2/3, as in the browser
socket.remoteAddress;
socket.protocol; // negotiated subprotocol, or null
socket.request; // the upgrade IncomingMessage
| event | arguments |
|---|---|
message | (data: string | Buffer, isBinary: boolean) |
close | (code: number, reason: string) — fires exactly once |
error | (error: Error) |
ping / pong | (data: Buffer) |
data is a string for text and a Buffer for binary, so JSON.parse(data)
needs no decode step. Messages are reassembled across fragments before delivery.
| option | default | |
|---|---|---|
path | (all) | handle only this exact pathname |
onPathMismatch | 'ignore' | 'ignore' leaves the upgrade for another listener; 'reject' answers 404 |
verify | — | authorise before the 101 (above) |
protocols | — | subprotocols supported, most preferred first |
maxPayload | 1 MiB | largest message, per frame and per reassembled message |
closeTimeoutMs | 10 000 | how long to await the peer's close frame |
onPathMismatch: 'ignore' is the default so this can share a port with
other protocols — Genie's HTTP front door passes upgrade through for its own
surfaces. The cost is worth knowing: with no other upgrade listener, an
unmatched upgrade sits open until the client times out, because Node does not
answer an upgrade once any listener exists. Use 'reject' when this is the only
WebSocket endpoint on the server.
const stop = ws.heartbeat(30_000); // pings; drops after 2 missed pongs
A TCP connection to a machine that slept, lost its network, or lost power stays
OPEN indefinitely: nothing arrives and nothing errors, and readyState is a
statement about this end only. The pong is the only evidence the peer is still
there. The interval timer is unref'd, so it never keeps a process alive.
Does: text, binary, fragmentation, masking enforcement, ping/pong, the close
handshake with code and reason, strict UTF-8 validation (1007), payload limits
per frame and per message (1009), minimal-length-encoding enforcement, RSV and
reserved-opcode refusal (1002), subprotocol negotiation, https.Server as well
as http.Server.
Does not: permessage-deflate (RSV1 is refused rather than ignored, so a
client offering it gets a clean failure instead of a corrupted message); a
client (Node has one built in); clustering or a pub/sub layer.
EventEmitter throws when 'error' is emitted with no listener, so a naive
implementation lets any peer take the process down with one malformed frame.
Every error path here checks for a listener first; the close frame still carries
the protocol verdict to the peer. There is a test that drives a violation
through a connection with no error listener attached and then asserts the
server is still serving.
0.1.x. Pre-1.0, so breaking changes land in minor releases — see
CHANGELOG.md. Requires Node >= 22.
MIT © Particle Academy