|
|
|
@ -17,6 +17,14 @@ module.exports = class TermConnection extends EventEmitter { |
|
|
|
|
this.reconnTimeout = null |
|
|
|
|
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.disconnectTimeout = null |
|
|
|
@ -64,9 +72,8 @@ module.exports = class TermConnection extends EventEmitter { |
|
|
|
|
this.emit('disconnect', evt.code) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onWSMessage (evt) { |
|
|
|
|
try { |
|
|
|
|
switch (evt.data.charAt(0)) { |
|
|
|
|
onDecodedWSMessage (str) { |
|
|
|
|
switch (str.charAt(0)) { |
|
|
|
|
case '.': |
|
|
|
|
// heartbeat, no-op message
|
|
|
|
|
break |
|
|
|
@ -86,7 +93,7 @@ module.exports = class TermConnection extends EventEmitter { |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
this.screen.load(evt.data) |
|
|
|
|
this.screen.load(str) |
|
|
|
|
if (!this.pageShown) { |
|
|
|
|
window.showPage() |
|
|
|
|
this.pageShown = true |
|
|
|
@ -94,8 +101,18 @@ module.exports = class TermConnection extends EventEmitter { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|