@ddtcorex/dsh-maestro-supervisor 0.6.1 → 0.6.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/client.js +14 -10
- package/lib/types/client/auto-reload.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -46,11 +46,13 @@ function apply(ctx) {
|
|
|
46
46
|
};
|
|
47
47
|
const onOffline = () => startPolling();
|
|
48
48
|
const onOnline = () => {
|
|
49
|
+
const wasPolling = !!timer;
|
|
49
50
|
stopPolling();
|
|
50
|
-
|
|
51
|
+
if (wasPolling)
|
|
52
|
+
void checkAndReload();
|
|
51
53
|
};
|
|
52
|
-
// DSH Web uses WebSocket for sessions; a close
|
|
53
|
-
//
|
|
54
|
+
// DSH Web uses WebSocket for sessions; a close does NOT necessarily mean server down
|
|
55
|
+
// (normal session end also closes WS). Only start polling if HEAD fetch actually fails.
|
|
54
56
|
const OriginalWebSocket = window.WebSocket;
|
|
55
57
|
let wsCloseHandler = null;
|
|
56
58
|
try {
|
|
@@ -58,15 +60,17 @@ function apply(ctx) {
|
|
|
58
60
|
const Patched = function (url, protocols) {
|
|
59
61
|
const ws = protocols ? new OriginalWebSocket(url, protocols) : new OriginalWebSocket(url);
|
|
60
62
|
ws.addEventListener('close', () => {
|
|
61
|
-
// Only treat DSH WebSocket closes (same origin) as server-down
|
|
62
63
|
try {
|
|
63
64
|
const u = new URL(url, window.location.href);
|
|
64
|
-
if (u.host
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
startPolling();
|
|
65
|
+
if (u.host !== window.location.host)
|
|
66
|
+
return;
|
|
69
67
|
}
|
|
68
|
+
catch { /* ignore */ }
|
|
69
|
+
// Verify server is actually down before polling — avoid reload on normal WS close
|
|
70
|
+
fetch('/', { method: 'HEAD', cache: 'no-store' }).then(res => {
|
|
71
|
+
if (!res.ok)
|
|
72
|
+
startPolling();
|
|
73
|
+
}).catch(() => startPolling());
|
|
70
74
|
});
|
|
71
75
|
ws.addEventListener('open', () => {
|
|
72
76
|
// If we were polling and WS reopens, check immediately
|
|
@@ -85,7 +89,7 @@ function apply(ctx) {
|
|
|
85
89
|
window.addEventListener('offline', onOffline);
|
|
86
90
|
window.addEventListener('online', onOnline);
|
|
87
91
|
document.addEventListener('visibilitychange', () => {
|
|
88
|
-
if (document.visibilityState === 'visible')
|
|
92
|
+
if (document.visibilityState === 'visible' && timer)
|
|
89
93
|
void checkAndReload();
|
|
90
94
|
});
|
|
91
95
|
// Host push: POST /dsh-maestro-supervisor-reload/reload (loopback) -> reload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-reload.d.ts","sourceRoot":"","sources":["../../../src/client/auto-reload.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"auto-reload.d.ts","sourceRoot":"","sources":["../../../src/client/auto-reload.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAgGpC"}
|
package/package.json
CHANGED