@dokebi/websocket 0.4.0 → 0.4.1
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/AI.md +6 -5
- package/README.md +4 -4
- package/dist/gateway.js +72 -17
- package/dist/index.js +1 -1
- package/dist/options.js +1 -1
- package/options.schema.json +1 -1
- package/package.json +3 -3
package/AI.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# AI guide — @dokebi/websocket 0.4.
|
|
1
|
+
# AI guide — @dokebi/websocket 0.4.1
|
|
2
2
|
|
|
3
3
|
Opens WebSocket routes on dokebi-web (Fastify) and connects broadcasts and the connection list across servers and workers through @dokebi/websocket-hub. A broadcast is **at most once**: once the hub sends it out it is done; there is no client ACK or resend ([D-0057](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0057-websocket-broadcast-without-ack.md)). No views or DB are forced. Node >=24, core ^0.4.0, peers: @dokebi/web, @dokebi/websocket-hub. Details are in the [README](README.md).
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ The hub style is chosen in dokebi.yaml `options.dokebi-websocket-hub.mode`. `loc
|
|
|
23
23
|
|---|---|---|---|
|
|
24
24
|
| `maxPayloadBytes` | integer | 65536 | Message size |
|
|
25
25
|
| `maxConnections` | integer | 128 | Connections of this process |
|
|
26
|
-
| `maxPending` | integer | 32 | Waiting messages per connection (each connection runs in order) |
|
|
26
|
+
| `maxPending` | integer | 32 | Waiting messages per connection (each connection runs in order); also bounds its waiting presence calls, separately |
|
|
27
27
|
| `maxBufferedBytes` | integer | 1048576 | Send buffer. Beyond it the socket is closed with 1013 `Slow consumer` and warn `WebSocket slow consumer closed` (code `SLOW_CONSUMER`) is logged. Replies meant for that socket are dropped (not counted as handler failures) |
|
|
28
28
|
| `shutdownTimeoutMs` | integer ms | 2000 | Socket close wait at drain (not a limit on work) |
|
|
29
29
|
| `heartbeatMs` | integer ms | 10000 | ping/pong |
|
|
@@ -105,7 +105,7 @@ setInterval(() => socket.send('{"$dokebi":"ping-v1"}'), 15000); // when
|
|
|
105
105
|
|
|
106
106
|
- Broadcasts arrive as the bytes the server sent: a text frame when UTF-8 (`defineSocket`'s `{ type, data }` JSON), otherwise a binary frame. There is no envelope to unwrap (`delivery-v1`) and no ACK to send. The browser entry `@dokebi/websocket/client` (`DeliveryReceiver`) was removed in 0.2.0 (importing it fails to resolve). Use only the standard `WebSocket` API. The `{"$dokebi":"ack-v1"}` that old pages send is ignored, not closed (debug `ACK_IGNORED`).
|
|
107
107
|
- Broadcasts sent while disconnected or while closed as a slow consumer never come again. The screen reads the latest state from the server after reconnecting.
|
|
108
|
-
- Close codes: 4426 reload, 4409 duplicate clientId (`Duplicate client`), 4408 idle, 1013 hub unavailable or
|
|
108
|
+
- Close codes: 4426 reload, 4409 duplicate clientId (`Duplicate client`), 4408 idle, 1013 hub unavailable, slow consumer or a full replay nonce store (`Try again later`, D-0075), 1012 server shutting down, 1011 unhandled handler error, 4415 sealed host but no `dokebi.seal` offered, 4400 sealed frame refused (§4a). 4400 and 4415 repeat on reconnect, so do not reconnect.
|
|
109
109
|
|
|
110
110
|
## 4a. Sealed connections (0.3.0, [D-0059](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0059-seal-and-websocket-client.md) §4)
|
|
111
111
|
|
|
@@ -115,7 +115,7 @@ Every frame is sealed per host (or route). **This package does not know the seal
|
|
|
115
115
|
- Contract (shape only): `SocketCodecProvider { forConnection({ host, path, userAgent, nonces, driftMs }): SocketCodec }`, `SocketCodec { decode(frame): Promise<string>; encode(text): string; hello(): string }`. `host` is the web `requestHost` (with trustProxy applied) in lower case without the port, `path` the upgrade path (no query), `nonces` is `hub.nonces()` (cluster = shared in Redis, local = in process), `driftMs` is `sealDriftMs`.
|
|
116
116
|
- Negotiation: a client with the seal bridge offers the subprotocols `['dokebi.seal', 'dokebi.plain']` (constants `SEAL_PROTOCOL`, `PLAIN_PROTOCOL`). A sealed connection picks only `dokebi.seal` (never plain). When it is not offered, the connection is closed after the upgrade with **4415** `Seal required` (no reconnect). A plain connection picks `dokebi.plain` when offered, otherwise nothing (old clients). Clients decide sealing only by `ws.protocol === 'dokebi.seal'`, so the same page code runs in plain on a plain host.
|
|
117
117
|
- Flow: the server first sends a sealed `{"$dokebi":"hello-v1"}` (the client measures clock offset from its ts). Incoming frames are opened in the connection's order chain, then go to control frames (`$dokebi` ping, ack) or the route (counted in waiting messages). Routes and handlers see plain text.
|
|
118
|
-
- Refusal: unsealed frames, binary frames, frames that fail to open, drift and replays get **4400** `Bad frame`. The reason (`no-prefix`, `plain-rejected`, `drift`, `replay`, `open-failed`, `binary`) goes only to the warn log, never to the client (so replay success cannot be probed). After a refusal no further frames of that connection are read.
|
|
118
|
+
- Refusal: unsealed frames, binary frames, frames that fail to open, drift and replays get **4400** `Bad frame`. The reason (`no-prefix`, `plain-rejected`, `drift`, `replay`, `open-failed`, `binary`) goes only to the warn log, never to the client (so replay success cannot be probed). After a refusal no further frames of that connection are read. One exception: when the hub's local nonce store is full of live nonces (seal reason `capacity`, [D-0075](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0075-replay-capacity.md)), the frame is refused and the connection closes with **1013** `Try again later` (temporary: the client reconnects with backoff), warn `SEAL_FRAME_REFUSED` with `reason: capacity`.
|
|
119
119
|
- Outgoing: replies, `send`, presence and broadcasts are all sealed. Plain sockets share one broadcast buffer; only sealed sockets are sealed per recipient. UTF-8 bytes are sealed as text; `send` of non-UTF-8 bytes is refused with `SEAL_BINARY_UNSUPPORTED` (in `defineSocket`, an error reply with that code). Binary broadcasts are not sent to sealed sockets and are counted (warn `SEAL_BINARY_UNSUPPORTED`, `dropped`).
|
|
120
120
|
- Cost (2026-10-15, `benchmarks/results/2026-10-15-websocket-seal.json`): one seal plus open about 15–17 µs (1 KB), a broadcast to 500 recipients p50 about 14.5 ms (plain 1.6 ms), a request round trip with a Redis nonce p50 0.38 ms (plain 0.04 ms).
|
|
121
121
|
|
|
@@ -127,6 +127,7 @@ Every frame is sealed per host (or route). **This package does not know the seal
|
|
|
127
127
|
- Sending a broadcast does not wait per socket; it goes into the send queue (order kept per socket). Only slow sockets are closed.
|
|
128
128
|
- `send` is a raw reply (current socket). It is done once it is in the send buffer.
|
|
129
129
|
- presence: the first change one server receives may list connections that existed before as joined. Screens read the list again when presence arrives.
|
|
130
|
+
- presence calls per connection are bounded by `maxPending` (counted apart from messages). A handler slower than the changes gets them merged: later changes become one net `{ joined, left }` (a connection that joined and left meanwhile appears in neither), handed over when a call ends; warn `PRESENCE_MERGED` once per 10 seconds. Apply `left` and `joined` to a kept list and it stays right.
|
|
130
131
|
|
|
131
132
|
## 6. Shutdown
|
|
132
133
|
|
|
@@ -137,7 +138,7 @@ stop: block new work → wait for received handlers and broadcasts being sent
|
|
|
137
138
|
- Exceptions are never dropped silently. Failures other than those turned into close codes or error replies are `error`: a fixed English message + `code` + `error` (the full original error: name, whole message, stack and `Caused by: …` for each cause, address, port and errno text included; only URL credentials masked as `//***@`; cut only beyond 16 KB). Examples: handler failure `WebSocket message handler failed` (code from the error or `HANDLER_FAILED`, closed with 1011), socket error `SOCKET_ERROR`, broadcast write failure `BROADCAST_WRITE_FAILED`, presence handler `PRESENCE_HANDLER_FAILED`, lost hub events `HUB_EVENTS_FAILED` (every socket 1013), delayed cleanup `PRESENCE_CLEANUP_DEFERRED`. Registration failures are warn (closed with 4409 or 1013), slow consumers warn `SLOW_CONSUMER`. A reply or presence that could not be written to an already closed socket is warn `REPLY_DROPPED` (the client simply left; not a server failure; once per 10 seconds + `repeated`).
|
|
138
139
|
- Places that run per message or socket write the same message and code once per 10 seconds and group the rest as a `repeated` count (the remaining count is written at drain end too). Bodies and tokens are never logged.
|
|
139
140
|
- Sealing (§4a): a refused frame is warn `WebSocket sealed frame refused; closed` (code `SEAL_FRAME_REFUSED`, `reason`, `error`; one line per reason per 10 seconds + `repeated`), codec creation failure error `SEAL_CODEC_FAILED` (1011), broadcast seal failure error `SEAL_ENCODE_FAILED` (1011), hello send failure warn `SEAL_HELLO_FAILED`. debug: provider present (`WebSocket seal provider`), the decision per upgrade (`WebSocket seal decision`: path, sealed, offered), `WebSocket seal hello sent`, 4415 (`WebSocket seal required; closed`), `sealed` on connection logs, the `sealed` count on broadcast logs.
|
|
140
|
-
- debug: connect, close, refused upgrades, hub registration ms, room join, leave and refusal, presence changes (counts), kick, broadcast delivery (ID, connection count, `binary`; after checking `isEnabled`), ignored `ack-v1` from old clients (`ACK_IGNORED`, one line per 10 seconds + `repeated`), idle and heartbeat closes, drain start and end. Too many waiting messages (1013 `Too many messages`) is warn `TOO_MANY_MESSAGES
|
|
141
|
+
- debug: connect, close, refused upgrades, hub registration ms, room join, leave and refusal, presence changes (counts), kick, broadcast delivery (ID, connection count, `binary`; after checking `isEnabled`), ignored `ack-v1` from old clients (`ACK_IGNORED`, one line per 10 seconds + `repeated`), idle and heartbeat closes, drain start and end. Too many waiting messages (1013 `Too many messages`) is warn `TOO_MANY_MESSAGES`; presence changes merged behind a slow presence handler are warn `PRESENCE_MERGED` (once per 10 seconds + `repeated`).
|
|
141
142
|
- `defineSocket` handler errors: the client still gets only `{ type: 'error', id?, code }` (no message or stack; the socket stays open), and the server logs error `WebSocket handler failed.` (code `SOCKET_HANDLER_FAILED`, `type` = message type, `reply` = the code sent to the client, `connection`, `error` = full text). Repeats are one line per type + reply code per 10 seconds. Malformed messages and unknown types (client mistakes) are debug `WebSocket client message refused` (code `INVALID_MESSAGE` or `UNKNOWN_TYPE`, counted and grouped per code).
|
|
142
143
|
- This report goes through `session.reportError?(error, { source: 'handler' | 'client', code, type? })`. Only sessions the gateway created have it; with a hand-made session (tests and the like) `defineSocket` only sends the reply. A low-level `route.message` can report through the same method.
|
|
143
144
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @dokebi/websocket
|
|
2
2
|
|
|
3
|
-
Node >=24, version 0.4.
|
|
3
|
+
Node >=24, version 0.4.1 (unreleased). An optional plugin that connects the Dokebi Fastify web plugin with websocket-hub. It does not force templates or views on API servers. AI agents start with [AI.md](AI.md).
|
|
4
4
|
|
|
5
5
|
```ts snippet
|
|
6
6
|
import { Application, dependencyOf, loadConfig } from '@dokebi/core';
|
|
@@ -38,7 +38,7 @@ Prepare the required YAML of websocket-hub. The CLI registration order is redis
|
|
|
38
38
|
|---|---|---|---|
|
|
39
39
|
| `maxPayloadBytes` | integer | 65536 | Message size |
|
|
40
40
|
| `maxConnections` | integer | 128 | Connections per process |
|
|
41
|
-
| `maxPending` | integer | 32 | Waiting messages per connection |
|
|
41
|
+
| `maxPending` | integer | 32 | Waiting messages per connection; also bounds its waiting presence calls, separately |
|
|
42
42
|
| `maxBufferedBytes` | integer | 1048576 | Send buffer before 1013 `Slow consumer` |
|
|
43
43
|
| `shutdownTimeoutMs` | integer ms | 2000 | Socket close wait at drain |
|
|
44
44
|
| `heartbeatMs` | integer ms | 10000 | ping/pong interval |
|
|
@@ -71,7 +71,7 @@ stop blocks new work, waits for received handlers and broadcasts being sent, the
|
|
|
71
71
|
|
|
72
72
|
`hub.events` is consumed only by this plugin. `broadcast` is at most once and returns the receipt `{ id, recipients }` once the hub sends it out ("Broadcast" below). `send` is a raw reply on the current socket with its own completion contract. Verified cross-server delivery between two real containers and four workers, a hub SIGKILL, NATS faults and DB drain do not mean full operational certification or verification on two physical machines.
|
|
73
73
|
|
|
74
|
-
**Joins and leaves (presence):** the hub tells every server the connection list of a server owner whenever connections come and go, including when a dead server's registration expires. This package turns that into per-tenant `{ tenant, joined, left }` and calls the route's `presence(change, session)` hook for each of its own connections open in the same tenant, in that connection's message order.
|
|
74
|
+
**Joins and leaves (presence):** the hub tells every server the connection list of a server owner whenever connections come and go, including when a dead server's registration expires. This package turns that into per-tenant `{ tenant, joined, left }` and calls the route's `presence(change, session)` hook for each of its own connections open in the same tenant, in that connection's message order. At most `maxPending` presence calls wait per connection; changes that come while that many wait are merged into one net change (joins and leaves of the same connection cancel out) and handed over when a call ends, with warn `PRESENCE_MERGED` once per 10 seconds. Nothing is dropped: applying the calls in order gives the same list.
|
|
75
75
|
- `defineSocket({ presence: true })` sends `{ type: 'presence', data: { tenant, joined, left } }` to each connection. Given a function, that function handles it as `(change, socket)`.
|
|
76
76
|
- The first notice a server receives may list connections that existed before as `joined`. Screens should read the list again when this message arrives.
|
|
77
77
|
|
|
@@ -130,7 +130,7 @@ context.get(ws).route({
|
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
- When a sealed route exists but no `dokebi-seal` plugin does, setup fails with `SEAL_PROVIDER_MISSING`.
|
|
133
|
-
- Sealed connections: the client must offer the subprotocol `dokebi.seal` (otherwise 4415 `Seal required`). The server first sends a sealed `{"$dokebi":"hello-v1"}`, and opens incoming frames in the connection's order chain before passing them to control frames or the route. Frames that do not open (plain, binary, drift, replay) get 4400 `Bad frame`, with the reason only in the server warn log. Replies, presence and broadcasts go out sealed; plain sockets still share one broadcast buffer and only sealed sockets are sealed per recipient. Binary is not sent (`SEAL_BINARY_UNSUPPORTED`).
|
|
133
|
+
- Sealed connections: the client must offer the subprotocol `dokebi.seal` (otherwise 4415 `Seal required`). The server first sends a sealed `{"$dokebi":"hello-v1"}`, and opens incoming frames in the connection's order chain before passing them to control frames or the route. Frames that do not open (plain, binary, drift, replay) get 4400 `Bad frame`, with the reason only in the server warn log. A frame refused because the local replay nonce store is full of live nonces (fail closed, D-0075) closes with 1013 `Try again later` instead, so the client reconnects. Replies, presence and broadcasts go out sealed; plain sockets still share one broadcast buffer and only sealed sockets are sealed per recipient. Binary is not sent (`SEAL_BINARY_UNSUPPORTED`).
|
|
134
134
|
- Negotiation: clients with the seal bridge offer `dokebi.seal` and `dokebi.plain` (`PLAIN_PROTOCOL`) together. A sealed connection picks only `dokebi.seal` (never plain); a plain connection picks `dokebi.plain` when offered, otherwise nothing (old clients unchanged). So a page with the bridge still runs in plain on a plain host.
|
|
135
135
|
- `sealDriftMs` (default 60000): allowed frame time difference. Replay nonces stay in `hub.nonces()` (shared in Redis in cluster mode) for twice as long.
|
|
136
136
|
- Detailed rules, logs and costs are in [AI.md](AI.md) §4a.
|
package/dist/gateway.js
CHANGED
|
@@ -121,6 +121,19 @@ function aborted(signal) {
|
|
|
121
121
|
signal.addEventListener('abort', () => resolve(), { once: true });
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Folds `change` into `buffer`: a peer that joined and then left (or left and then joined)
|
|
126
|
+
* before the handler saw either cancels out, so the buffer holds the net change and never more
|
|
127
|
+
* peers than the tenant has.
|
|
128
|
+
*/
|
|
129
|
+
function mergePresence(buffer, change) {
|
|
130
|
+
for (const peer of change.joined)
|
|
131
|
+
if (!buffer.left.delete(peer.connection))
|
|
132
|
+
buffer.joined.set(peer.connection, peer);
|
|
133
|
+
for (const peer of change.left)
|
|
134
|
+
if (!buffer.joined.delete(peer.connection))
|
|
135
|
+
buffer.left.set(peer.connection, peer);
|
|
136
|
+
}
|
|
124
137
|
export class Gateway {
|
|
125
138
|
context;
|
|
126
139
|
web;
|
|
@@ -426,6 +439,8 @@ export class Gateway {
|
|
|
426
439
|
session: undefined,
|
|
427
440
|
tail: Promise.resolve(),
|
|
428
441
|
pending: 0,
|
|
442
|
+
presencePending: 0,
|
|
443
|
+
presenceBuffer: undefined,
|
|
429
444
|
registration: undefined,
|
|
430
445
|
alive: true,
|
|
431
446
|
failed: false,
|
|
@@ -622,11 +637,19 @@ export class Gateway {
|
|
|
622
637
|
* A sealed frame that did not open (plain text, binary, drift, replay, bad seal): 4400 and the
|
|
623
638
|
* connection takes nothing more. The reason goes to the log only, never to the client: telling
|
|
624
639
|
* `replay` from `drift` would let an attacker probe the defence (D-0059 §4).
|
|
640
|
+
* One exception: `capacity` (the in-process nonce store is full of live nonces, D-0075) is the
|
|
641
|
+
* server's state, not the frame's, so it closes with 1013 `Try again later` and the client
|
|
642
|
+
* reconnects with backoff.
|
|
625
643
|
*/
|
|
626
644
|
#refuse(value, id, error) {
|
|
627
645
|
const given = error?.reason;
|
|
628
646
|
const reason = typeof given === 'string' && REASON.test(given) ? given : 'unknown';
|
|
629
647
|
value.failed = true;
|
|
648
|
+
if (reason === 'capacity') {
|
|
649
|
+
this.#throttle.log('warn', 'WebSocket sealed frame refused: replay nonce store full; closed', 'SEAL_FRAME_REFUSED', error, { connection: id, reason }, reason);
|
|
650
|
+
value.socket.close(1013, 'Try again later');
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
630
653
|
this.#throttle.log('warn', 'WebSocket sealed frame refused; closed', 'SEAL_FRAME_REFUSED', error, { connection: id, reason }, reason);
|
|
631
654
|
value.socket.close(BAD_FRAME, 'Bad frame');
|
|
632
655
|
}
|
|
@@ -724,25 +747,57 @@ export class Gateway {
|
|
|
724
747
|
!value.registration ||
|
|
725
748
|
value.socket.readyState !== WebSocket.OPEN)
|
|
726
749
|
continue;
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
left:
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const code = error?.code;
|
|
737
|
-
if (code === 'SLOW_CONSUMER')
|
|
738
|
-
return; // Logged where the socket was closed.
|
|
739
|
-
this.#throttle.log(code === 'SOCKET_CLOSED' ? 'warn' : 'error', code === 'SOCKET_CLOSED'
|
|
740
|
-
? 'WebSocket presence dropped; socket closed'
|
|
741
|
-
: 'WebSocket presence handler failed', code === 'SOCKET_CLOSED' ? 'REPLY_DROPPED' : 'PRESENCE_HANDLER_FAILED', error, { connection: session.id });
|
|
742
|
-
});
|
|
743
|
-
this.#watch(value.tail);
|
|
750
|
+
// At most maxPending presence calls wait per connection (like its messages); changes
|
|
751
|
+
// that come while that many wait are merged and handed over when a call ends.
|
|
752
|
+
if (value.presencePending >= this.settings.maxPending) {
|
|
753
|
+
value.presenceBuffer ??= { joined: new Map(), left: new Map() };
|
|
754
|
+
mergePresence(value.presenceBuffer, change);
|
|
755
|
+
this.#throttle.log('warn', 'WebSocket presence changes merged; handler behind', 'PRESENCE_MERGED', undefined, { connection: session.id, maxPending: this.settings.maxPending });
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
this.#presenceCall(value, route, session, change.joined, change.left);
|
|
744
759
|
}
|
|
745
760
|
}
|
|
761
|
+
/** Queues one presence call on the connection, in order with its messages. */
|
|
762
|
+
#presenceCall(value, route, session, joined, left) {
|
|
763
|
+
const presence = Object.freeze({
|
|
764
|
+
tenant: session.identity.tenant,
|
|
765
|
+
joined: Object.freeze([...joined]),
|
|
766
|
+
left: Object.freeze([...left]),
|
|
767
|
+
});
|
|
768
|
+
value.presencePending++;
|
|
769
|
+
// In order with this connection's messages, like a message handler.
|
|
770
|
+
value.tail = value.tail
|
|
771
|
+
.then(() => route.presence?.(presence, session))
|
|
772
|
+
.then(() => { }, (error) => {
|
|
773
|
+
const code = error?.code;
|
|
774
|
+
if (code === 'SLOW_CONSUMER')
|
|
775
|
+
return; // Logged where the socket was closed.
|
|
776
|
+
this.#throttle.log(code === 'SOCKET_CLOSED' ? 'warn' : 'error', code === 'SOCKET_CLOSED'
|
|
777
|
+
? 'WebSocket presence dropped; socket closed'
|
|
778
|
+
: 'WebSocket presence handler failed', code === 'SOCKET_CLOSED' ? 'REPLY_DROPPED' : 'PRESENCE_HANDLER_FAILED', error, { connection: session.id });
|
|
779
|
+
})
|
|
780
|
+
.finally(() => {
|
|
781
|
+
value.presencePending--;
|
|
782
|
+
const buffer = value.presenceBuffer;
|
|
783
|
+
if (!buffer)
|
|
784
|
+
return;
|
|
785
|
+
value.presenceBuffer = undefined;
|
|
786
|
+
const open = !value.failed && value.registration && value.socket.readyState === WebSocket.OPEN;
|
|
787
|
+
if (this.context.logger.isEnabled('debug'))
|
|
788
|
+
this.context.logger.log('debug', open ? 'WebSocket merged presence handed over' : 'WebSocket merged presence dropped', {
|
|
789
|
+
connection: session.id,
|
|
790
|
+
joined: buffer.joined.size,
|
|
791
|
+
left: buffer.left.size,
|
|
792
|
+
...(open ? {} : { reason: 'socket closing' }),
|
|
793
|
+
});
|
|
794
|
+
// Everything cancelled out, or the socket is closing: nothing to tell.
|
|
795
|
+
if (!open || (!buffer.joined.size && !buffer.left.size))
|
|
796
|
+
return;
|
|
797
|
+
this.#presenceCall(value, route, session, [...buffer.joined.values()], [...buffer.left.values()]);
|
|
798
|
+
});
|
|
799
|
+
this.#watch(value.tail);
|
|
800
|
+
}
|
|
746
801
|
/** Records of the presence mirror (every server, as the hub reported them) that match. */
|
|
747
802
|
#mirror(filter) {
|
|
748
803
|
const result = [];
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ class WebsocketRuntime {
|
|
|
46
46
|
/** Factory input: `{ app, options? }`. Options default to `app.config['dokebi-websocket']`. */
|
|
47
47
|
export const createPlugin = definePlugin({
|
|
48
48
|
name: 'dokebi-websocket',
|
|
49
|
-
version: '0.4.
|
|
49
|
+
version: '0.4.1',
|
|
50
50
|
core: '^0.4.0',
|
|
51
51
|
options,
|
|
52
52
|
contributes: [realtime],
|
package/dist/options.js
CHANGED
|
@@ -9,7 +9,7 @@ export const options = defineOptions({
|
|
|
9
9
|
maxPayloadBytes: limit(65536, 'Largest incoming frame in bytes.'),
|
|
10
10
|
maxPayload: o.alias('maxPayloadBytes'),
|
|
11
11
|
maxConnections: limit(128, 'Open connections this process accepts at most.'),
|
|
12
|
-
maxPending: limit(32, 'Messages of one connection waiting for its handler at most.'),
|
|
12
|
+
maxPending: limit(32, 'Messages of one connection waiting for its handler at most; its presence calls are bounded by the same number, separately (later changes are merged).'),
|
|
13
13
|
maxPendingMessages: o.alias('maxPending'),
|
|
14
14
|
maxBufferedBytes: limit(1048576, 'Bytes waiting to be sent to one connection at most; a slower client is closed (SLOW_CONSUMER).'),
|
|
15
15
|
shutdownTimeoutMs: limit(2000, 'How long drain waits for closing connections (1012) before it cuts them, in ms.'),
|
package/options.schema.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"minimum": 1,
|
|
30
30
|
"maximum": 67108864,
|
|
31
31
|
"default": 32,
|
|
32
|
-
"description": "Messages of one connection waiting for its handler at most."
|
|
32
|
+
"description": "Messages of one connection waiting for its handler at most; its presence calls are bounded by the same number, separately (later changes are merged)."
|
|
33
33
|
},
|
|
34
34
|
"maxPendingMessages": {
|
|
35
35
|
"type": "integer",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/websocket",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "WebSocket routes on @dokebi/web with rooms and broadcast across servers through @dokebi/websocket-hub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dokebi",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@dokebi/websocket-hub": "^0.4.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@dokebi/web": "0.4.
|
|
49
|
-
"@dokebi/websocket-hub": "0.4.
|
|
48
|
+
"@dokebi/web": "0.4.2",
|
|
49
|
+
"@dokebi/websocket-hub": "0.4.1"
|
|
50
50
|
},
|
|
51
51
|
"dokebi": {
|
|
52
52
|
"schemaVersion": 2,
|