prep for addon - find loop

This commit is contained in:
Felipe Gasper
2017-10-16 15:12:07 +01:00
parent a6efda6120
commit 151eac6f4f
4 changed files with 1052 additions and 100 deletions
+6
View File
@@ -8,7 +8,13 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script src="/build/xterm.js" ></script>
<!--
<script src="/build/addons/attach/attach.js" ></script>
-->
<script src="/build/addons/zmodem/zmodemjs/dist/zmodem.js" ></script>
<script src="/build/addons/zmodem/zmodem.js" ></script>
<script src="/build/addons/fit/fit.js" ></script>
<script src="/build/addons/fullscreen/fullscreen.js" ></script>
<script src="/build/addons/search/search.js" ></script>
+22 -53
View File
@@ -106,12 +106,9 @@ function createTerminal() {
window.pid = pid;
socketURL += pid;
socket = new WebSocket(socketURL);
socket.binaryType = "arraybuffer";
socket.onopen = runRealTerminal;
socket.onclose = runFakeTerminal;
socket.onerror = runFakeTerminal;
socket.addEventListener("message", handleWSMessage);
});
});
}, 0);
@@ -235,75 +232,47 @@ function _handle_send_session(zsession) {
//This is here to allow canceling of an in-progress ZMODEM transfer.
var current_zsession;
//Called from HTML directly.
function abort_current_session() {
current_zsession.abort();
}
var text_encoder = new TextEncoder();
var zsentry = new Zmodem.Sentry( {
to_terminal(octets) {
term.write(
String.fromCharCode.apply(String, octets)
);
},
term.zmodemAttach(socket);
sender(octets) {
socket.send( new Uint8Array(octets) );
},
term.on("zmodemRetract", () => {
start_form.style.display = "none";
start_form.onsubmit = null;
});
on_retract() {
term.on("zmodemDetect", () => {
start_form.style.display = "";
start_form.onsubmit = function(e) {
start_form.style.display = "none";
start_form.onsubmit = null;
},
on_detect(detection) {
start_form.style.display = "";
start_form.onsubmit = function(e) {
start_form.style.display = "none";
if (document.getElementById("zmstart_yes").checked) {
let zsession = detection.confirm();
if (document.getElementById("zmstart_yes").checked) {
let zsession = detection.confirm();
current_zsession = zsession;
current_zsession = zsession;
if (zsession.type === "receive") {
_handle_receive_session(zsession);
}
else {
_handle_send_session(zsession);
}
if (zsession.type === "receive") {
_handle_receive_session(zsession);
}
else {
detection.deny();
_handle_send_session(zsession);
}
};
},
} );
function handleWSMessage(evt) {
//For some reason the first message from the server is text.
if (typeof evt.data === "string") {
term.write(evt.data);
}
else {
zsentry.consume(evt.data);
}
}
//var text_encoder = new TextEncoder();
}
else {
detection.deny();
}
};
});
function runRealTerminal() {
term.attach(socket, false);
/*
term.on("data", (d) => {
//socket.send( text_encoder.encode(d) );
socket.send(d);
});
*/
term._initialized = true;
term._initialized = true;
}
function runFakeTerminal() {
+948 -47
View File
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
//Eventually?
//import { Zmodem } from './zmodemjs/dist/zmodem';
(function (addon) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = addon(require('../../Terminal').Terminal);
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../xterm'], addon);
} else {
/*
* Plain browser environment
*/
addon(window.Terminal);
}
})(function _zmodemAddon(Terminal) {
if (Terminal.prototype.attach) {
throw "The “zmodem” and “attach” addons are mutually incompatible.";
}
function _makeSendWsWrapper(socket) {
return
}
Object.assign(
Terminal.prototype,
{
zmodemAttach: function zmodemAttach(ws) {
var term = this;
var senderFunc = function _ws_sender_func(octets) {
ws.send( new Uint8Array(octets) );
};
var zsentry = new Zmodem.Sentry( {
to_terminal: function _to_terminal(octets) {
term.write(
String.fromCharCode.apply(String, octets)
);
},
sender: senderFunc,
on_retract: function _on_retract() {
term.emit("zmodemRetract");
},
on_detect: function _on_detect(detection) {
term.emit("zmodemDetect", detection);
},
} );
function handleWSMessage(evt) {
//For some reason the first message from the server is text.
if (typeof evt.data === "string") {
term.write(evt.data);
}
else {
zsentry.consume(evt.data);
}
}
ws.binaryType = "arraybuffer";
ws.addEventListener("message", handleWSMessage);
},
zmodemBrowser: Zmodem.Browser,
}
);
});