@1presence/bridge 0.72.0 → 0.73.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/dist/index.js +19 -3
- package/dist/timer.js +8 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47,6 +47,10 @@ const PWA_URL = process.env.BRIDGE_PWA_URL ?? GATEWAY_HTTP.replace('://api.', ':
|
|
|
47
47
|
// ─── In-memory state ──────────────────────────────────────────────────────────
|
|
48
48
|
let currentAuth = null;
|
|
49
49
|
let currentWs = null;
|
|
50
|
+
// When the socket first dropped, for reporting how long the bridge was offline
|
|
51
|
+
// once it reconnects. Set on the first disconnect of an outage (repeated failed
|
|
52
|
+
// reconnect attempts don't reset it), cleared on a successful open.
|
|
53
|
+
let disconnectedAt = null;
|
|
50
54
|
// Running cost across all turns this process has handled, for the cost segment
|
|
51
55
|
// of the per-turn status line. On a pure subscription the CLI often reports a
|
|
52
56
|
// per-turn cost of 0, in which case this stays at 0 and reads as "plan usage".
|
|
@@ -629,7 +633,14 @@ function connect(auth, retryDelay = 1000) {
|
|
|
629
633
|
// 4001 refresh-retry budget so a future expiry gets the full allowance.
|
|
630
634
|
authRejections = 0;
|
|
631
635
|
const who = auth.email ? ` as ${auth.email}` : '';
|
|
632
|
-
|
|
636
|
+
if (disconnectedAt !== null) {
|
|
637
|
+
const downFor = formatElapsed(Math.round((Date.now() - disconnectedAt) / 1000));
|
|
638
|
+
disconnectedAt = null;
|
|
639
|
+
console.log(`✓ Bridge reconnected${who} after ${downFor} offline. Local Mode active on all your devices.\n`);
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
console.log(`✓ Bridge connected${who}. Local Mode active on all your devices.\n`);
|
|
643
|
+
}
|
|
633
644
|
startPing();
|
|
634
645
|
// Drain any save records left behind by an earlier crashed/dropped session.
|
|
635
646
|
// Fire-and-forget — the network is up, the gateway is reachable, and we
|
|
@@ -732,9 +743,14 @@ function connect(auth, retryDelay = 1000) {
|
|
|
732
743
|
function scheduleReconnect(closeCode, retryDelay) {
|
|
733
744
|
const authFailure = closeCode === 4001;
|
|
734
745
|
const delay = Math.min(retryDelay, 30_000);
|
|
746
|
+
// Stamp the start of the outage — only on the first drop, so the offline
|
|
747
|
+
// duration reported on reconnect spans failed retry cycles too.
|
|
748
|
+
if (disconnectedAt === null)
|
|
749
|
+
disconnectedAt = Date.now();
|
|
750
|
+
const who = currentAuth?.email ? ` for ${currentAuth.email}` : '';
|
|
735
751
|
console.log(authFailure
|
|
736
|
-
? `Authentication expired (${closeCode}). Refreshing token and reconnecting in ${delay / 1000}s…`
|
|
737
|
-
: `Bridge disconnected (${closeCode}). Reconnecting in ${delay / 1000}s…`);
|
|
752
|
+
? `Authentication expired (${closeCode})${who}. Refreshing token and reconnecting in ${delay / 1000}s…`
|
|
753
|
+
: `Bridge disconnected (${closeCode})${who}. Reconnecting in ${delay / 1000}s…`);
|
|
738
754
|
setTimeout(async () => {
|
|
739
755
|
if (!currentAuth)
|
|
740
756
|
return;
|
package/dist/timer.js
CHANGED
|
@@ -17,9 +17,14 @@ function draw() {
|
|
|
17
17
|
export function formatElapsed(seconds) {
|
|
18
18
|
if (seconds < 60)
|
|
19
19
|
return `${seconds}s`;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (seconds < 3600) {
|
|
21
|
+
const m = Math.floor(seconds / 60);
|
|
22
|
+
const s = seconds % 60;
|
|
23
|
+
return `${m}m ${s.toString().padStart(2, '0')}s`;
|
|
24
|
+
}
|
|
25
|
+
const h = Math.floor(seconds / 3600);
|
|
26
|
+
const m = Math.floor((seconds % 3600) / 60);
|
|
27
|
+
return `${h}h ${m.toString().padStart(2, '0')}m`;
|
|
23
28
|
}
|
|
24
29
|
export function startTurnTimer() {
|
|
25
30
|
if (intervalId !== null)
|