@@ -66,9 +66,8 @@ var clientService = {
66
66
path : 'localhost' , // Is this always localhost?
67
67
port : 6009 , // BlocklyProp Client/Launcher port number
68
68
type : null , // {string} Seems to be one of "", "ws", "http"
69
-
70
- /*
71
69
rxBase64 : true ,
70
+ /*
72
71
portListReceiveCountUp: 0, // This is set to 0 each time the port list is received, and incremented once each 4 second heartbeat
73
72
activeConnection: null,
74
73
*/
@@ -140,8 +139,8 @@ var find_client = function () {
140
139
}
141
140
} ;
142
141
143
- var setPropToolbarButtons = function ( ui_btn_state ) {
144
- if ( ui_btn_state === ' available' ) {
142
+ var setPropToolbarButtons = function ( ) {
143
+ if ( clientService . available ) {
145
144
if ( projectData && projectData . board === 's3' ) {
146
145
// Hide the buttons that are not required for the S3 robot
147
146
$ ( '.no-s3' ) . addClass ( 'hidden' ) ;
@@ -209,11 +208,12 @@ var check_client = function () {
209
208
if ( ! data . server || data . server !== 'BlocklyPropHTTP' ) {
210
209
client_version_str = '0.0.0' ;
211
210
}
211
+
212
212
checkClientVersionModal ( client_version_str ) ;
213
213
214
214
clientService . type = 'http' ;
215
215
clientService . available = true ;
216
- setPropToolbarButtons ( 'available' ) ;
216
+ setPropToolbarButtons ( ) ;
217
217
if ( checkForComPorts && typeof ( checkForComPorts ) === "function" ) {
218
218
checkForComPorts ( ) ;
219
219
check_com_ports_interval = setInterval ( checkForComPorts , 5000 ) ;
@@ -226,7 +226,7 @@ var check_client = function () {
226
226
clientService . type = 'none' ;
227
227
clientService . available = false ;
228
228
clientService . portsAvailable = false ;
229
- setPropToolbarButtons ( 'unavailable' ) ;
229
+ setPropToolbarButtons ( ) ;
230
230
check_ws_socket_timeout = setTimeout ( find_client , 3000 ) ;
231
231
} ) ;
232
232
} ;
@@ -342,14 +342,14 @@ function establish_socket() {
342
342
if ( ws_msg . type === 'hello-client' ) {
343
343
// type: 'hello-client',
344
344
// version: [String version (semantic versioning)]
345
+ // rxBase64: [boolean, accepts base64-encoded serial streams (all versions transmit base64)]
345
346
checkClientVersionModal ( ws_msg . version ) ;
346
347
347
348
if ( window . getURLParameter ( 'debug' ) ) {
348
349
console . log ( "Websocket client/launcher found - version " + ws_msg . version ) ;
349
350
}
350
351
351
- // TODO: Add version checking here.
352
-
352
+ clientService . rxBase64 = ws_msg . rxBase64 || false ;
353
353
clientService . type = 'ws' ;
354
354
clientService . available = true ;
355
355
@@ -383,12 +383,22 @@ function establish_socket() {
383
383
// type: 'serial-terminal'
384
384
// msg: [String Base64-encoded message]
385
385
386
- var msg_in = atob ( ws_msg . msg ) ;
386
+ var msg_in = '' ;
387
+ try {
388
+ var msg_in = atob ( ws_msg . msg ) ;
389
+ } catch ( error ) {
390
+ // only show the error if it's something other than base-64 encoding
391
+ if ( error . toString ( ) . indexOf ( "'atob'" ) < 0 ) {
392
+ console . error ( error ) ;
393
+ }
394
+ msg_in = ws_msg . msg ;
395
+ }
396
+
387
397
388
- if ( term !== null ) { // is the terminal open?
398
+ if ( term !== null && msg_in !== '' && ws_msg . packetID ) { // is the terminal open?
389
399
pTerm . display ( msg_in ) ;
390
400
pTerm . focus ( ) ;
391
- } else if ( graph !== null ) { // is the graph open?
401
+ } else if ( graph !== null && msg_in !== '' && ws_msg . packetID ) { // is the graph open?
392
402
graph_new_data ( msg_in ) ;
393
403
}
394
404
}
0 commit comments