Skip to content

Commit 13387cb

Browse files
authored
Merge pull request #317 from MatzElectronics/solo-200-resubmit-E-clientURLFormattingFunction
Solo 200 resubmit E client URL formatting function
2 parents 960fee9 + 7ece119 commit 13387cb

File tree

2 files changed

+23
-84
lines changed

2 files changed

+23
-84
lines changed

src/blocklyc.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ function loadInto(modal_message, compile_command, load_option, load_action) {
616616

617617
if (clientService.version.isCoded) {
618618
//Request load with options from BlocklyProp Client
619-
$.post("http://" + client_domain_name + ":" + client_domain_port + "/load.action", {
619+
$.post(clientService.url("load.action"), {
620620
option: load_option,
621621
action: load_action,
622622
binary: data.binary,
@@ -662,7 +662,7 @@ function loadInto(modal_message, compile_command, load_option, load_action) {
662662
} else {
663663
//TODO: Remove this once client_min_version is >= minCodedVer
664664
//Request load without options from old BlocklyProp Client
665-
$.post("http://" + client_domain_name + ":" + client_domain_port + "/load.action", {
665+
$.post(clientService.url("load.action"), {
666666
action: load_action,
667667
binary: data.binary,
668668
extension: data.extension,
@@ -707,9 +707,7 @@ function serial_console() {
707707
}
708708

709709
if (ports_available) {
710-
var url = "http://" + client_domain_name + ":" + client_domain_port + "/serial.connect";
711-
url = url.replace('http', 'ws');
712-
var connection = new WebSocket(url);
710+
var connection = new WebSocket(clientService.url("serial.connect", "ws"));
713711

714712
// When the connection is open, open com port
715713
connection.onopen = function () {
@@ -892,7 +890,7 @@ function graphing_console() {
892890
}
893891

894892
if (client_use_type !== 'ws' && ports_available) {
895-
var connection = new WebSocket("ws://" + client_domain_name + ":" + client_domain_port + "/serial.connect");
893+
var connection = new WebSocket(clientService.url("serial.connect", "ws"));
896894

897895
// When the connection is open, open com port
898896
connection.onopen = function () {
@@ -1041,13 +1039,11 @@ var graphStartStop = function (action) {
10411039
var checkForComPorts = function () {
10421040
// TODO: We need to evaluate this when using web sockets ('ws') === true
10431041
if (client_use_type !== 'ws') {
1044-
if (client_domain_name && client_domain_port) {
1045-
$.get("http://" + client_domain_name + ":" + client_domain_port + "/ports.json", function (data) {
1046-
set_port_list(data);
1047-
}).fail(function () {
1048-
set_port_list();
1049-
});
1050-
}
1042+
$.get(clientService.url("ports.json"), function (data) {
1043+
set_port_list(data);
1044+
}).fail(function () {
1045+
set_port_list();
1046+
});
10511047
}
10521048
};
10531049

src/blocklypropclient.js

Lines changed: 14 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,6 @@ var client_available = false;
4141
var ports_available = false;
4242

4343

44-
/**
45-
* The version number the BlocklyProp Client reported
46-
*
47-
* @type {number}
48-
*/
49-
var client_version = 0;
50-
51-
52-
// TODO: Verify that this variable is a host name and not a domain name
53-
/**
54-
* Client host name
55-
*
56-
* @type {string}
57-
*/
58-
var client_domain_name = "localhost";
59-
60-
61-
/**
62-
* Port number component of the BlocklyProp Client interface
63-
*
64-
* @type {number}
65-
*/
66-
var client_domain_port = 6009;
67-
68-
69-
/**
70-
* The minimum version of the BlocklyProp Client that can be used with this interface
71-
*
72-
* @type {string}
73-
*/
74-
var client_min_version = "0.7.0";
75-
76-
77-
/**
78-
* The most recent version of the BlocklyPro Client that can be used with this interface
79-
*
80-
* @type {string}
81-
*/
82-
var client_recommended_version = "0.8.0";
83-
84-
8544
// TODO: Document what the 'client_use_type' variable represents
8645
/**
8746
* Not sure what this does
@@ -126,16 +85,18 @@ var clientService = {
12685
/*
12786
available: false,
12887
portsAvailable: false,
88+
*/
12989
path: 'localhost',
13090
port: 6009,
91+
/*
13192
type: null,
13293
rxBase64: true,
13394
portListReceiveCountUp: 0, // This is set to 0 each time the port list is received, and incremented once each 4 second heartbeat
13495
activeConnection: null,
135-
url: function (protocol) {
136-
return protocol + '://' + this.path + ':' + this.port + '/';
137-
},
13896
*/
97+
url: function (location, protocol) {
98+
return (protocol || window.location.protocol.replace(':', '')) + '://' + this.path + ':' + this.port + '/' + (location || '');
99+
},
139100
version: {
140101
// Constants
141102
MINIMUM_ALLOWED: '0.7.0',
@@ -174,12 +135,11 @@ var clientService = {
174135
}
175136

176137
// Status Notice IDs
177-
//const NS_DOWNLOADING = 002;
178-
//const NS_DOWNLOAD_SUCCESSFUL = 005;
179-
const NS_DOWNLOADING = 2;
138+
//const NS_DOWNLOADING = 002;
139+
//const NS_DOWNLOAD_SUCCESSFUL = 005;
140+
const NS_DOWNLOADING = 2;
180141
const NS_DOWNLOAD_SUCCESSFUL = 5;
181142

182-
183143
// Error Notice IDs
184144
const NE_DOWNLOAD_FAILED = 102;
185145

@@ -201,22 +161,6 @@ var find_client = function () {
201161
}
202162
};
203163

204-
var version_as_number = function (rawVersion) {
205-
var tempVersion = rawVersion.toString().split(".");
206-
tempVersion.push('0');
207-
208-
if (tempVersion.length < 3) {
209-
if (tempVersion.length === 1)
210-
tempVersion = '0.0.0';
211-
else
212-
tempVersion.unshift('0');
213-
}
214-
215-
// Allow for any of the three numbers to be between 0 and 1023.
216-
// Equivalent to: (Major * 104856) + (Minor * 1024) + Revision.
217-
return (Number(tempVersion[0]) << 20 | Number(tempVersion[1]) << 10 | Number(tempVersion[2]));
218-
};
219-
220164
var setPropToolbarButtons = function (ui_btn_state) {
221165
if (ui_btn_state === 'available') {
222166
if (projectData && projectData.board === 's3') {
@@ -279,7 +223,7 @@ function checkClientVersionModal(rawVersion) {
279223
* This is evaluating the BlocklyProp Client or BlocklyProp Launcher version??
280224
*/
281225
var check_client = function () {
282-
$.get("http://" + client_domain_name + ":" + client_domain_port + "/", function (data) {
226+
$.get(clientService.url(), function (data) {
283227
if (!client_available) {
284228
let client_version_str = (typeof data.version_str !== "undefined") ? data.version_str : data.version;
285229
if (!data.server || data.server !== 'BlocklyPropHTTP') {
@@ -347,7 +291,7 @@ var configure_client = function () {
347291
id: "domain_name",
348292
type: "text",
349293
class: "form-control",
350-
value: client_domain_name
294+
value: clientService.path
351295
}).appendTo(domain_name_group);
352296

353297
// Hard code the ':' between the domain name and port input fields
@@ -365,14 +309,14 @@ var configure_client = function () {
365309
id: "port_number",
366310
type: "number",
367311
class: "form-control",
368-
value: client_domain_port
312+
value: clientService.port
369313
}).appendTo(domain_port_group);
370314

371315
// Show the modal dialog
372316
utils.confirm(Blockly.Msg.DIALOG_BLOCKLYPROP_LAUNCHER_CONFIGURE_TITLE, url_input, function (action) {
373317
if (action) {
374-
client_domain_name = $("#domain_name").val();
375-
client_domain_port = $("#port_number").val();
318+
clientService.path = $("#domain_name").val();
319+
clientService.port = $("#port_number").val();
376320
}
377321
}, Blockly.Msg.DIALOG_SAVE_TITLE);
378322
};
@@ -386,8 +330,7 @@ function establish_socket() {
386330
// Clear the port list
387331
set_port_list();
388332

389-
var url = "ws://" + client_domain_name + ":" + client_domain_port + "/";
390-
var connection = new WebSocket(url);
333+
var connection = new WebSocket(clientService.url('', 'ws'));
391334

392335
connection.onopen = function () {
393336

0 commit comments

Comments
 (0)