aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/sw.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/sw.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/sw.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/sw.js b/packages/meshbay-hub/src/meshbay_hub/static/sw.js
index 309ecc1..5f663f9 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/sw.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/sw.js
@@ -89,6 +89,21 @@ self.addEventListener('message', (event) => {
// stream and the page's first write blocks for good.
port: data.port || null,
});
+ // Say so, on the port the page is already listening to.
+ //
+ // `pending` is in memory, and a worker with nothing to do is terminated:
+ // Chrome after tens of seconds, which a long upload spends without giving
+ // this worker a single event. A stream posted to a worker in that state is
+ // lost, the iframe then wakes it with no entry to find, and the request falls
+ // through to the network — measured as a 404 from the hub and thirty seconds
+ // of nothing, twice, before the download started at all.
+ //
+ // The page waits for this before navigating, so the entry is known to be here
+ // rather than hoped to be. A page talking to an older worker gets no answer
+ // and navigates anyway, which is what it did before.
+ if (data.port) {
+ try { data.port.postMessage({ type: 'mbdl-ready', id: data.id }); } catch { /* gone */ }
+ }
// A tab that is closed before it navigates would leave a stream here for the
// life of the worker.
setTimeout(() => pending.delete(data.id), 60000);