owlservable 0.2.7 → 0.2.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/dashboard.html +6 -2
- package/index.cjs +7 -3
- package/index.js +7 -3
- package/package.json +1 -1
package/dashboard.html
CHANGED
|
@@ -336,10 +336,14 @@ document.getElementById('btn-theme').addEventListener('click',function(){
|
|
|
336
336
|
|
|
337
337
|
function connect(){
|
|
338
338
|
var es=new EventSource('/events');
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
var lastMsg=Date.now(),staleTimer=null;
|
|
340
|
+
staleTimer=setInterval(function(){if(Date.now()-lastMsg>35000){dot.classList.add('off');clearInterval(staleTimer);es.close();setTimeout(connect,1000);}},5000);
|
|
341
|
+
es.addEventListener('open',function(){dot.classList.remove('off');lastMsg=Date.now();});
|
|
342
|
+
es.addEventListener('error',function(){dot.classList.add('off');clearInterval(staleTimer);es.close();setTimeout(connect,2000);});
|
|
341
343
|
es.addEventListener('message',function(e){
|
|
344
|
+
lastMsg=Date.now();
|
|
342
345
|
var msg;try{msg=JSON.parse(e.data);}catch(_){return;}
|
|
346
|
+
if(msg.type==='ping')return;
|
|
343
347
|
if(paused&&(msg.type==='request'||msg.type==='update')){
|
|
344
348
|
pauseBuffer.push(msg);
|
|
345
349
|
btnPause.title='Resume ('+pauseBuffer.length+' buffered)';
|
package/index.cjs
CHANGED
|
@@ -341,7 +341,7 @@ function startDashboard(port) {
|
|
|
341
341
|
|
|
342
342
|
if (urlPath === '/events') {
|
|
343
343
|
try { req.socket.setNoDelay(true) } catch (_) {}
|
|
344
|
-
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' })
|
|
344
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no' })
|
|
345
345
|
const send = d => { try { res.write('data: ' + JSON.stringify(d) + '\n\n') } catch (_) {} }
|
|
346
346
|
send({ type: 'init', requests: getRequests(), save: getSaveInfo() })
|
|
347
347
|
const onReq = r => send({ type: 'request', record: r })
|
|
@@ -352,12 +352,16 @@ function startDashboard(port) {
|
|
|
352
352
|
emitter.on('update', onUpdate)
|
|
353
353
|
emitter.on('saveConfig', onSave)
|
|
354
354
|
emitter.on('reload', onReload)
|
|
355
|
-
|
|
355
|
+
let hb = null
|
|
356
|
+
const cleanup = () => {
|
|
357
|
+
if (hb) { clearInterval(hb); hb = null }
|
|
356
358
|
emitter.off('request', onReq)
|
|
357
359
|
emitter.off('update', onUpdate)
|
|
358
360
|
emitter.off('saveConfig', onSave)
|
|
359
361
|
emitter.off('reload', onReload)
|
|
360
|
-
}
|
|
362
|
+
}
|
|
363
|
+
hb = setInterval(() => { try { res.write('data: {"type":"ping"}\n\n') } catch (_) { cleanup() } }, 15000)
|
|
364
|
+
req.on('close', cleanup)
|
|
361
365
|
return
|
|
362
366
|
}
|
|
363
367
|
|
package/index.js
CHANGED
|
@@ -341,7 +341,7 @@ function startDashboard(port) {
|
|
|
341
341
|
|
|
342
342
|
if (urlPath === '/events') {
|
|
343
343
|
try { req.socket.setNoDelay(true) } catch (_) {}
|
|
344
|
-
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' })
|
|
344
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no' })
|
|
345
345
|
const send = d => { try { res.write('data: ' + JSON.stringify(d) + '\n\n') } catch (_) {} }
|
|
346
346
|
send({ type: 'init', requests: getRequests(), save: getSaveInfo() })
|
|
347
347
|
const onReq = r => send({ type: 'request', record: r })
|
|
@@ -352,12 +352,16 @@ function startDashboard(port) {
|
|
|
352
352
|
emitter.on('update', onUpdate)
|
|
353
353
|
emitter.on('saveConfig', onSave)
|
|
354
354
|
emitter.on('reload', onReload)
|
|
355
|
-
|
|
355
|
+
let hb = null
|
|
356
|
+
const cleanup = () => {
|
|
357
|
+
if (hb) { clearInterval(hb); hb = null }
|
|
356
358
|
emitter.off('request', onReq)
|
|
357
359
|
emitter.off('update', onUpdate)
|
|
358
360
|
emitter.off('saveConfig', onSave)
|
|
359
361
|
emitter.off('reload', onReload)
|
|
360
|
-
}
|
|
362
|
+
}
|
|
363
|
+
hb = setInterval(() => { try { res.write('data: {"type":"ping"}\n\n') } catch (_) { cleanup() } }, 15000)
|
|
364
|
+
req.on('close', cleanup)
|
|
361
365
|
return
|
|
362
366
|
}
|
|
363
367
|
|