Update sumorobot.js

This commit is contained in:
Silver Kuusik 2018-06-30 17:17:54 +02:00 committed by GitHub
parent f2907cfd27
commit 4845e90e5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 32 deletions

View File

@ -4,13 +4,15 @@ var hotkeys = true;
var remoteControl = false; var remoteControl = false;
/* the local/remote server URL */ /* the local/remote server URL */
//var robotServer = "10.42.0.1"; //var robotServer = "10.42.0.1";
var robotServer = "iot.koodur.com"; var robotServer = "achex.ca:4010";
/* ace editor object */ /* ace editor object */
var codingEditor = null; var codingEditor = null;
/* read only ace editor object */ /* read only ace editor object */
var readOnlyCodingEditor = null; var readOnlyCodingEditor = null;
// sumorobot ID
var robotId = "";
/* the sumorobot code */ /* the sumorobot code */
var sumocode = ""; var sumocode = "";
/* the sumorobot object */ /* the sumorobot object */
@ -516,18 +518,18 @@ window.onload = function() {
/* if we are in coding mode */ /* if we are in coding mode */
if (codingEnabled) { if (codingEnabled) {
/* send the code from the textarea to the SumoRobot */ /* send the code from the textarea to the SumoRobot */
sumorobot.send("start:" + codingEditor.getValue()); sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'code', 'val': '" + codingEditor.getValue() + "'});
/* otherwise when we are in Blockly mode */ /* otherwise when we are in Blockly mode */
} else { } else {
/* send the code from the blocks to the SumoRobot */ /* send the code from the blocks to the SumoRobot */
sumorobot.send("start:" + sumocode); sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'code', 'val': '" + sumocode + "'});
} }
}); });
/* stop button listener */ /* stop button listener */
$(".btn-stop").click(function() { $(".btn-stop").click(function() {
sumostart = false; sumostart = false;
sumorobot.send("stop"); sumorobot.send("{'to':'sumo-" + robotId + "@00000514','cmd': 'stop'}");
workspace.highlightBlock(lastHighlighted, false); workspace.highlightBlock(lastHighlighted, false);
}); });
@ -538,31 +540,12 @@ window.onload = function() {
$(".btn-robot-go").click(); $(".btn-robot-go").click();
} }
}); });
/* when robot-id input field gets focused */
$("#robot-id").focus(function() {
/* if there is no value in the robot-id input field */
if (!$("#robot-id").val()) {
/* add "sumo-" to the input field so the user */
/* just has to add the robot ID */
$("#robot-id").val("sumo-");
}
});
/* when robot-id input field gets unfocused */
$("#robot-id").blur(function() {
/* if the robot-id input value is the previously set "sumo-" */
if ($("#robot-id").val() === "sumo-") {
/* remove the value */
$("#robot-id").val("");
}
});
/* robot number button listener */ /* robot number button listener */
$(".btn-robot-go").click(function() { $(".btn-robot-go").click(function() {
/* extract and validate the selected robot ID */ /* extract and validate the selected robot ID */
var robotId = $("#robot-id").val().trim(); robotId = $("#robot-id").val().trim();
if (robotId === "" || /^(sumo-[a-f0-9]{6})$/.test(robotId) == false) { if (robotId === "" || /^([a-f0-9]{6})$/.test(robotId) == false) {
$("#robot-id, #robot-label").addClass("has-error"); $("#robot-id, #robot-label").addClass("has-error");
return; return;
} else { } else {
@ -571,23 +554,24 @@ window.onload = function() {
/* update robot IDs in local storage */ /* update robot IDs in local storage */
setLocalStorageItem("sumorobot.robotId", robotId); setLocalStorageItem("sumorobot.robotId", robotId);
/* in case there is a open connection */ /* in case there is a open connection */
if (sumorobot && blockHighlight) { if (sumorobot/* && blockHighlight*/) {
/* close the connections */ /* close the connections */
sumorobot.close(); sumorobot.close();
blockHighlight.close(); //blockHighlight.close();
} }
/* connect to the selected robots WebSocket */ /* connect to the selected robots WebSocket */
sumorobot = new Sumorobot("ws://" + robotServer + ":80/p2p/browser/" + robotId + "/"); sumorobot = new Sumorobot("ws://" + robotServer);
sumorobot.send("{'setID': 'browser-" + robotId + "@00000514', 'passwd': 'salakala'}");
/* connect to the other block highlight WebSocket */ /* connect to the other block highlight WebSocket */
blockHighlight = new WebSocket("ws://" + robotServer + ":80/p2p/browser/" + robotId + "-highlight/"); /*blockHighlight = new WebSocket("ws://" + robotServer + ":80/p2p/browser/" + robotId + "-highlight/");
/* when there is a message from the WebSocket */ // when there is a message from the WebSocket
blockHighlight.onmessage = function(evt) { blockHighlight.onmessage = function(evt) {
/* when scope is received */ // when scope is received
if (evt.data.length == 20 && sumostart) { if (evt.data.length == 20 && sumostart) {
workspace.highlightBlock(evt.data); workspace.highlightBlock(evt.data);
lastHighlighted = evt.data; lastHighlighted = evt.data;
} }
}; };*/
/* hide the configuration panel */ /* hide the configuration panel */
$("#panel").hide(); $("#panel").hide();
}); });