@hadoku/rooms-server 0.45.64 → 0.45.65
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/presence.d.ts +11 -4
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +9 -2
- package/package.json +3 -3
package/dist/presence.d.ts
CHANGED
|
@@ -63,11 +63,16 @@ export type PresenceEvent<K extends string = string> =
|
|
|
63
63
|
lastSeen: number;
|
|
64
64
|
};
|
|
65
65
|
export type PresenceListener<K extends string = string> = (event: PresenceEvent<K>) => void;
|
|
66
|
-
export interface PresenceOptions {
|
|
66
|
+
export interface PresenceOptions<K extends string = string> {
|
|
67
67
|
/** A connection with no heartbeat for this long is dropped (`idle`). */
|
|
68
68
|
idleMs: number;
|
|
69
|
-
/**
|
|
70
|
-
|
|
69
|
+
/**
|
|
70
|
+
* A person offline this long has left (`left`). 0 decides on the next timer
|
|
71
|
+
* tick. A function gives each key its own grace (one tracker holding a
|
|
72
|
+
* lobby's seats and a draft pod's, say); it is read when that key goes
|
|
73
|
+
* offline, which is when the timer is armed.
|
|
74
|
+
*/
|
|
75
|
+
graceMs: number | ((key: K) => number);
|
|
71
76
|
/** Clock. Defaults to `Date.now`. */
|
|
72
77
|
now?: () => number;
|
|
73
78
|
/** One-shot timer. Defaults to `setTimeout`; injectable for tests and non-Node hosts. */
|
|
@@ -84,7 +89,7 @@ export declare class PresenceTracker<K extends string = string> {
|
|
|
84
89
|
private readonly people;
|
|
85
90
|
private readonly conns;
|
|
86
91
|
private readonly listeners;
|
|
87
|
-
constructor(opts: PresenceOptions);
|
|
92
|
+
constructor(opts: PresenceOptions<K>);
|
|
88
93
|
/** Subscribe. Returns the unsubscribe. Listeners run synchronously, in order. */
|
|
89
94
|
on(listener: PresenceListener<K>): () => void;
|
|
90
95
|
/**
|
|
@@ -115,6 +120,8 @@ export declare class PresenceTracker<K extends string = string> {
|
|
|
115
120
|
forget(key: K): void;
|
|
116
121
|
/** Cancel every timer and forget everyone, with no events. For shutdown and room deletion. */
|
|
117
122
|
dispose(): void;
|
|
123
|
+
/** The key's grace. A function's bad answer (negative, NaN) is 0: decide on the next tick, never never. */
|
|
124
|
+
private graceFor;
|
|
118
125
|
private armIdle;
|
|
119
126
|
private reapIdle;
|
|
120
127
|
private drop;
|
package/dist/presence.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../src/presence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,oEAAoE;AACpE,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;AACjD,gGAAgG;AAC9F;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,CAAC,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE;AAC3D,oEAAoE;GAClE;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,CAAC,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AACzC,gGAAgG;GAC9F;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,CAAC,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE;AAC9E;;;GAGG;GACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,CAAC,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAE5F,MAAM,WAAW,eAAe;
|
|
1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AA4D;IAC5D,KAAK,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAI1C,uCAAuC;IACvC,MAAM,IAAI,CAAC,EAAE;IAIb;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAYpB,8FAA8F;IAC9F,OAAO,IAAI,IAAI;IAIf,2GAA2G;IAC3G,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,IAAI;IAkBZ,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,IAAI;CAGb"}
|
package/dist/presence.js
CHANGED
|
@@ -40,7 +40,7 @@ export class PresenceTracker {
|
|
|
40
40
|
constructor(opts) {
|
|
41
41
|
if (!(opts.idleMs > 0))
|
|
42
42
|
throw new RangeError(`idleMs must be > 0, got ${opts.idleMs}`);
|
|
43
|
-
if (!(opts.graceMs >= 0))
|
|
43
|
+
if (typeof opts.graceMs !== 'function' && !(opts.graceMs >= 0))
|
|
44
44
|
throw new RangeError(`graceMs must be >= 0, got ${opts.graceMs}`);
|
|
45
45
|
this.idleMs = opts.idleMs;
|
|
46
46
|
this.graceMs = opts.graceMs;
|
|
@@ -149,6 +149,13 @@ export class PresenceTracker {
|
|
|
149
149
|
for (const key of [...this.people.keys()])
|
|
150
150
|
this.forget(key);
|
|
151
151
|
}
|
|
152
|
+
/** The key's grace. A function's bad answer (negative, NaN) is 0: decide on the next tick, never never. */
|
|
153
|
+
graceFor(key) {
|
|
154
|
+
if (typeof this.graceMs !== 'function')
|
|
155
|
+
return this.graceMs;
|
|
156
|
+
const ms = this.graceMs(key);
|
|
157
|
+
return Number.isFinite(ms) && ms > 0 ? ms : 0;
|
|
158
|
+
}
|
|
152
159
|
armIdle(connectionId) {
|
|
153
160
|
return this.setTimer(() => this.reapIdle(connectionId), this.idleMs);
|
|
154
161
|
}
|
|
@@ -179,7 +186,7 @@ export class PresenceTracker {
|
|
|
179
186
|
// A listener may have reconnected or forgotten them synchronously.
|
|
180
187
|
if (this.people.get(key) !== person || person.offlineSince !== at || person.connections.size > 0)
|
|
181
188
|
return;
|
|
182
|
-
person.graceTimer = this.setTimer(() => this.leave(key, person), this.
|
|
189
|
+
person.graceTimer = this.setTimer(() => this.leave(key, person), this.graceFor(key));
|
|
183
190
|
}
|
|
184
191
|
leave(key, person) {
|
|
185
192
|
if (this.people.get(key) !== person || person.offlineSince === undefined)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/rooms-server",
|
|
3
|
-
"version": "0.45.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.45.65",
|
|
4
|
+
"gitHead": "90ff6d04cecd05839a738fe0e07422535d7322ce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Room lifecycle, membership, seating, identity, presence, backpressure-aware emit and durable room storage for a socket.io server.",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"directory": "packages/rooms-server"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@0.45.
|
|
38
|
+
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@0.45.65"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"socket.io": "^4.8.3"
|