aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/transport.js
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-09-19 17:13:17 +0200
committerChristophe Besson <cbesson@gmail.com>2026-09-19 17:13:17 +0200
commit2eaf6887295614509f8d0bc24a9b77ccd915ef88 (patch)
treec713fec411770da9250a44f9b1e08c4165c8d439 /packages/meshbay-hub/src/meshbay_hub/static/transport.js
parentd2495a2c4b89fbbfc18cefec83ae96cabdd745e2 (diff)
downloadmeshbay-2eaf6887295614509f8d0bc24a9b77ccd915ef88.tar.gz
fix(hub): a reconnect re-reads the index, not just the handshake
_reconnectLoop re-did the handshake and nothing else, so a page kept whatever it last saw until someone reloaded it. That is invisible until the node restarts: it rebuilds its index from index_cache.db, which holds no enrichment, and Music is the one app whose enrichment is persisted nowhere — for the length of the re-read pass it serves tracks with no artist, and the album grid drew nothing. onReconnected was one slot the video player took on open and cleared on close; it is a listener set now, and carries the fresh ack. docs/MESHBAY_DESIGN.md §15.3 records the two defects found alongside and not fixed here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transport.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/transport.js42
1 files changed, 31 insertions, 11 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
index f4979f4..39e0ccf 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
@@ -487,7 +487,12 @@ class MeshBayTransport {
// "a reconnect to wait for" and stall every handshake step for the full
// 6s gate below before ever sending it.
this._inReconnectAttempt = false;
- this._onReconnected = null;
+ // A set, not one slot. Two consumers want this at once — the video
+ // player, to re-ask for the stream it was watching, and the group
+ // page, to re-read an index the node rebuilt while we were away —
+ // and a single setter meant the second to arrive silently replaced
+ // the first, then cleared it on the way out.
+ this._reconnectListeners = new Set();
this._onNeedToken = null;
// Which device key THIS connection has identified itself to the node with.
// Empty means "not identified": nothing can be sealed, so nothing can be
@@ -548,10 +553,19 @@ class MeshBayTransport {
// Fired when a message that must open under the group key does not —
// see _failSession. The session is over by the time this runs.
set onSessionFailed(fn) { this._onSessionFailed = fn; }
- // Fired once an automatic reconnect (see _reconnectLoop) lands a fresh
- // handshake, so a consumer with something mid-flight on the old channel —
- // today only the video player — can pick back up rather than sit dead.
- set onReconnected(fn) { this._onReconnected = fn; }
+ /**
+ * Told once an automatic reconnect (see _reconnectLoop) lands a fresh
+ * handshake, with that handshake's ack.
+ *
+ * Returns its own unsubscribe, because the caller that stops listening
+ * must not be able to stop anyone else listening: `onReconnected` was a
+ * setter, the video player took it on open and set it back to `null` on
+ * close, and any other consumer's handler went with it.
+ */
+ addReconnectListener(fn) {
+ this._reconnectListeners.add(fn);
+ return () => this._reconnectListeners.delete(fn);
+ }
/**
* Told whenever this connection's device identity changes — including to
@@ -1213,10 +1227,11 @@ class MeshBayTransport {
const token = this._onNeedToken ? await this._onNeedToken() : this._lastToken;
trace('reconnect_attempt', { attempt: this._reconnectAttempts });
this._inReconnectAttempt = true;
+ let ack;
try {
- await this.connect(args.nodeId, token, args.groupId, args.gekRaw,
- this._sessionKeys, args.bundleKey, args.username,
- args.userId, args.joinCode);
+ ack = await this.connect(args.nodeId, token, args.groupId, args.gekRaw,
+ this._sessionKeys, args.bundleKey, args.username,
+ args.userId, args.joinCode);
} finally {
this._inReconnectAttempt = false;
}
@@ -1226,9 +1241,14 @@ class MeshBayTransport {
// have asked for its slot back first, or its next `file_req` carries a
// `tr` the node has never heard of.
this._reopenTransfers();
- if (this._onReconnected) {
- try { this._onReconnected(); } catch (e) {
- console.error('[MeshBay] onReconnected handler threw:', e);
+ // The ack goes with it: this is a *new* session against whatever the
+ // node is running now, and everything the first handshake taught the
+ // page — the folders each app reads, which apps are on, the roots —
+ // was answered by a process that may since have restarted. One
+ // listener throwing must not rob the next of the notification.
+ for (const fn of [...this._reconnectListeners]) {
+ try { fn(ack); } catch (e) {
+ console.error('[MeshBay] reconnect listener threw:', e);
}
}
return;