omlapp/Open Media Library.app/Contents/Resources/static/js/install.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-04 19:41:30 +00:00
function load() {
var base = '//127.0.0.1:9842',
2014-08-12 12:50:56 +00:00
ws = new WebSocket('ws:' + base + '/ws');
ws.onopen = function(event) {
document.location.href = 'http:' + base;
};
ws.onerror = function(event) {
ws.close();
};
ws.onclose = function(event) {
setTimeout(load, 500);
2014-08-04 19:41:30 +00:00
};
};
function update() {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = JSON.parse(this.responseText);
2014-08-07 09:49:59 +00:00
if (response.step) {
var status = response.step;
2014-08-04 19:41:30 +00:00
if (response.progress) {
status = parseInt(response.progress * 100) + '% ' + status;
}
document.getElementById('status').innerHTML = status;
setTimeout(update, 1000);
} else {
document.getElementById('status').innerHTML = "done";
load();
}
};
xhr.onerror = function() {
var status = document.getElementById('status').innerHTML;
if (['done', 'setup'].indexOf(status) == -1) {
document.getElementById('status').innerHTML = "error";
}
load();
}
xhr.open('get', '/status');
xhr.send();
}
update();