From df21a9c6682a85b3f608d5d5ecdd155768a252f0 Mon Sep 17 00:00:00 2001 From: Matthew Matz <19737272+MatzElectronics@users.noreply.github.com> Date: Wed, 1 Jan 2020 23:31:07 -0800 Subject: [PATCH 1/2] base64 encode port failure messages No need to transmit "No Device", but it is helpful to denote the device that was unable to connect. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9218040..fff0bec 100644 --- a/index.js +++ b/index.js @@ -477,7 +477,7 @@ function serialTerminal(sock, action, portName, baudrate, msg) { .then(function() {log('Connected terminal to ' + portName + ' at ' + baudrate + ' baud.');}) .catch(function() { log('Unable to connect terminal to ' + portName); - var msg_to_send = {type:'serial-terminal', msg:'Failed to connect.\rPlease close this terminal and select a connected port.'}; + var msg_to_send = {type:'serial-terminal', msg:btoa('Failed to connect to ' + portName + '.\rPlease close this terminal and select a connected port.')}; sock.send(JSON.stringify(msg_to_send)); }); } else if (action === "close") { @@ -492,7 +492,7 @@ function serialTerminal(sock, action, portName, baudrate, msg) { } } } else { - var msg_to_send = {type:'serial-terminal', msg:'Port ' + portName + ' not found.\rPlease close this terminal and select an existing port.'}; + var msg_to_send = {type:'serial-terminal', msg:btoa('No device connected.\rPlease close this terminal and select an existing port.')}; sock.send(JSON.stringify(msg_to_send)); } } From 8f820a5828dc571a49400ae6d5c969c2b4219e5b Mon Sep 17 00:00:00 2001 From: Matthew Matz <19737272+MatzElectronics@users.noreply.github.com> Date: Wed, 1 Jan 2020 23:42:05 -0800 Subject: [PATCH 2/2] Base 64 decode incoming serial messages Adds flag to let the browser know that it is safe to base64 encode those transmissions --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fff0bec..59c4832 100644 --- a/index.js +++ b/index.js @@ -319,7 +319,7 @@ function connect_ws(ws_port, url_path) { setTimeout(function() {loadPropeller(socket, ws_msg.portPath, ws_msg.action, ws_msg.payload, ws_msg.debug)}, 10); // success is a JSON that the browser generates and expects back to know if the load was successful or not } else if (ws_msg.type === "serial-terminal") { // open or close the serial port for terminal/debug - serialTerminal(socket, ws_msg.action, ws_msg.portPath, ws_msg.baudrate, ws_msg.msg); // action is "open", "close" or "msg" + serialTerminal(socket, ws_msg.action, ws_msg.portPath, ws_msg.baudrate, atob(ws_msg.msg)); // action is "open", "close" or "msg" } else if (ws_msg.type === "port-list-request") { // send an updated port list (and continue on scheduled interval) // log("Browser requested port-list for socket " + socket.pSocket_.socketId, mDbug); @@ -455,7 +455,7 @@ function sendPortList(socket) { function helloClient(sock, baudrate) { - var msg_to_send = {type:'hello-client', version:clientVersion}; + var msg_to_send = {type:'hello-client', version:clientVersion, rxBase64:true}; sock.send(JSON.stringify(msg_to_send)); }