support binary socket messages

box-drawing
Ondřej Hruška 7 years ago
parent 55e2def6e3
commit 0a281414a8
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 77
      js/term/connection.js

@ -17,6 +17,14 @@ module.exports = class TermConnection extends EventEmitter {
this.reconnTimeout = null this.reconnTimeout = null
this.forceClosing = false this.forceClosing = false
this.blobReader = new FileReader()
this.blobReader.onload = (evt) => {
this.onDecodedWSMessage(this.blobReader.result)
}
this.blobReader.onerror = (evt) => {
console.error(evt)
}
this.pageShown = false this.pageShown = false
this.disconnectTimeout = null this.disconnectTimeout = null
@ -64,38 +72,47 @@ module.exports = class TermConnection extends EventEmitter {
this.emit('disconnect', evt.code) this.emit('disconnect', evt.code)
} }
onWSMessage (evt) { onDecodedWSMessage (str) {
try { switch (str.charAt(0)) {
switch (evt.data.charAt(0)) { case '.':
case '.': // heartbeat, no-op message
// heartbeat, no-op message break
break
case '-':
case '-': // console.log('xoff');
// console.log('xoff'); this.xoff = true
this.xoff = true this.autoXoffTimeout = setTimeout(() => {
this.autoXoffTimeout = setTimeout(() => {
this.xoff = false
}, 250)
break
case '+':
// console.log('xon');
this.xoff = false this.xoff = false
clearTimeout(this.autoXoffTimeout) }, 250)
break break
default: case '+':
this.screen.load(evt.data) // console.log('xon');
if (!this.pageShown) { this.xoff = false
window.showPage() clearTimeout(this.autoXoffTimeout)
this.pageShown = true break
}
break default:
this.screen.load(str)
if (!this.pageShown) {
window.showPage()
this.pageShown = true
}
break
}
this.heartbeat()
}
onWSMessage (evt) {
if (typeof evt.data === 'string') this.onDecodedWSMessage(evt.data)
else {
if (this.blobReader.readyState !== 1) {
this.blobReader.readAsText(evt.data)
} else {
setTimeout(() => {
this.onWSMessage(evt)
}, 1)
} }
this.heartbeat()
} catch (e) {
console.error(e)
} }
} }

Loading…
Cancel
Save