Skip to content

Commit 722adee

Browse files
Add url generating function to clientService function
1 parent 4eb8664 commit 722adee

File tree

2 files changed

+20
-64
lines changed

2 files changed

+20
-64
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: 11 additions & 51 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) + '://' + this.path + ':' + this.port + '/' + (location || '');
99+
},
139100
version: {
140101
// Constants
141102
MINIMUM_ALLOWED: '0.7.0',
@@ -279,7 +240,7 @@ function checkClientVersionModal(rawVersion) {
279240
* This is evaluating the BlocklyProp Client or BlocklyProp Launcher version??
280241
*/
281242
var check_client = function () {
282-
$.get("http://" + client_domain_name + ":" + client_domain_port + "/", function (data) {
243+
$.get(clientService.url(), function (data) {
283244
if (!client_available) {
284245
let client_version_str = (typeof data.version_str !== "undefined") ? data.version_str : data.version;
285246
if (!data.server || data.server !== 'BlocklyPropHTTP') {
@@ -347,7 +308,7 @@ var configure_client = function () {
347308
id: "domain_name",
348309
type: "text",
349310
class: "form-control",
350-
value: client_domain_name
311+
value: clientService.path
351312
}).appendTo(domain_name_group);
352313

353314
// Hard code the ':' between the domain name and port input fields
@@ -365,14 +326,14 @@ var configure_client = function () {
365326
id: "port_number",
366327
type: "number",
367328
class: "form-control",
368-
value: client_domain_port
329+
value: clientService.port
369330
}).appendTo(domain_port_group);
370331

371332
// Show the modal dialog
372333
utils.confirm(Blockly.Msg.DIALOG_BLOCKLYPROP_LAUNCHER_CONFIGURE_TITLE, url_input, function (action) {
373334
if (action) {
374-
client_domain_name = $("#domain_name").val();
375-
client_domain_port = $("#port_number").val();
335+
clientService.path = $("#domain_name").val();
336+
clientService.port = $("#port_number").val();
376337
}
377338
}, Blockly.Msg.DIALOG_SAVE_TITLE);
378339
};
@@ -386,8 +347,7 @@ function establish_socket() {
386347
// Clear the port list
387348
set_port_list();
388349

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

392352
connection.onopen = function () {
393353

0 commit comments

Comments
 (0)