|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest(); |
|
|
var xhr = new XMLHttpRequest(); |
|
|
|
|
|
|
|
|
xhr.addEventListener("load", function() { |
|
|
xhr.addEventListener("load", function() { |
|
|
var obj = JSON.parse(xhr.responseText); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
var obj = JSON.parse(xhr.responseText); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(xhr.responseText); |
|
|
|
|
|
cb(err); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (obj.error) { |
|
|
if (obj.error) { |
|
|
cb(obj.error); |
|
|
cb(obj.error); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function init() { |
|
|
function init() { |
|
|
|
|
|
console.log("init..."); |
|
|
post("/webevents/register", function(err, res) { |
|
|
post("/webevents/register", function(err, res) { |
|
|
|
|
|
console.log("Init done", err ? "with errors" : "no errors"); |
|
|
|
|
|
|
|
|
// Retry on error |
|
|
// Retry on error |
|
|
if (err) { |
|
|
if (err) { |
|
|
|
|
|
console.log(err); |
|
|
setTimeout(function() { init() }, 2000); |
|
|
setTimeout(function() { init() }, 2000); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function await() { |
|
|
function await() { |
|
|
|
|
|
console.log("await..."); |
|
|
post("/webevents/await/"+key, function(err, res) { |
|
|
post("/webevents/await/"+key, function(err, res) { |
|
|
|
|
|
console.log("Await done", err ? "with errors" : "no errors"); |
|
|
|
|
|
|
|
|
// Retry on error |
|
|
// Retry on error |
|
|
if (err === "ENOTREGISTERED") { |
|
|
if (err === "ENOTREGISTERED") { |