@couch-kit/core 0.9.2 → 0.10.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/CHANGELOG.md +37 -0
- package/dist/index.cjs +22 -8
- package/dist/index.js +4 -0
- package/lib/constants.d.ts +13 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/middleware.d.ts +1 -1
- package/lib/middleware.d.ts.map +1 -1
- package/lib/protocol.d.ts.map +1 -1
- package/lib/reducer.d.ts +2 -2
- package/lib/reducer.d.ts.map +1 -1
- package/lib/replay.d.ts +1 -1
- package/lib/replay.d.ts.map +1 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/constants.ts +16 -3
- package/src/index.ts +6 -6
- package/src/middleware.ts +7 -2
- package/src/reducer.ts +4 -4
- package/src/replay.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @couch-kit/core
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#164](https://github.com/faluciano/react-native-couch-kit/pull/164) [`a157126`](https://github.com/faluciano/react-native-couch-kit/commit/a157126424e4d73dcc7185118d5be0db6719792e) Thanks [@faluciano](https://github.com/faluciano)! - Back the time-sync ping off to 30s once the clock estimate settles
|
|
8
|
+
|
|
9
|
+
`useGameClient`'s clock sync pinged every 5 seconds for the life of the
|
|
10
|
+
connection. It now starts there and doubles to a 30-second ceiling
|
|
11
|
+
(`MAX_SYNC_INTERVAL`), resetting to the fast interval whenever a new socket is
|
|
12
|
+
established, including after a reconnect.
|
|
13
|
+
|
|
14
|
+
The first few pings are what converge the offset; the clock difference they
|
|
15
|
+
measure does not drift on a human timescale, so the fast interval stops earning
|
|
16
|
+
its cost within about a minute. On a relay transport it is not free: each ping
|
|
17
|
+
is a message in and a `PONG` back out, and pings are the only traffic an idle
|
|
18
|
+
table generates at all. A four-player lobby went from 5,760 relay messages an
|
|
19
|
+
hour to under 1,000 while sitting untouched.
|
|
20
|
+
|
|
21
|
+
`rtt` and `getServerTime()` are unchanged in accuracy — both are updated by the
|
|
22
|
+
same `PONG` handling as before, just less often once settled. Games needing the
|
|
23
|
+
old cadence can dispatch their own pings; the constants
|
|
24
|
+
(`DEFAULT_SYNC_INTERVAL`, `MAX_SYNC_INTERVAL`, `SYNC_BACKOFF_FACTOR`) are
|
|
25
|
+
exported from `@couch-kit/core`.
|
|
26
|
+
|
|
27
|
+
## 0.9.3
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#122](https://github.com/faluciano/react-native-couch-kit/pull/122) [`ec8a0ae`](https://github.com/faluciano/react-native-couch-kit/commit/ec8a0ae2626fce135d553e88eca1f0ad59d54e2d) Thanks [@faluciano](https://github.com/faluciano)! - Extract the authoritative game state, sessions, authorization, rate limiting,
|
|
32
|
+
and broadcast scheduling into a transport-neutral runtime package. The React
|
|
33
|
+
Native host now adapts its existing HTTP and WebSocket servers to that runtime
|
|
34
|
+
without changing the public `GameHostProvider` API.
|
|
35
|
+
|
|
36
|
+
The core ESM package metadata and declaration imports are also made compatible
|
|
37
|
+
with Node's ESM and `NodeNext` resolution so the runtime can be consumed from
|
|
38
|
+
supported Node versions.
|
|
39
|
+
|
|
3
40
|
## 0.9.2
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -39,7 +49,9 @@ __export(exports_src, {
|
|
|
39
49
|
applyMiddleware: () => applyMiddleware,
|
|
40
50
|
actionValidator: () => actionValidator,
|
|
41
51
|
actionLogger: () => actionLogger,
|
|
52
|
+
SYNC_BACKOFF_FACTOR: () => SYNC_BACKOFF_FACTOR,
|
|
42
53
|
MessageTypes: () => MessageTypes,
|
|
54
|
+
MAX_SYNC_INTERVAL: () => MAX_SYNC_INTERVAL,
|
|
43
55
|
MAX_PENDING_PINGS: () => MAX_PENDING_PINGS,
|
|
44
56
|
MAX_FRAME_SIZE: () => MAX_FRAME_SIZE,
|
|
45
57
|
KEEPALIVE_TIMEOUT: () => KEEPALIVE_TIMEOUT,
|
|
@@ -368,6 +380,8 @@ var DEFAULT_MAX_RETRIES = 5;
|
|
|
368
380
|
var DEFAULT_BASE_DELAY = 1000;
|
|
369
381
|
var DEFAULT_MAX_DELAY = 1e4;
|
|
370
382
|
var DEFAULT_SYNC_INTERVAL = 5000;
|
|
383
|
+
var MAX_SYNC_INTERVAL = 30000;
|
|
384
|
+
var SYNC_BACKOFF_FACTOR = 2;
|
|
371
385
|
var MAX_PENDING_PINGS = 50;
|
|
372
386
|
var DEFAULT_DISCONNECT_TIMEOUT = 5 * 60 * 1000;
|
|
373
387
|
var KEEPALIVE_INTERVAL = 30000;
|
package/dist/index.js
CHANGED
|
@@ -310,6 +310,8 @@ var DEFAULT_MAX_RETRIES = 5;
|
|
|
310
310
|
var DEFAULT_BASE_DELAY = 1000;
|
|
311
311
|
var DEFAULT_MAX_DELAY = 1e4;
|
|
312
312
|
var DEFAULT_SYNC_INTERVAL = 5000;
|
|
313
|
+
var MAX_SYNC_INTERVAL = 30000;
|
|
314
|
+
var SYNC_BACKOFF_FACTOR = 2;
|
|
313
315
|
var MAX_PENDING_PINGS = 50;
|
|
314
316
|
var DEFAULT_DISCONNECT_TIMEOUT = 5 * 60 * 1000;
|
|
315
317
|
var KEEPALIVE_INTERVAL = 30000;
|
|
@@ -380,7 +382,9 @@ export {
|
|
|
380
382
|
applyMiddleware,
|
|
381
383
|
actionValidator,
|
|
382
384
|
actionLogger,
|
|
385
|
+
SYNC_BACKOFF_FACTOR,
|
|
383
386
|
MessageTypes,
|
|
387
|
+
MAX_SYNC_INTERVAL,
|
|
384
388
|
MAX_PENDING_PINGS,
|
|
385
389
|
MAX_FRAME_SIZE,
|
|
386
390
|
KEEPALIVE_TIMEOUT,
|
package/lib/constants.d.ts
CHANGED
|
@@ -13,8 +13,20 @@ export declare const DEFAULT_MAX_RETRIES = 5;
|
|
|
13
13
|
export declare const DEFAULT_BASE_DELAY = 1000;
|
|
14
14
|
/** Default maximum delay (ms) cap for reconnection backoff. */
|
|
15
15
|
export declare const DEFAULT_MAX_DELAY = 10000;
|
|
16
|
-
/** Default time sync ping interval (ms). */
|
|
16
|
+
/** Default time sync ping interval (ms) — the interval a fresh socket starts at. */
|
|
17
17
|
export declare const DEFAULT_SYNC_INTERVAL = 5000;
|
|
18
|
+
/**
|
|
19
|
+
* Ceiling (ms) the time-sync interval backs off to once the clock estimate has
|
|
20
|
+
* settled.
|
|
21
|
+
*
|
|
22
|
+
* Pings are the only traffic an idle table generates, and on a relay transport
|
|
23
|
+
* every one of them is a billed message for the ping *and* the host's pong. The
|
|
24
|
+
* offset they measure is a clock difference that does not drift on a human
|
|
25
|
+
* timescale, so the fast interval only earns its cost right after connecting.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_SYNC_INTERVAL = 30000;
|
|
28
|
+
/** Multiplier applied to the time-sync interval after each ping, up to {@link MAX_SYNC_INTERVAL}. */
|
|
29
|
+
export declare const SYNC_BACKOFF_FACTOR = 2;
|
|
18
30
|
/** Maximum number of outstanding pings before cleanup. */
|
|
19
31
|
export declare const MAX_PENDING_PINGS = 50;
|
|
20
32
|
/** Default timeout (ms) before a disconnected player is removed from state. */
|
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAIxD,oDAAoD;AACpD,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,0DAA0D;AAC1D,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,8FAA8F;AAC9F,eAAO,MAAM,cAAc,QAAc,CAAC;AAE1C,4DAA4D;AAC5D,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,oFAAoF;AACpF,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,+EAA+E;AAC/E,eAAO,MAAM,0BAA0B,QAAgB,CAAC;AAExD,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAwBnC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBpE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGrD"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./reducer";
|
|
3
|
-
export * from "./protocol";
|
|
4
|
-
export * from "./constants";
|
|
5
|
-
export * from "./replay";
|
|
6
|
-
export * from "./middleware";
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./reducer.js";
|
|
3
|
+
export * from "./protocol.js";
|
|
4
|
+
export * from "./constants.js";
|
|
5
|
+
export * from "./replay.js";
|
|
6
|
+
export * from "./middleware.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
package/lib/middleware.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IGameState, IAction, InternalAction, GameReducer } from "./types";
|
|
1
|
+
import type { IGameState, IAction, InternalAction, GameReducer } from "./types.js";
|
|
2
2
|
/** The API surface available to each middleware. */
|
|
3
3
|
export interface MiddlewareAPI<S extends IGameState> {
|
|
4
4
|
getState: () => S;
|
package/lib/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAC;AAOpB,oDAAoD;AACpD,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU;IACjD,QAAQ,EAAE,MAAM,CAAC,CAAC;CACnB;AAED,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,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;IACrB,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CACrE,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CACpE,GACD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAElE,eAAO,MAAM,YAAY;aAEvB,IAAI,EAAE,MAAM;aACZ,MAAM,EAAE,QAAQ;aAChB,IAAI,EAAE,MAAM;aACZ,aAAa,EAAE,eAAe;aAG9B,OAAO,EAAE,SAAS;aAClB,YAAY,EAAE,cAAc;aAC5B,IAAI,EAAE,MAAM;aACZ,WAAW,EAAE,aAAa;aAC1B,KAAK,EAAE,OAAO;CACN,CAAC"}
|
package/lib/reducer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Middleware } from "./middleware";
|
|
2
|
-
import type { IGameState, IAction, InternalAction, GameReducer } from "./types";
|
|
1
|
+
import type { Middleware } from "./middleware.js";
|
|
2
|
+
import type { IGameState, IAction, InternalAction, GameReducer } from "./types.js";
|
|
3
3
|
/** Options for `createGameReducer`. */
|
|
4
4
|
export interface CreateGameReducerOptions<S extends IGameState, A extends IAction> {
|
|
5
5
|
/**
|
package/lib/reducer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EACV,UAAU,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB,uCAAuC;AACvC,MAAM,WAAW,wBAAwB,CACvC,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,OAAO;IAEjB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;CACjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,EACvE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAC1B,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GACvC,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAgFvC"}
|
package/lib/replay.d.ts
CHANGED
package/lib/replay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,MAAM,EAAE,C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BAAmB;aAClC,WAAW,EAAE,iBAAiB;aAC9B,kBAAkB,EAAE,wBAAwB;aAC5C,cAAc,EAAE,oBAAoB;CAC5B,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,OAAO,IAAI,CACjE,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,CAAC,KACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@couch-kit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
7
7
|
},
|
|
8
8
|
"description": "Shared types, protocol, and game reducer for Couch Kit party games",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
10
11
|
"engines": {
|
|
11
12
|
"node": ">=18.0.0"
|
|
12
13
|
},
|
|
@@ -45,11 +46,10 @@
|
|
|
45
46
|
"build": "bun build ./src/index.ts --outdir ./dist --target browser && bun build ./src/index.ts --outfile ./dist/index.cjs --target browser --format cjs && tsc -p tsconfig.build.json",
|
|
46
47
|
"prepublishOnly": "bun run build",
|
|
47
48
|
"test": "bun test",
|
|
48
|
-
"lint": "eslint src/",
|
|
49
49
|
"typecheck": "tsc --noEmit",
|
|
50
50
|
"clean": "rm -rf dist lib"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"typescript": "^
|
|
53
|
+
"typescript": "^7.0.0"
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** Shared constants for Couch Kit protocol defaults. */
|
|
2
2
|
|
|
3
|
-
import { sha256Hex } from "./sha256";
|
|
4
|
-
|
|
3
|
+
import { sha256Hex } from "./sha256.js";
|
|
5
4
|
|
|
6
5
|
/** Default HTTP port for the static file server. */
|
|
7
6
|
export const DEFAULT_HTTP_PORT = 8080;
|
|
@@ -24,9 +23,23 @@ export const DEFAULT_BASE_DELAY = 1000;
|
|
|
24
23
|
/** Default maximum delay (ms) cap for reconnection backoff. */
|
|
25
24
|
export const DEFAULT_MAX_DELAY = 10000;
|
|
26
25
|
|
|
27
|
-
/** Default time sync ping interval (ms). */
|
|
26
|
+
/** Default time sync ping interval (ms) — the interval a fresh socket starts at. */
|
|
28
27
|
export const DEFAULT_SYNC_INTERVAL = 5000;
|
|
29
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Ceiling (ms) the time-sync interval backs off to once the clock estimate has
|
|
31
|
+
* settled.
|
|
32
|
+
*
|
|
33
|
+
* Pings are the only traffic an idle table generates, and on a relay transport
|
|
34
|
+
* every one of them is a billed message for the ping *and* the host's pong. The
|
|
35
|
+
* offset they measure is a clock difference that does not drift on a human
|
|
36
|
+
* timescale, so the fast interval only earns its cost right after connecting.
|
|
37
|
+
*/
|
|
38
|
+
export const MAX_SYNC_INTERVAL = 30000;
|
|
39
|
+
|
|
40
|
+
/** Multiplier applied to the time-sync interval after each ping, up to {@link MAX_SYNC_INTERVAL}. */
|
|
41
|
+
export const SYNC_BACKOFF_FACTOR = 2;
|
|
42
|
+
|
|
30
43
|
/** Maximum number of outstanding pings before cleanup. */
|
|
31
44
|
export const MAX_PENDING_PINGS = 50;
|
|
32
45
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./reducer";
|
|
3
|
-
export * from "./protocol";
|
|
4
|
-
export * from "./constants";
|
|
5
|
-
export * from "./replay";
|
|
6
|
-
export * from "./middleware";
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./reducer.js";
|
|
3
|
+
export * from "./protocol.js";
|
|
4
|
+
export * from "./constants.js";
|
|
5
|
+
export * from "./replay.js";
|
|
6
|
+
export * from "./middleware.js";
|
package/src/middleware.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
IGameState,
|
|
3
|
+
IAction,
|
|
4
|
+
InternalAction,
|
|
5
|
+
GameReducer,
|
|
6
|
+
} from "./types.js";
|
|
7
|
+
import { InternalActionTypes } from "./types.js";
|
|
3
8
|
|
|
4
9
|
// ---------------------------------------------------------------------------
|
|
5
10
|
// Middleware types
|
package/src/reducer.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { applyMiddleware } from "./middleware";
|
|
2
|
-
import type { Middleware } from "./middleware";
|
|
3
|
-
import { InternalActionTypes } from "./types";
|
|
1
|
+
import { applyMiddleware } from "./middleware.js";
|
|
2
|
+
import type { Middleware } from "./middleware.js";
|
|
3
|
+
import { InternalActionTypes } from "./types.js";
|
|
4
4
|
import type {
|
|
5
5
|
IGameState,
|
|
6
6
|
IAction,
|
|
7
7
|
InternalAction,
|
|
8
8
|
GameReducer,
|
|
9
|
-
} from "./types";
|
|
9
|
+
} from "./types.js";
|
|
10
10
|
|
|
11
11
|
/** Options for `createGameReducer`. */
|
|
12
12
|
export interface CreateGameReducerOptions<
|
package/src/replay.ts
CHANGED