provide for better compatibility with attach.js

This commit is contained in:
Felipe Gasper
2017-10-27 20:14:18 -05:00
parent a90493a9af
commit 6c3af6e19a
3 changed files with 43 additions and 10 deletions
+3 -1
View File
@@ -112,7 +112,9 @@ function createTerminal() {
socket.onclose = runFakeTerminal;
socket.onerror = runFakeTerminal;
term.zmodemAttach(socket);
term.zmodemAttach(socket, {
noTerminalWriteOutsideSession: true,
} );
term.on("zmodemDetect", (detection) => {
term.detach();
+18 -2
View File
@@ -56,11 +56,27 @@
}
};
var myTextDecoder;
term._getMessage = function (ev) {
var str;
if (typeof ev.data === "object") {
if (ev.data instanceof ArrayBuffer) {
if (!myTextDecoder) {
myTextDecoder = new TextDecoder();
}
str = myTextDecoder.decode( ev.data );
}
else {
throw "TODO: handle Blob?";
}
}
if (buffered) {
term._pushToBuffer(ev.data);
term._pushToBuffer(str || ev.data);
} else {
term.write(ev.data);
term.write(str || ev.data);
}
};
+22 -7
View File
@@ -41,18 +41,28 @@
Object.assign(
Terminal.prototype,
{
zmodemAttach: function zmodemAttach(ws) {
zmodemAttach: function zmodemAttach(ws, opts) {
var term = this;
if (!opts) opts = {};
var senderFunc = function _ws_sender_func(octets) {
ws.send( new Uint8Array(octets) );
};
var zsentry = new Zmodem.Sentry( {
var zsentry;
function _shouldWrite() {
return !!zsentry.get_confirmed_session() || !opts.noTerminalWriteOutsideSession;
}
zsentry = new Zmodem.Sentry( {
to_terminal: function _to_terminal(octets) {
term.write(
String.fromCharCode.apply(String, octets)
);
if (_shouldWrite()) {
term.write(
String.fromCharCode.apply(String, octets)
);
}
},
sender: senderFunc,
@@ -68,9 +78,14 @@
function handleWSMessage(evt) {
//For some reason the first message from the server is text.
//In testing with xterm.jss demo the first message was
//always text even if the rest were binary. While that
//may be specific to xterm.jss demo, ultimately we
//should reject anything that isnt binary.
if (typeof evt.data === "string") {
term.write(evt.data);
if (_shouldWrite()) {
term.write(evt.data);
}
}
else {
zsentry.consume(evt.data);