From 6026bd44c3d92a549ce703c688fbfa50c788258f Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 19 Oct 2017 11:50:36 +0200 Subject: [PATCH] put ZMODEM auto-toggle into demo UI --- demo/index.html | 5 +++- demo/main.js | 77 ++++++++++++++++++++++++++++++------------------- package.json | 2 +- 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/demo/index.html b/demo/index.html index b70245ef..b2f64669 100644 --- a/demo/index.html +++ b/demo/index.html @@ -78,6 +78,9 @@

+

+ +

ZMODEM file transfers are supported via an addon. To try it out, install lrzsz onto the remote peer, then type rz to send from your browser or sz <file> to send from the remote peer.

Attention: 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.

+

* ZMODEM file transfers are supported via an addon. To try it out, install lrzsz onto the remote peer, then type rz to send from your browser or sz <file> to send from the remote peer.

diff --git a/demo/main.js b/demo/main.js index 3186a5eb..703658c4 100644 --- a/demo/main.js +++ b/demo/main.js @@ -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(); }, } diff --git a/package.json b/package.json index 2e247e9b..bdde38eb 100644 --- a/package.json +++ b/package.json @@ -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",