Add input queue

pull/1/head
cpsdqs 7 years ago
parent a5aa536f89
commit 3d93cd3690
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 14
      js/term/connection.js

@ -19,9 +19,10 @@ module.exports = class TermConnection extends EventEmitter {
this.autoXoffTimeout = null this.autoXoffTimeout = null
this.reconnTimeout = null this.reconnTimeout = null
this.forceClosing = false this.forceClosing = false
this.queue = []
try { try {
this.blobReader = new FileReader() this.blobReader = new window.FileReader()
this.blobReader.onload = (evt) => { this.blobReader.onload = (evt) => {
this.onDecodedWSMessage(this.blobReader.result) this.onDecodedWSMessage(this.blobReader.result)
} }
@ -90,12 +91,14 @@ module.exports = class TermConnection extends EventEmitter {
this.xoff = true this.xoff = true
this.autoXoffTimeout = setTimeout(() => { this.autoXoffTimeout = setTimeout(() => {
this.xoff = false this.xoff = false
this.flushQueue()
}, 250) }, 250)
break break
case '+': case '+':
// console.log('xon'); // console.log('xon');
this.xoff = false this.xoff = false
this.flushQueue()
clearTimeout(this.autoXoffTimeout) clearTimeout(this.autoXoffTimeout)
break break
@ -143,7 +146,8 @@ module.exports = class TermConnection extends EventEmitter {
} }
if (this.xoff) { if (this.xoff) {
// TODO queue // TODO queue
console.log("Can't send, flood control.") console.log("Can't send, flood control. Queueing")
this.queue.push(message)
return false return false
} }
@ -159,6 +163,12 @@ module.exports = class TermConnection extends EventEmitter {
return true return true
} }
flushQueue () {
console.log('Flushing input queue')
for (let message of this.queue) this.send(message)
this.queue = []
}
/** Safely close the socket */ /** Safely close the socket */
closeSocket () { closeSocket () {
if (this.ws) { if (this.ws) {

Loading…
Cancel
Save