Forgot usefull functions

This commit is contained in:
Silversthorn 2023-08-11 11:32:38 +02:00
parent 372fd04948
commit d172e9cd02
2 changed files with 18 additions and 6 deletions

View File

@ -308,6 +308,12 @@
} }
wsInternal.send(JSON.stringify(message)); wsInternal.send(JSON.stringify(message));
},
close: function (code, reason) {
wsInternal.close(code, reason);
},
getStatus: function () {
return wsInternal.readyState;
} }
} }
} catch (error) { } catch (error) {
@ -323,7 +329,7 @@
// Managing Connexions for Multi Tab opened to reduce bandwith usage // Managing Connexions for Multi Tab opened to reduce bandwith usage
document.addEventListener("visibilitychange", () => { document.addEventListener("visibilitychange", () => {
if (document.hidden) { if (document.visibilityState == "hidden") {
websocketTimeoutId = setTimeout(() => { websocketTimeoutId = setTimeout(() => {
webSocket.close(1000, "Closed due to Inactivity"); webSocket.close(1000, "Closed due to Inactivity");
console.log('%c[Crafty Controller] %cClose Websocket due to Tab not active after 5s', 'font-weight: 900; color: #800080;', 'font-weight: 900; color: #eee;'); console.log('%c[Crafty Controller] %cClose Websocket due to Tab not active after 5s', 'font-weight: 900; color: #800080;', 'font-weight: 900; color: #eee;');

View File

@ -54,9 +54,7 @@
<script src="/static/assets/js/shared/off-canvas.js"></script> <script src="/static/assets/js/shared/off-canvas.js"></script>
<script src="/static/assets/js/shared/hoverable-collapse.js"></script> <script src="/static/assets/js/shared/hoverable-collapse.js"></script>
<script src="/static/assets/js/shared/misc.js"></script> <script src="/static/assets/js/shared/misc.js"></script>
<!-- endinject -->
{% block js %}
<!-- Custom js for this page -->
<script> <script>
/* Script for WebSockets */ /* Script for WebSockets */
let usingWebSockets = false; let usingWebSockets = false;
@ -137,6 +135,12 @@
} }
wsInternal.send(JSON.stringify(message)); wsInternal.send(JSON.stringify(message));
},
close: function (code, reason) {
wsInternal.close(code, reason);
},
getStatus: function () {
return wsInternal.readyState;
} }
} }
} catch (error) { } catch (error) {
@ -152,7 +156,7 @@
// Managing Connexions for Multi Tab opened to reduce bandwith usage // Managing Connexions for Multi Tab opened to reduce bandwith usage
document.addEventListener("visibilitychange", () => { document.addEventListener("visibilitychange", () => {
if (document.hidden) { if (document.visibilityState == "hidden") {
websocketTimeoutId = setTimeout(() => { websocketTimeoutId = setTimeout(() => {
webSocket.close(1000, "Closed due to Inactivity"); webSocket.close(1000, "Closed due to Inactivity");
console.log('%c[Crafty Controller] %cClose Websocket due to Tab not active after 5s', 'font-weight: 900; color: #800080;', 'font-weight: 900; color: #eee;'); console.log('%c[Crafty Controller] %cClose Websocket due to Tab not active after 5s', 'font-weight: 900; color: #800080;', 'font-weight: 900; color: #eee;');
@ -165,7 +169,9 @@
} }
}); });
</script> </script>
<!-- endinject -->
{% block js %}
<!-- Custom js for this page -->
<script> <script>
$(document).ready(function () { $(document).ready(function () {
let login_opacity_div = document.getElementById('login_opacity'); let login_opacity_div = document.getElementById('login_opacity');