put ZMODEM auto-toggle into demo UI

This commit is contained in:
Felipe Gasper
2017-10-19 11:50:36 +02:00
parent 7bc7bb0ab9
commit 6026bd44c3
3 changed files with 53 additions and 31 deletions
+4 -1
View File
@@ -78,6 +78,9 @@
<p>
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
</p>
<p>
<label><input type="checkbox" checked id="zmodem-auto"> Accept all ZMODEM prompts<sup>*</sup></label>
</p>
<p>
<label>
cursorStyle
@@ -119,8 +122,8 @@
</div>
</div>
</div>
<p>ZMODEM file transfers are supported via an addon. To try it out, install <a href="https://ohse.de/uwe/software/lrzsz.html"><code>lrzsz</code></a> onto the remote peer, then type <code>rz</code> to send from your browser or <code>sz &lt;file&gt;</code> to send from the remote peer.</p>
<p><strong>Attention:</strong> The demo is a barebones implementation and is designed for xterm.js evaluation purposes only. Exposing the demo to the public as is would introduce security risks for the host.</p>
<p><sup>*</sup> ZMODEM file transfers are supported via an addon. To try it out, install <a href="https://ohse.de/uwe/software/lrzsz.html"><code>lrzsz</code></a> onto the remote peer, then type <code>rz</code> to send from your browser or <code>sz &lt;file&gt;</code> to send from the remote peer.</p>
<script src="main.js" defer ></script>
</body>
</html>
+48 -29
View File
@@ -120,34 +120,42 @@ function createTerminal() {
});
term.on("zmodemDetect", (detection) => {
start_form.style.display = "";
start_form.onsubmit = function(e) {
start_form.style.display = "none";
function do_zmodem() {
try {
term.detach();
let zsession = detection.confirm();
if (document.getElementById("zmstart_yes").checked) {
current_zsession = zsession;
try {
term.detach();
let zsession = detection.confirm();
current_zsession = zsession;
if (zsession.type === "receive") {
_handle_receive_session(zsession);
}
else {
_handle_send_session(zsession);
}
if (zsession.type === "receive") {
_handle_receive_session(zsession);
}
catch(e) { throw e }
finally {
term.attach(socket);
else {
_handle_send_session(zsession);
}
}
else {
detection.deny();
catch(e) { throw e }
finally {
term.attach(socket);
}
};
}
if (_auto_zmodem()) {
do_zmodem();
}
else {
start_form.style.display = "";
start_form.onsubmit = function(e) {
start_form.style.display = "none";
if (document.getElementById("zmstart_yes").checked) {
do_zmodem();
}
else {
detection.deny();
}
};
}
});
});
});
@@ -200,6 +208,10 @@ function _hide_progress() {
var start_form = document.getElementById("zm_start");
function _auto_zmodem() {
return document.getElementById("zmodem-auto").checked;
}
// END UI STUFF
//----------------------------------------------------------------------
@@ -208,10 +220,9 @@ function _handle_receive_session(zsession) {
_show_file_info(xfer);
var offer_form = document.getElementById("zm_offer");
offer_form.style.display = "";
offer_form.onsubmit = function(e) {
var the_form = e.currentTarget;
the_form.style.display = "none";
function on_form_submit() {
offer_form.style.display = "none";
//START
//if (offer_form.zmaccept.value) {
@@ -232,7 +243,15 @@ function _handle_receive_session(zsession) {
xfer.skip();
}
//END
};
}
if (_auto_zmodem()) {
on_form_submit();
}
else {
offer_form.onsubmit = on_form_submit;
offer_form.style.display = "";
}
} );
zsession.on("session_end", () => {
@@ -257,13 +276,13 @@ function _handle_send_session(zsession) {
files_obj,
{
on_offer_response(obj, xfer) {
console.log("offer", xfer ? "accepted" : "skipped");
//console.log("offer", xfer ? "accepted" : "skipped");
},
on_progress(obj, xfer) {
_update_progress(xfer);
},
on_file_complete(obj) {
console.log("COMPLETE", obj);
//console.log("COMPLETE", obj);
_hide_progress();
},
}
+1 -1
View File
@@ -68,7 +68,7 @@
"typescript": "~2.4.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"zmodem.js": "^0.1.1"
"zmodem.js": "^0.1.4"
},
"scripts": {
"prestart": "npm run build",