iosignal 7.0.4 → 7.2.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/README.md +21 -0
- package/dist/browser/esm/io.d.ts +31 -17
- package/dist/browser/esm/io.js +3 -3
- package/dist/browser/esm/io.js.map +1 -1
- package/dist/browser/iife/io.js +3 -3
- package/dist/browser/iife/io.js.map +1 -1
- package/dist/node/iosignal.cjs +124 -75
- package/dist/node/iosignal.d.cts +31 -17
- package/dist/node/iosignal.d.ts +31 -17
- package/dist/node/iosignal.js +124 -75
- package/dist/types/client/IOCore.d.ts +31 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -337,3 +337,24 @@ not run automatically, and some require a separate server or Redis.
|
|
|
337
337
|
## License
|
|
338
338
|
|
|
339
339
|
Package license: MIT.
|
|
340
|
+
|
|
341
|
+
### Server ping and peer ping
|
|
342
|
+
|
|
343
|
+
`io.ping()` sends a protocol PING to the server. The server replies with a
|
|
344
|
+
protocol PONG and the client emits `io.on('pong', () => { ... })`.
|
|
345
|
+
Native WebSocket heartbeat frames remain separate.
|
|
346
|
+
|
|
347
|
+
Peer ping uses ordinary direct signals, with **one TEXT argument** carrying the
|
|
348
|
+
sender CID. An application can opt in to replies as follows:
|
|
349
|
+
|
|
350
|
+
```js
|
|
351
|
+
io.signal(`${targetCid}@ping`, io.cid);
|
|
352
|
+
io.on('@', (tag, senderCid) => {
|
|
353
|
+
if (tag === '@ping') io.signal(`${senderCid}@pong`, io.cid);
|
|
354
|
+
if (tag === '@pong') console.log(`pong (${senderCid})`);
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Peer responses arrive in that same `@` handler with tag `@pong`; they do not
|
|
359
|
+
emit the protocol `pong` event. CLI clients implement replies, and Arduino's
|
|
360
|
+
`peer_ping_pong` example implements them in user code.
|
package/dist/browser/esm/io.d.ts
CHANGED
|
@@ -146,6 +146,12 @@ declare class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
146
146
|
* @type {Map<string, Set<string>>}
|
|
147
147
|
*/
|
|
148
148
|
linkMap: Map<string, Set<string>>;
|
|
149
|
+
/** @private @type {Map<string, Map<string, Set<Function>>>} */
|
|
150
|
+
private _linkHandlers;
|
|
151
|
+
/** @private @type {Set<string>} */
|
|
152
|
+
private _listenTags;
|
|
153
|
+
/** @private @type {Set<string>} */
|
|
154
|
+
private _manualSubscriptions;
|
|
149
155
|
/**
|
|
150
156
|
* Indicates if auto-reconnect is enabled.
|
|
151
157
|
* @type {boolean}
|
|
@@ -323,7 +329,7 @@ declare class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
323
329
|
/**
|
|
324
330
|
* Subscribes to a channel or channels.
|
|
325
331
|
* @param {string} tag - The tag(s) of the channel(s) to subscribe to (comma-separated).
|
|
326
|
-
* @throws {TypeError} If tag is
|
|
332
|
+
* @throws {TypeError} If tag is invalid, exceeds the length limit, or contains a direct-receive subscription.
|
|
327
333
|
*/
|
|
328
334
|
subscribe(tag: string): void;
|
|
329
335
|
/**
|
|
@@ -334,41 +340,49 @@ declare class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
334
340
|
/**
|
|
335
341
|
* Unsubscribes from a channel or channels.
|
|
336
342
|
* @param {string} [tag=""] - The tag(s) of the channel(s) to unsubscribe from (comma-separated). If empty, unsubscribes from all.
|
|
337
|
-
* @throws {TypeError} If tag is
|
|
343
|
+
* @throws {TypeError} If tag is invalid, exceeds the length limit, or contains a direct-receive subscription.
|
|
338
344
|
*/
|
|
339
345
|
unsubscribe(tag?: string): void;
|
|
340
346
|
/**
|
|
341
347
|
* Convenience API for simple clients (for example, CLI tools): register a
|
|
342
|
-
* tag handler once and remember its subscription in channels.
|
|
343
|
-
* connection readiness; the CID-ready flow subscribes on initial connection
|
|
348
|
+
* tag handler once and remember its subscription in channels. For subscription
|
|
349
|
+
* tags, register before connection readiness; the CID-ready flow subscribes on initial connection
|
|
344
350
|
* and again after reconnect, without application-level ready/subscribe code.
|
|
345
351
|
* This does not send a subscription immediately, even if already ready.
|
|
346
352
|
* For precise subscription/send ordering or dynamic subscriptions, use
|
|
347
|
-
* on() with subscribe() in a ready handler instead.
|
|
353
|
+
* on() with subscribe() in a ready handler instead.
|
|
354
|
+
* Direct signals need no subscription: use on/listen('@') for all direct
|
|
355
|
+
* signals, or on/listen('@topic') for an exact topic. Direct handlers can be
|
|
356
|
+
* registered before or after readiness, before the message arrives.
|
|
357
|
+
* Dispatch is synchronous: '@' first, then '@topic' when tag is not '@'.
|
|
358
|
+
* Returning false does not cancel dispatch; a thrown error interrupts it.
|
|
348
359
|
* @param {string} tag - The tag to listen on.
|
|
349
360
|
* @param {Function} handler - The callback function to handle the signal.
|
|
350
361
|
* @throws {TypeError} If tag is not a string, handler is not a function, or tag length is invalid.
|
|
351
362
|
*/
|
|
352
363
|
listen(tag: string, handler: Function): void;
|
|
353
364
|
/**
|
|
354
|
-
*
|
|
355
|
-
* @
|
|
356
|
-
*
|
|
357
|
-
* @param {
|
|
358
|
-
* @
|
|
365
|
+
* Associates handlers with a local component for scoped teardown.
|
|
366
|
+
* Direct tags (@ or @topic) only register local handlers. Other tags also
|
|
367
|
+
* subscribe now and are remembered for reconnection.
|
|
368
|
+
* @param {string} to - The local component identifier, not a server target.
|
|
369
|
+
* @param {string} tag - The exact event tag.
|
|
370
|
+
* @param {Function} handler - The callback receiving (tag, ...args).
|
|
371
|
+
* @throws {TypeError} If the arguments or subscription tags are invalid.
|
|
359
372
|
*/
|
|
360
373
|
link(to: string, tag: string, handler: Function): void;
|
|
361
374
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* @param {string}
|
|
365
|
-
* @
|
|
375
|
+
* Removes only one local component's handlers for a tag. Direct tags never
|
|
376
|
+
* send an unsubscribe. Shared subscriptions and explicit subscriptions remain.
|
|
377
|
+
* @param {string} to - The local component identifier.
|
|
378
|
+
* @param {string} tag - The exact linked tag.
|
|
379
|
+
* @throws {TypeError} If the arguments are invalid.
|
|
366
380
|
*/
|
|
367
381
|
unlink(to: string, tag: string): void;
|
|
368
382
|
/**
|
|
369
|
-
*
|
|
370
|
-
* @param {string} to - The local
|
|
371
|
-
* @throws {TypeError} If
|
|
383
|
+
* Removes this local component's links without removing other listeners.
|
|
384
|
+
* @param {string} to - The local component identifier.
|
|
385
|
+
* @throws {TypeError} If the component identifier is not a string.
|
|
372
386
|
*/
|
|
373
387
|
unlinkAll(to: string): void;
|
|
374
388
|
/**
|