channel.js: ack every 30 events *even if this.outstandingJSON is empty*

This commit is contained in:
Logan Allen 2021-01-11 15:13:48 -06:00
parent 85435e9a81
commit 5dd29f1fe7

View File

@ -182,19 +182,19 @@ class Channel {
// sends a JSON command command to the server. // sends a JSON command command to the server.
// //
sendJSONToChannel(j) { sendJSONToChannel(j) {
if(!j && this.outstandingJSON.length === 0) {
return;
}
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.open("PUT", this.channelURL()); req.open("PUT", this.channelURL());
req.setRequestHeader("Content-Type", "application/json"); req.setRequestHeader("Content-Type", "application/json");
if (this.lastEventId == this.lastAcknowledgedEventId) { if (this.lastEventId == this.lastAcknowledgedEventId) {
if(j) { if (j) {
this.outstandingJSON.push(j); this.outstandingJSON.push(j);
} }
let x = JSON.stringify(this.outstandingJSON);
req.send(x); if (this.outstandingJSON.length > 0) {
let x = JSON.stringify(this.outstandingJSON);
req.send(x);
}
} else { } else {
// we add an acknowledgment to clear the server side queue // we add an acknowledgment to clear the server side queue
// //
@ -205,7 +205,7 @@ class Channel {
...this.outstandingJSON, ...this.outstandingJSON,
{action: "ack", "event-id": parseInt(this.lastEventId)} {action: "ack", "event-id": parseInt(this.lastEventId)}
]; ];
if(j) { if (j) {
payload.push(j) payload.push(j)
} }
let x = JSON.stringify(payload); let x = JSON.stringify(payload);