Refactoring

master
0xee 2019-11-10 13:04:32 +01:00
parent 1de334592b
commit 05616f5ad5
1 changed files with 12 additions and 5 deletions

View File

@ -1,9 +1,9 @@
// Called after form input is processed
function startConnect() {
if (connecting) {
if (window.connecting) {
return;
}
connecting = true;
window.connecting = true;
// Generate a random client ID
clientId = navigator.userAgent + "-" + parseInt(Math.random() * 1000000);
document.getElementById("wrapper").classList.add("wrapper-error");
@ -29,6 +29,13 @@ function startConnect() {
showConnectionModal();
}
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function log(msg) {
console.log(msg);
document.getElementById("messages").innerHTML += '<span>' + msg + '</span><br/>';
@ -37,7 +44,7 @@ function log(msg) {
function checkConnection(){
clearTimeout(connectionCheckTimeout);
if (!client.isConnected()) {
connecting = false;
window.connecting = false;
//log("Error connecting to broker");
startConnect();
}
@ -45,7 +52,7 @@ function checkConnection(){
// Called when the client connects
function onConnect() {
connecting = false;
window.connecting = false;
clearTimeout(connectionCheckTimeout);
hideConnectionModal();
document.getElementById("wrapper").classList.remove("wrapper-error");
@ -139,7 +146,7 @@ function updateContents(id, value) {
function init(brokerUri) {
window.brokerUri = brokerUri
connecting = false;
window.connecting = false;
startConnect();
var sliders = document.getElementsByClassName("slider");