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. 29
      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,9 +72,8 @@ 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
@ -86,7 +93,7 @@ module.exports = class TermConnection extends EventEmitter {
break break
default: default:
this.screen.load(evt.data) this.screen.load(str)
if (!this.pageShown) { if (!this.pageShown) {
window.showPage() window.showPage()
this.pageShown = true this.pageShown = true
@ -94,8 +101,18 @@ module.exports = class TermConnection extends EventEmitter {
break break
} }
this.heartbeat() this.heartbeat()
} catch (e) { }
console.error(e)
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)
}
} }
} }

Loading…
Cancel
Save