You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-27 14:33:52 +01:00
Merge pull request #89 from AmateurAudioDude/fixes/v1.3.0.1-serialport-reconnect-fixes
Fixes/v1.3.0.1 serialport reconnect fixes - 4 files
This commit is contained in:
@@ -425,6 +425,18 @@ function handleData(wss, receivedData, rdsWss) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Serialport retry code when port is open but communication is lost (additional code in index.js)
|
||||||
|
isSerialportAlive = true;
|
||||||
|
lastFrequencyAlive = '87.500';
|
||||||
|
setInterval(() => {
|
||||||
|
lastFrequencyAlive = initialData.freq;
|
||||||
|
// Activate serialport retry if handleData has not been executed for over 10 seconds
|
||||||
|
if (((Date.now() - lastUpdateTime) > 8000) && !isSerialportRetrying && serverConfig.xdrd.wirelessConnection === false) {
|
||||||
|
isSerialportAlive = false;
|
||||||
|
isSerialportRetrying = true;
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
function showOnlineUsers(currentUsers) {
|
function showOnlineUsers(currentUsers) {
|
||||||
dataToSend.users = currentUsers;
|
dataToSend.users = currentUsers;
|
||||||
initialData.users = currentUsers;
|
initialData.users = currentUsers;
|
||||||
|
|||||||
@@ -128,6 +128,28 @@ function checkIPv6Support(callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Serialport retry code when port is open but communication is lost (additional code in datahandler.js)
|
||||||
|
isSerialportRetrying = false;
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if (!isSerialportAlive && serverConfig.xdrd.wirelessConnection === false) {
|
||||||
|
isSerialportAlive = true;
|
||||||
|
isSerialportRetrying = true;
|
||||||
|
if (serialport && serialport.isOpen) {
|
||||||
|
logWarn('Communication lost from ' + serverConfig.xdrd.comPort + ', force closing serialport.');
|
||||||
|
setTimeout(() => {
|
||||||
|
serialport.close((err) => {
|
||||||
|
if (err) {
|
||||||
|
logError('Error closing serialport: ', err.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
logWarn('Communication lost from ' + serverConfig.xdrd.comPort + '.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
// Serial Connection
|
// Serial Connection
|
||||||
function connectToSerial() {
|
function connectToSerial() {
|
||||||
if (serverConfig.xdrd.wirelessConnection === false) {
|
if (serverConfig.xdrd.wirelessConnection === false) {
|
||||||
@@ -152,6 +174,7 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logInfo('Using COM device: ' + serverConfig.xdrd.comPort);
|
logInfo('Using COM device: ' + serverConfig.xdrd.comPort);
|
||||||
|
isSerialportAlive = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
serialport.write('x\n');
|
serialport.write('x\n');
|
||||||
}, 3000);
|
}, 3000);
|
||||||
@@ -165,9 +188,12 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
|||||||
serialport.write('T' + Math.round(serverConfig.defaultFreq * 1000) + '\n');
|
serialport.write('T' + Math.round(serverConfig.defaultFreq * 1000) + '\n');
|
||||||
dataHandler.initialData.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
dataHandler.initialData.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
||||||
dataHandler.dataToSend.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
dataHandler.dataToSend.freq = Number(serverConfig.defaultFreq).toFixed(3);
|
||||||
|
} else if (lastFrequencyAlive && isSerialportRetrying) { // Serialport retry code when port is open but communication is lost
|
||||||
|
serialport.write('T' + (lastFrequencyAlive * 1000) + '\n');
|
||||||
} else {
|
} else {
|
||||||
serialport.write('T87500\n');
|
serialport.write('T87500\n');
|
||||||
}
|
}
|
||||||
|
isSerialportRetrying = false;
|
||||||
|
|
||||||
serialport.write('A0\n');
|
serialport.write('A0\n');
|
||||||
serialport.write('F-1\n');
|
serialport.write('F-1\n');
|
||||||
@@ -192,6 +218,7 @@ if (serverConfig.xdrd.wirelessConnection === false) {
|
|||||||
serialport.on('close', () => {
|
serialport.on('close', () => {
|
||||||
logWarn('Disconnected from ' + serverConfig.xdrd.comPort + '. Attempting to reconnect.');
|
logWarn('Disconnected from ' + serverConfig.xdrd.comPort + '. Attempting to reconnect.');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
isSerialportRetrying = true;
|
||||||
connectToSerial();
|
connectToSerial();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
var audioStreamRestartInterval;
|
||||||
var elapsedTimeConnectionWatchdog;
|
var elapsedTimeConnectionWatchdog;
|
||||||
var _3LAS_Settings = /** @class */ (function () {
|
var _3LAS_Settings = /** @class */ (function () {
|
||||||
function _3LAS_Settings() {
|
function _3LAS_Settings() {
|
||||||
@@ -48,6 +49,22 @@ var _3LAS = /** @class */ (function () {
|
|||||||
this.ConnectivityFlag = false;
|
this.ConnectivityFlag = false;
|
||||||
this.Stop(); // Attempt to mitigate the 0.5x speed/multiple stream bug
|
this.Stop(); // Attempt to mitigate the 0.5x speed/multiple stream bug
|
||||||
|
|
||||||
|
// Restart audio stream if radio data connection was reestablished
|
||||||
|
// to prevent stuttering audio in some cases
|
||||||
|
if (audioStreamRestartInterval) {
|
||||||
|
clearInterval(audioStreamRestartInterval);
|
||||||
|
}
|
||||||
|
audioStreamRestartInterval = setInterval(() => {
|
||||||
|
if (requiresAudioStreamRestart) {
|
||||||
|
requiresAudioStreamRestart = false;
|
||||||
|
if (Stream) {
|
||||||
|
this.Stop();
|
||||||
|
this.Start();
|
||||||
|
console.log("Audio stream restarted after radio data loss.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
// Stream connection watchdog monitors mp3 frames
|
// Stream connection watchdog monitors mp3 frames
|
||||||
console.log("Stream connection watchdog active.");
|
console.log("Stream connection watchdog active.");
|
||||||
let intervalReconnectWatchdog = setInterval(() => {
|
let intervalReconnectWatchdog = setInterval(() => {
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
//FMLIST logging
|
//FMLIST logging
|
||||||
$('#log-fmlist').on('click', function() {
|
$('#log-fmlist').on('click', function() {
|
||||||
console.log('asdfdasf');
|
//console.log('FMLIST');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: './log_fmlist',
|
url: './log_fmlist',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -284,6 +284,18 @@ function sendPingRequest() {
|
|||||||
console.warn("Main/UI WebSocket closed during reconnection. Will attempt to reconnect...");
|
console.warn("Main/UI WebSocket closed during reconnection. Will attempt to reconnect...");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (connectionLost) {
|
||||||
|
if (dataTimeout == dataTimeoutPrevious) {
|
||||||
|
connectionLost = true;
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.socket.close(1000, 'Normal closure'); // Force reconnection to unfreeze browser UI
|
||||||
|
}, 8000); // Timeout must be higher than TIMEOUT_DURATION
|
||||||
|
connectionLost = false;
|
||||||
|
requiresAudioStreamRestart = true;
|
||||||
|
console.log("Radio data restored.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Automatic UI resume on WebSocket reconnect
|
// Automatic UI resume on WebSocket reconnect
|
||||||
@@ -298,7 +310,9 @@ function handleWebSocketMessage(event) {
|
|||||||
|
|
||||||
parsedData = JSON.parse(event.data);
|
parsedData = JSON.parse(event.data);
|
||||||
|
|
||||||
|
resetDataTimeout();
|
||||||
updatePanels(parsedData);
|
updatePanels(parsedData);
|
||||||
|
|
||||||
const sum = signalData.reduce((acc, strNum) => acc + parseFloat(strNum), 0);
|
const sum = signalData.reduce((acc, strNum) => acc + parseFloat(strNum), 0);
|
||||||
const averageSignal = sum / signalData.length;
|
const averageSignal = sum / signalData.length;
|
||||||
data.push(averageSignal);
|
data.push(averageSignal);
|
||||||
@@ -455,12 +469,18 @@ function updateCanvas(parsedData, signalChart) {
|
|||||||
|
|
||||||
let reconnectTimer = null;
|
let reconnectTimer = null;
|
||||||
let dataTimeout = null;
|
let dataTimeout = null;
|
||||||
|
let dataTimeoutPrevious = null;
|
||||||
|
let connectionLost = false;
|
||||||
|
let requiresAudioStreamRestart = false;
|
||||||
|
|
||||||
const TIMEOUT_DURATION = 5000; // 5 seconds timeout for lost connection
|
const TIMEOUT_DURATION = 5000; // 5 seconds timeout for lost connection
|
||||||
|
|
||||||
const resetDataTimeout = () => {
|
const resetDataTimeout = () => {
|
||||||
clearTimeout(dataTimeout);
|
clearTimeout(dataTimeout);
|
||||||
dataTimeout = setTimeout(() => {
|
dataTimeout = setTimeout(() => {
|
||||||
sendToast('warning', 'Connection lost', 'Attempting to reconnect...', false, false);
|
sendToast('warning', 'Connection lost', 'Attempting to reconnect...', false, false);
|
||||||
|
connectionLost = true;
|
||||||
|
dataTimeoutPrevious = dataTimeout;
|
||||||
}, TIMEOUT_DURATION);
|
}, TIMEOUT_DURATION);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user