added apicheck file

This commit is contained in:
Kevin Froman 2019-10-16 17:32:47 -05:00
parent 560e828c8a
commit d034072704
1 changed files with 27 additions and 0 deletions

View 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)