@kumiai/hub-tunnel 0.13.0 → 0.13.2
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/lib/transport.d.ts +2 -0
- package/lib/transport.js +5 -5
- package/package.json +10 -9
package/lib/transport.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TransportType } from '@enkaku/transport';
|
|
2
2
|
import type { StoredMessage } from '@kumiai/hub-protocol';
|
|
3
3
|
import type { EventEmitter } from '@sozai/event';
|
|
4
|
+
import type { Now } from '@sozai/runtime';
|
|
4
5
|
import type { ObservabilityEventListener } from './events.js';
|
|
5
6
|
export type HubReceiveSubscription = AsyncIterable<StoredMessage> & {
|
|
6
7
|
return?: () => void;
|
|
@@ -159,6 +160,7 @@ export type HubTunnelTransportParams = {
|
|
|
159
160
|
/** Topic this transport subscribes to and accepts inbound frames from. */
|
|
160
161
|
receiveTopicID: string;
|
|
161
162
|
inboxCapacity?: number;
|
|
163
|
+
monotonicNow?: Now;
|
|
162
164
|
idleTimeoutMs?: number;
|
|
163
165
|
reconnectTimeoutMs?: number;
|
|
164
166
|
signal?: AbortSignal;
|
package/lib/transport.js
CHANGED
|
@@ -21,7 +21,7 @@ const DEFAULT_INBOX_CAPACITY = 1024;
|
|
|
21
21
|
* the subscribe completes (never before it) so a subscribe that is still in flight at teardown
|
|
22
22
|
* cannot land after — and resurrect — the unsubscribe.
|
|
23
23
|
*/ export function createHubTunnelTransport(params) {
|
|
24
|
-
const { hub, sessionID, localDID, sendTopicID, receiveTopicID, signal, idleTimeoutMs, reconnectTimeoutMs, onEvent, onSessionEnd } = params;
|
|
24
|
+
const { hub, monotonicNow = ()=>performance.now(), sessionID, localDID, sendTopicID, receiveTopicID, signal, idleTimeoutMs, reconnectTimeoutMs, onEvent, onSessionEnd } = params;
|
|
25
25
|
const inboxCapacity = params.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;
|
|
26
26
|
let lockedSessionID = typeof sessionID === 'string' ? sessionID : null;
|
|
27
27
|
let outboundSeq = 0;
|
|
@@ -48,7 +48,7 @@ const DEFAULT_INBOX_CAPACITY = 1024;
|
|
|
48
48
|
let abortHandler;
|
|
49
49
|
let torndown = false;
|
|
50
50
|
let readableController;
|
|
51
|
-
let lastActivity =
|
|
51
|
+
let lastActivity = monotonicNow();
|
|
52
52
|
let idleTimer;
|
|
53
53
|
let reconnectTimer;
|
|
54
54
|
let unsubscribeEvents;
|
|
@@ -133,13 +133,13 @@ const DEFAULT_INBOX_CAPACITY = 1024;
|
|
|
133
133
|
const scheduleIdleTimer = ()=>{
|
|
134
134
|
if (idleTimeoutMs == null || torndown) return;
|
|
135
135
|
clearIdleTimer();
|
|
136
|
-
const elapsed =
|
|
136
|
+
const elapsed = monotonicNow() - lastActivity;
|
|
137
137
|
const remaining = idleTimeoutMs - elapsed;
|
|
138
138
|
const delay = Math.max(remaining, 0);
|
|
139
139
|
idleTimer = setTimeout(()=>{
|
|
140
140
|
idleTimer = undefined;
|
|
141
141
|
if (torndown) return;
|
|
142
|
-
const sinceActivity =
|
|
142
|
+
const sinceActivity = monotonicNow() - lastActivity;
|
|
143
143
|
if (sinceActivity >= idleTimeoutMs) {
|
|
144
144
|
teardown(new TimeoutInterruption({
|
|
145
145
|
message: 'idle timeout'
|
|
@@ -150,7 +150,7 @@ const DEFAULT_INBOX_CAPACITY = 1024;
|
|
|
150
150
|
}, delay);
|
|
151
151
|
};
|
|
152
152
|
const markActivity = ()=>{
|
|
153
|
-
lastActivity =
|
|
153
|
+
lastActivity = monotonicNow();
|
|
154
154
|
};
|
|
155
155
|
// A hub's ack may be synchronous and throw synchronously, before `Promise.resolve` sees it — so
|
|
156
156
|
// the rejection guard alone is not enough (same fix as `ackUpstream` in rpc/src/hub-mux.ts). An
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/hub-tunnel",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Peer-to-peer Enkaku transport tunneled through a hub relay",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"enkaku",
|
|
@@ -26,19 +26,20 @@
|
|
|
26
26
|
"lib/*"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@enkaku/transport": "^0.23.
|
|
30
|
-
"@kumiai/hub-protocol": "^0.13.
|
|
31
|
-
"@sozai/async": "^0.4.
|
|
29
|
+
"@enkaku/transport": "^0.23.3",
|
|
30
|
+
"@kumiai/hub-protocol": "^0.13.2",
|
|
31
|
+
"@sozai/async": "^0.4.4",
|
|
32
32
|
"@sozai/codec": "^0.4.4",
|
|
33
33
|
"@sozai/event": "^0.1.6",
|
|
34
|
+
"@sozai/runtime": "^0.1.1",
|
|
34
35
|
"@sozai/schema": "^0.1.6"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@enkaku/client": "^0.23.
|
|
38
|
-
"@enkaku/protocol": "^0.23.
|
|
39
|
-
"@enkaku/server": "^0.23.
|
|
40
|
-
"@kokuin/token": "^0.7.
|
|
41
|
-
"@kumiai/hub-conformance": "^0.13.
|
|
38
|
+
"@enkaku/client": "^0.23.7",
|
|
39
|
+
"@enkaku/protocol": "^0.23.4",
|
|
40
|
+
"@enkaku/server": "^0.23.4",
|
|
41
|
+
"@kokuin/token": "^0.7.1",
|
|
42
|
+
"@kumiai/hub-conformance": "^0.13.1"
|
|
42
43
|
},
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|