tw-framework 1.0.7 → 1.0.9
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/hydration-runtime.js +19 -3
- package/dist/testing.cjs +1059 -284
- package/dist/tw-server.mjs +56210 -0
- package/dist/tw.mjs +1392 -361
- package/package.json +7 -2
|
@@ -495,28 +495,44 @@
|
|
|
495
495
|
}
|
|
496
496
|
|
|
497
497
|
var es = null;
|
|
498
|
+
// v2: exponential backoff reconnect -- 1s, 2s, 4s, 8s, cap 10s.
|
|
499
|
+
// Every successfully applied frame resets the delay, so a healthy
|
|
500
|
+
// connection never grows its retry window; a dead server stops the
|
|
501
|
+
// client from hammering it every 1.5s forever.
|
|
502
|
+
var backoffMs = 1000, reconnectTimer = null;
|
|
498
503
|
function open() {
|
|
504
|
+
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
|
|
499
505
|
es = new EventSource(
|
|
500
506
|
"/_tw/stream?s=" + encodeURIComponent(names.join(",")) + "&since=" + lastSeq
|
|
501
507
|
);
|
|
502
508
|
es.onmessage = function (ev) {
|
|
503
|
-
try {
|
|
509
|
+
try {
|
|
510
|
+
apply(JSON.parse(ev.data));
|
|
511
|
+
backoffMs = 1000; // healthy frame -> reset the backoff
|
|
512
|
+
} catch (e) { /* malformed frame */ }
|
|
504
513
|
};
|
|
505
514
|
es.onerror = function () {
|
|
506
515
|
// EventSource retries on its own, but with the original URL; close
|
|
507
516
|
// and reopen so the connection resumes from lastSeq.
|
|
508
517
|
try { es.close(); } catch (e) { /* already closed */ }
|
|
509
|
-
|
|
518
|
+
es = null;
|
|
519
|
+
reconnectTimer = setTimeout(open, backoffMs);
|
|
520
|
+
backoffMs = Math.min(backoffMs * 2, 10000);
|
|
510
521
|
};
|
|
511
522
|
}
|
|
512
523
|
open();
|
|
513
524
|
activeStream = {
|
|
514
525
|
close: function () {
|
|
526
|
+
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
|
|
515
527
|
try { es.close(); } catch (e) { /* already closed */ }
|
|
516
528
|
activeStream = null;
|
|
517
529
|
},
|
|
518
530
|
};
|
|
519
|
-
window.__tw.signalStream = {
|
|
531
|
+
window.__tw.signalStream = {
|
|
532
|
+
reconnect: open,
|
|
533
|
+
lastSeq: function () { return lastSeq; },
|
|
534
|
+
backoffMs: function () { return backoffMs; },
|
|
535
|
+
};
|
|
520
536
|
}
|
|
521
537
|
|
|
522
538
|
// expose for debugging / userland
|