You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
Reconnect on loss method based on decoded mp3 frames
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
var elapsedTimeConnectionWatchdog;
|
||||||
var _3LAS_Settings = /** @class */ (function () {
|
var _3LAS_Settings = /** @class */ (function () {
|
||||||
function _3LAS_Settings() {
|
function _3LAS_Settings() {
|
||||||
this.SocketHost = document.location.hostname ? document.location.hostname : "127.0.0.1";
|
this.SocketHost = document.location.hostname ? document.location.hostname : "127.0.0.1";
|
||||||
@@ -47,6 +48,29 @@ 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
|
||||||
|
|
||||||
|
// Stream connection watchdog monitors mp3 frames
|
||||||
|
console.log("Stream connection watchdog active.");
|
||||||
|
let intervalReconnectWatchdog = setInterval(() => {
|
||||||
|
if (Stream) {
|
||||||
|
var endTimeConnectionWatchdog = performance.now();
|
||||||
|
elapsedTimeConnectionWatchdog = endTimeConnectionWatchdog - window.startTimeConnectionWatchdog;
|
||||||
|
//console.log(`Stream frame elapsed time: ${elapsedTimeConnectionWatchdog} ms`);
|
||||||
|
if (elapsedTimeConnectionWatchdog > 2000 && shouldReconnect) {
|
||||||
|
clearInterval(intervalReconnectWatchdog);
|
||||||
|
setTimeout(() => {
|
||||||
|
clearInterval(intervalReconnectWatchdog);
|
||||||
|
console.log("Unstable internet connection detected, reconnecting (" + elapsedTimeConnectionWatchdog + " ms)...");
|
||||||
|
this.Stop();
|
||||||
|
this.Start();
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearInterval(intervalReconnectWatchdog);
|
||||||
|
this.Stop();
|
||||||
|
console.log("Stream connection watchdog inactive.");
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
|
||||||
// This is stupid, but required for Android.... thanks Google :(
|
// This is stupid, but required for Android.... thanks Google :(
|
||||||
if (this.WakeLock)
|
if (this.WakeLock)
|
||||||
this.WakeLock.Begin();
|
this.WakeLock.Begin();
|
||||||
@@ -130,45 +154,6 @@ var _3LAS = /** @class */ (function () {
|
|||||||
if (this.ConnectivityCallback)
|
if (this.ConnectivityCallback)
|
||||||
this.ConnectivityCallback(false);
|
this.ConnectivityCallback(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldReconnect) {
|
|
||||||
if (!this.ConnectivityFlag) {
|
|
||||||
console.log("Initial reconnect attempt...");
|
|
||||||
this.Stop(); // Attempt to mitigate the 0.5x speed/multiple stream bug
|
|
||||||
this.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delay launch of subsequent reconnect attempts by 3 seconds
|
|
||||||
setTimeout(() => {
|
|
||||||
|
|
||||||
let streamReconnecting = false;
|
|
||||||
|
|
||||||
let intervalReconnect = setInterval(() => {
|
|
||||||
if (this.ConnectivityFlag || typeof Stream === 'undefined' || Stream === null) {
|
|
||||||
console.log("Reconnect attempts aborted.");
|
|
||||||
clearInterval(intervalReconnect);
|
|
||||||
} else if (!streamReconnecting) {
|
|
||||||
streamReconnecting = true;
|
|
||||||
console.log("Attempting to restart stream...");
|
|
||||||
this.Stop(); // Attempt to mitigate the 0.5x speed/multiple stream bug
|
|
||||||
this.Start();
|
|
||||||
// Wait for reconnect attempt
|
|
||||||
setTimeout(() => {
|
|
||||||
streamReconnecting = false;
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
// Restore user set volume
|
|
||||||
if (Stream && typeof newVolumeGlobal !== 'undefined' && newVolumeGlobal !== null) {
|
|
||||||
Stream.Volume = newVolumeGlobal;
|
|
||||||
console.log(`User volume restored: ${Math.round(newVolumeGlobal * 100)}%`);
|
|
||||||
}
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
}, 3000);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.Logger.Log("Reconnection is disabled.");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_3LAS.prototype.OnSocketDataReady = function (data) {
|
_3LAS.prototype.OnSocketDataReady = function (data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user