provide for better compatibility with attach.js
This commit is contained in:
+3
-1
@@ -112,7 +112,9 @@ function createTerminal() {
|
|||||||
socket.onclose = runFakeTerminal;
|
socket.onclose = runFakeTerminal;
|
||||||
socket.onerror = runFakeTerminal;
|
socket.onerror = runFakeTerminal;
|
||||||
|
|
||||||
term.zmodemAttach(socket);
|
term.zmodemAttach(socket, {
|
||||||
|
noTerminalWriteOutsideSession: true,
|
||||||
|
} );
|
||||||
|
|
||||||
term.on("zmodemDetect", (detection) => {
|
term.on("zmodemDetect", (detection) => {
|
||||||
term.detach();
|
term.detach();
|
||||||
|
|||||||
@@ -56,11 +56,27 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var myTextDecoder;
|
||||||
|
|
||||||
term._getMessage = function (ev) {
|
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) {
|
if (buffered) {
|
||||||
term._pushToBuffer(ev.data);
|
term._pushToBuffer(str || ev.data);
|
||||||
} else {
|
} else {
|
||||||
term.write(ev.data);
|
term.write(str || ev.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,18 +41,28 @@
|
|||||||
Object.assign(
|
Object.assign(
|
||||||
Terminal.prototype,
|
Terminal.prototype,
|
||||||
{
|
{
|
||||||
zmodemAttach: function zmodemAttach(ws) {
|
zmodemAttach: function zmodemAttach(ws, opts) {
|
||||||
var term = this;
|
var term = this;
|
||||||
|
|
||||||
|
if (!opts) opts = {};
|
||||||
|
|
||||||
var senderFunc = function _ws_sender_func(octets) {
|
var senderFunc = function _ws_sender_func(octets) {
|
||||||
ws.send( new Uint8Array(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) {
|
to_terminal: function _to_terminal(octets) {
|
||||||
term.write(
|
if (_shouldWrite()) {
|
||||||
String.fromCharCode.apply(String, octets)
|
term.write(
|
||||||
);
|
String.fromCharCode.apply(String, octets)
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
sender: senderFunc,
|
sender: senderFunc,
|
||||||
@@ -68,9 +78,14 @@
|
|||||||
|
|
||||||
function handleWSMessage(evt) {
|
function handleWSMessage(evt) {
|
||||||
|
|
||||||
//For some reason the first message from the server is text.
|
//In testing with xterm.js’s demo the first message was
|
||||||
|
//always text even if the rest were binary. While that
|
||||||
|
//may be specific to xterm.js’s demo, ultimately we
|
||||||
|
//should reject anything that isn’t binary.
|
||||||
if (typeof evt.data === "string") {
|
if (typeof evt.data === "string") {
|
||||||
term.write(evt.data);
|
if (_shouldWrite()) {
|
||||||
|
term.write(evt.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
zsentry.consume(evt.data);
|
zsentry.consume(evt.data);
|
||||||
|
|||||||
Reference in New Issue
Block a user