This commit is contained in:
Dmitry Borisenko
2021-12-06 01:21:55 +01:00
parent 15eb165446
commit 75f057f67a

View File

@@ -161,6 +161,37 @@
}); });
} }
// Make the function wait until the connection is made...
//function waitForSocketConnection(socket, callback) {
// setTimeout(function () {
// if (socket.readyState === 1) {
// console.log("Connection is made");
// if (callback != null) {
// callback();
// }
// } else {
// console.log("wait for connection...");
// waitForSocketConnection(socket, callback);
// }
// }, 5); // wait 5 milisecond for the connection...
//}
var reconnectTimer;
function tryReconnect() {
reconnectTimer = setInterval(reconnect, 3000);
}
function reconnect() {
if (socket[0].readyState == 1) {
console.log("web socket connected");
} else {
console.log("Try reconnect to web socket");
wsConnect();
}
}
function myStopFunction() {
clearInterval(reconnectTimer);
}
const syntaxHighlight = (json) => { const syntaxHighlight = (json) => {
try { try {
json = JSON.stringify(JSON.parse(json), null, 4); json = JSON.stringify(JSON.parse(json), null, 4);
@@ -198,6 +229,7 @@
console.log("mounted"); console.log("mounted");
wsConnect(); wsConnect();
findNewPage(); findNewPage();
tryReconnect();
}); });
function wigetsUpdate() { function wigetsUpdate() {
@@ -232,7 +264,9 @@
<main> <main>
<div class="fixed m-0 h-10 w-full bg-gray-100 shadow-md"> <div class="fixed m-0 h-10 w-full bg-gray-100 shadow-md">
<b class="text-center" /> <div class="flex justify-end content-center px-6 py-1">
<svg class="h-8 w-8 {socketConnected == true ? 'text-green-500' : 'text-red-500'}" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" /> <path d="M7 18a4.6 4.4 0 0 1 0 -9h0a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-12" /></svg>
</div>
</div> </div>
<input id="menu__toggle" type="checkbox" /> <input id="menu__toggle" type="checkbox" />
@@ -303,11 +337,13 @@
</Route> </Route>
<Route path="/utilities" /> <Route path="/utilities" />
<Route path="/log"> <Route path="/log">
<Card title={"Лог"}> <div class="flex justify-center w-2/3">
{#each messages as message, i} <Card title={"Лог"}>
<h2>{message.msg}</h2> {#each messages as message, i}
{/each} <div class={message.msg.toString().includes("[E]") ? "text-red-500" : "text-black"}>{message.msg}</div>
</Card> {/each}
</Card>
</div>
</Route> </Route>
<Route path="/about" /> <Route path="/about" />
</div> </div>