channel-js: ensure lastEventId is an integer, and correctly set lastAckedEvent

This commit is contained in:
Logan Allen 2021-01-11 23:07:53 +00:00
parent 5dd29f1fe7
commit 3611fcab16

View File

@ -63,7 +63,7 @@ class Channel {
} }
resetDebounceTimer() { resetDebounceTimer() {
if(this.debounceTimer) { if (this.debounceTimer) {
clearTimeout(this.debounceTimer); clearTimeout(this.debounceTimer);
this.debounceTimer = null; this.debounceTimer = null;
} }
@ -203,7 +203,7 @@ class Channel {
// //
let payload = [ let payload = [
...this.outstandingJSON, ...this.outstandingJSON,
{action: "ack", "event-id": parseInt(this.lastEventId)} {action: "ack", "event-id": this.lastEventId}
]; ];
if (j) { if (j) {
payload.push(j) payload.push(j)
@ -211,7 +211,7 @@ class Channel {
let x = JSON.stringify(payload); let x = JSON.stringify(payload);
req.send(x); req.send(x);
this.lastEventId = this.lastAcknowledgedEventId; this.lastAcknowledgedEventId = this.lastEventId;
} }
this.outstandingJSON = []; this.outstandingJSON = [];
@ -227,7 +227,7 @@ class Channel {
this.eventSource = new EventSource(this.channelURL(), {withCredentials:true}); this.eventSource = new EventSource(this.channelURL(), {withCredentials:true});
this.eventSource.onmessage = e => { this.eventSource.onmessage = e => {
this.lastEventId = e.lastEventId; this.lastEventId = parseInt(e.lastEventId, 10);
let obj = JSON.parse(e.data); let obj = JSON.parse(e.data);
let pokeFuncs = this.outstandingPokes.get(obj.id); let pokeFuncs = this.outstandingPokes.get(obj.id);