1
0
mirror of https://github.com/KubaPro010/fm-dx-webserver.git synced 2026-02-26 22:13:53 +01:00

add per-ip limit

This commit is contained in:
Amateur Audio Dude
2025-07-07 22:38:20 +10:00
committed by GitHub
parent 4ece21d513
commit 2ab7dd33dd
3 changed files with 101 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ var parsedData, signalChart, previousFreq;
var data = [];
var signalData = [];
let updateCounter = 0;
let lastReconnectAttempt = 0;
let messageCounter = 0; // Count for WebSocket data length returning 0
let messageData = 800; // Initial value anything above 0
let messageLength = 800; // Retain value of messageData until value is updated
@@ -375,10 +376,16 @@ function sendPingRequest() {
messageCounter = 0;
}
// Automatic reconnection on WebSocket close
if (socket.readyState === WebSocket.CLOSED || socket.readyState === WebSocket.CLOSING) {
// Automatic reconnection on WebSocket close with cooldown
const now = Date.now();
if (
(socket.readyState === WebSocket.CLOSED || socket.readyState === WebSocket.CLOSING) &&
(now - lastReconnectAttempt > TIMEOUT_DURATION)
) {
lastReconnectAttempt = now;
socket = new WebSocket(socketAddress);
socket.onopen = () => {
sendToast('info', 'Connected', 'Reconnected successfully!', false, false);
};