From 3d93cd3690432ed39cf65887c3e008747740db4c Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 8 Oct 2017 14:19:09 +0200 Subject: [PATCH] Add input queue --- js/term/connection.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/js/term/connection.js b/js/term/connection.js index d3cdf03..5e2c360 100644 --- a/js/term/connection.js +++ b/js/term/connection.js @@ -19,9 +19,10 @@ module.exports = class TermConnection extends EventEmitter { this.autoXoffTimeout = null this.reconnTimeout = null this.forceClosing = false + this.queue = [] try { - this.blobReader = new FileReader() + this.blobReader = new window.FileReader() this.blobReader.onload = (evt) => { this.onDecodedWSMessage(this.blobReader.result) } @@ -90,12 +91,14 @@ module.exports = class TermConnection extends EventEmitter { this.xoff = true this.autoXoffTimeout = setTimeout(() => { this.xoff = false + this.flushQueue() }, 250) break case '+': // console.log('xon'); this.xoff = false + this.flushQueue() clearTimeout(this.autoXoffTimeout) break @@ -143,7 +146,8 @@ module.exports = class TermConnection extends EventEmitter { } if (this.xoff) { // TODO queue - console.log("Can't send, flood control.") + console.log("Can't send, flood control. Queueing") + this.queue.push(message) return false } @@ -159,6 +163,12 @@ module.exports = class TermConnection extends EventEmitter { return true } + flushQueue () { + console.log('Flushing input queue') + for (let message of this.queue) this.send(message) + this.queue = [] + } + /** Safely close the socket */ closeSocket () { if (this.ws) {