mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
provide for better compatibility with attach.js
This commit is contained in:
+3
-1
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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.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") {
|
||||
term.write(evt.data);
|
||||
if (_shouldWrite()) {
|
||||
term.write(evt.data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
zsentry.consume(evt.data);
|
||||
|
||||
Reference in New Issue
Block a user