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> <p>
<label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label> <label><input type="checkbox" id="option-cursor-blink"> cursorBlink</label>
</p> </p>
<p>
<label><input type="checkbox" checked id="zmodem-auto"> Accept all ZMODEM prompts<sup>*</sup></label>
</p>
<p> <p>
<label> <label>
cursorStyle cursorStyle
@@ -119,8 +122,8 @@
</div> </div>
</div> </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><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> <script src="main.js" defer ></script>
</body> </body>
</html> </html>
+48 -29
View File
@@ -120,34 +120,42 @@ function createTerminal() {
}); });
term.on("zmodemDetect", (detection) => { term.on("zmodemDetect", (detection) => {
start_form.style.display = ""; function do_zmodem() {
start_form.onsubmit = function(e) { try {
start_form.style.display = "none"; term.detach();
let zsession = detection.confirm();
if (document.getElementById("zmstart_yes").checked) { current_zsession = zsession;
try { if (zsession.type === "receive") {
term.detach(); _handle_receive_session(zsession);
let zsession = detection.confirm();
current_zsession = zsession;
if (zsession.type === "receive") {
_handle_receive_session(zsession);
}
else {
_handle_send_session(zsession);
}
} }
catch(e) { throw e } else {
finally { _handle_send_session(zsession);
term.attach(socket);
} }
} }
else { catch(e) { throw e }
detection.deny(); 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"); var start_form = document.getElementById("zm_start");
function _auto_zmodem() {
return document.getElementById("zmodem-auto").checked;
}
// END UI STUFF // END UI STUFF
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -208,10 +220,9 @@ function _handle_receive_session(zsession) {
_show_file_info(xfer); _show_file_info(xfer);
var offer_form = document.getElementById("zm_offer"); var offer_form = document.getElementById("zm_offer");
offer_form.style.display = "";
offer_form.onsubmit = function(e) { function on_form_submit() {
var the_form = e.currentTarget; offer_form.style.display = "none";
the_form.style.display = "none";
//START //START
//if (offer_form.zmaccept.value) { //if (offer_form.zmaccept.value) {
@@ -232,7 +243,15 @@ function _handle_receive_session(zsession) {
xfer.skip(); xfer.skip();
} }
//END //END
}; }
if (_auto_zmodem()) {
on_form_submit();
}
else {
offer_form.onsubmit = on_form_submit;
offer_form.style.display = "";
}
} ); } );
zsession.on("session_end", () => { zsession.on("session_end", () => {
@@ -257,13 +276,13 @@ function _handle_send_session(zsession) {
files_obj, files_obj,
{ {
on_offer_response(obj, xfer) { on_offer_response(obj, xfer) {
console.log("offer", xfer ? "accepted" : "skipped"); //console.log("offer", xfer ? "accepted" : "skipped");
}, },
on_progress(obj, xfer) { on_progress(obj, xfer) {
_update_progress(xfer); _update_progress(xfer);
}, },
on_file_complete(obj) { on_file_complete(obj) {
console.log("COMPLETE", obj); //console.log("COMPLETE", obj);
_hide_progress(); _hide_progress();
}, },
} }
+1 -1
View File
@@ -68,7 +68,7 @@
"typescript": "~2.4.0", "typescript": "~2.4.0",
"vinyl-buffer": "^1.0.0", "vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0", "vinyl-source-stream": "^1.1.0",
"zmodem.js": "^0.1.1" "zmodem.js": "^0.1.4"
}, },
"scripts": { "scripts": {
"prestart": "npm run build", "prestart": "npm run build",