From d034072704508789bf3f130fa15e70ee3762bba5 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 16 Oct 2019 17:32:47 -0500 Subject: [PATCH] added apicheck file --- static-data/www/shared/main/apicheck.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 static-data/www/shared/main/apicheck.js diff --git a/static-data/www/shared/main/apicheck.js b/static-data/www/shared/main/apicheck.js new file mode 100644 index 00000000..9a3b59f1 --- /dev/null +++ b/static-data/www/shared/main/apicheck.js @@ -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)