You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
|
|
|
|
wdt = {
|
|
last_wdt_time: 0,
|
|
watchdog_counter: 0
|
|
}
|
|
|
|
pollFileChange = () => {
|
|
setTimeout(() => {
|
|
wdt.watchdog_counter++
|
|
console.log(wdt.watchdog_counter)
|
|
if (wdt.watchdog_counter > 20) {
|
|
return
|
|
}
|
|
ajax({
|
|
type: "GET",
|
|
url: "/watchdog",
|
|
success: (data) => {
|
|
var time = Number(data)
|
|
if (wdt.last_wdt_time == 0) {
|
|
wdt.last_wdt_time = time
|
|
pollFileChange()
|
|
} else if (time > wdt.last_wdt_time) {
|
|
location.reload();
|
|
} else {
|
|
pollFileChange()
|
|
}
|
|
},
|
|
})
|
|
}, 10000)
|
|
}
|
|
|
|
function ajax(setting) {
|
|
if (typeof(shutdown) !== 'undefined') return
|
|
var request = new XMLHttpRequest();
|
|
request.open(setting.type, setting.url, true);
|
|
request.setRequestHeader('Content-Type', setting.dataType)
|
|
request.onload = function(data) {
|
|
if (typeof(shutdown) !== 'undefined') return
|
|
if (this.status >= 200 && this.status < 400) {
|
|
if (setting.success) {
|
|
setting.success(this.response)
|
|
}
|
|
} else {
|
|
if (setting.error) {
|
|
setting.error(this.response)
|
|
}
|
|
}
|
|
}
|
|
request.onerror = function(data) {
|
|
if (typeof(shutdown) !== 'undefined') return
|
|
if (setting.error) {
|
|
setting.error(data)
|
|
}
|
|
}
|
|
if (setting.data) {
|
|
request.send(setting.data)
|
|
} else {
|
|
request.send()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pollFileChange()
|
|
|
|
|
|
|