Refactoring

This commit is contained in:
0xee 2019-11-10 13:04:32 +01:00
parent 1de334592b
commit 05616f5ad5

View File

@ -1,9 +1,9 @@
// Called after form input is processed // Called after form input is processed
function startConnect() { function startConnect() {
if (connecting) { if (window.connecting) {
return; return;
} }
connecting = true; window.connecting = true;
// Generate a random client ID // Generate a random client ID
clientId = navigator.userAgent + "-" + parseInt(Math.random() * 1000000); clientId = navigator.userAgent + "-" + parseInt(Math.random() * 1000000);
document.getElementById("wrapper").classList.add("wrapper-error"); document.getElementById("wrapper").classList.add("wrapper-error");
@ -29,6 +29,13 @@ function startConnect() {
showConnectionModal(); 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) { function log(msg) {
console.log(msg); console.log(msg);
document.getElementById("messages").innerHTML += '<span>' + msg + '</span><br/>'; document.getElementById("messages").innerHTML += '<span>' + msg + '</span><br/>';
@ -37,7 +44,7 @@ function log(msg) {
function checkConnection(){ function checkConnection(){
clearTimeout(connectionCheckTimeout); clearTimeout(connectionCheckTimeout);
if (!client.isConnected()) { if (!client.isConnected()) {
connecting = false; window.connecting = false;
//log("Error connecting to broker"); //log("Error connecting to broker");
startConnect(); startConnect();
} }
@ -45,7 +52,7 @@ function checkConnection(){
// Called when the client connects // Called when the client connects
function onConnect() { function onConnect() {
connecting = false; window.connecting = false;
clearTimeout(connectionCheckTimeout); clearTimeout(connectionCheckTimeout);
hideConnectionModal(); hideConnectionModal();
document.getElementById("wrapper").classList.remove("wrapper-error"); document.getElementById("wrapper").classList.remove("wrapper-error");
@ -139,7 +146,7 @@ function updateContents(id, value) {
function init(brokerUri) { function init(brokerUri) {
window.brokerUri = brokerUri window.brokerUri = brokerUri
connecting = false; window.connecting = false;
startConnect(); startConnect();
var sliders = document.getElementsByClassName("slider"); var sliders = document.getElementsByClassName("slider");