easy-server-sent-events
Advanced tools
Comparing version
{ | ||
"name": "easy-server-sent-events", | ||
"version": "1.0.8", | ||
"version": "1.0.10", | ||
"description": "An easy to use Server Side Events library for Node.js + frontend", | ||
@@ -29,2 +29,2 @@ "author": "Thomas Frank <thomas@nodehill.com>", | ||
} | ||
} | ||
} |
12
sse.js
@@ -5,2 +5,4 @@ export default class SSE { | ||
this.listeners = []; | ||
this.timeoutOnError = 200; | ||
this.timeoutMem; | ||
this.restart(endpoint); | ||
@@ -11,7 +13,10 @@ } | ||
this.endPointCalc(endPoint); | ||
if(this.longpolling){} | ||
this.stream && this.stream.close(); | ||
this.stream = new EventSource(this.endPoint); | ||
this.stream.addEventListener('error', () => { | ||
this.addListeners(); | ||
clear(this.timeoutMem); | ||
this.timeoutMem = setTimeout(() => this.addListeners(), this.timeoutOnError); | ||
if (this.timeoutOnError < 10000) { | ||
this.timeoutOnError += 1000; | ||
} | ||
}); | ||
@@ -34,2 +39,3 @@ } | ||
this.stream.addEventListener(x, (event) => { | ||
this.timeoutOnError = 200; | ||
let data = event.data; | ||
@@ -51,3 +57,3 @@ try { data = JSON.parse(data) } catch (e) { } | ||
endPointCalc(endPoint){ | ||
endPointCalc(endPoint) { | ||
this.endPoint = endPoint || this.endPoint || '/api/sse'; | ||
@@ -54,0 +60,0 @@ if (!this.endPoint.includes('browserId=')) { |
11245
2.13%143
4.38%