added apicheck file
This commit is contained in:
parent
560e828c8a
commit
d034072704
27
static-data/www/shared/main/apicheck.js
Normal file
27
static-data/www/shared/main/apicheck.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
apiOnline = true
|
||||||
|
async function doPing(){
|
||||||
|
out = setTimeout(function(){
|
||||||
|
if (apiOnline){
|
||||||
|
PNotify.notice('Connection lost with API server')
|
||||||
|
}
|
||||||
|
apiOnline = false
|
||||||
|
}, 1000)
|
||||||
|
return await fetch('/ping', {
|
||||||
|
headers: {
|
||||||
|
"token": webpass
|
||||||
|
}})
|
||||||
|
.then((resp) => resp.text()) // Transform the data into text
|
||||||
|
.then(function(resp) {
|
||||||
|
if (!apiOnline){PNotify.success('API server connection reestablished')}
|
||||||
|
apiOnline = true
|
||||||
|
clearTimeout(out)
|
||||||
|
return resp
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let pingCheck = async function(){
|
||||||
|
result = await doPing()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pingCheckInterval = setInterval(function(){pingCheck()}, 3000)
|
Loading…
Reference in New Issue
Block a user