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

Merge pull request #132 from AmateurAudioDude/fixes/v1.3.6.1-reconnect-fixes

Fixes/v1.3.6.1 reconnect fixes
This commit is contained in:
Marek Farkaš
2025-04-22 13:08:48 +02:00
committed by GitHub
2 changed files with 20 additions and 8 deletions

View File

@@ -2,7 +2,8 @@ var audioStreamRestartInterval;
var elapsedTimeConnectionWatchdog; 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 = location.hostname ? location.hostname : "127.0.0.1";
this.SocketPort = location.port;
this.SocketPath = "/"; this.SocketPath = "/";
this.Fallback = new Fallback_Settings(); this.Fallback = new Fallback_Settings();
} }
@@ -69,14 +70,14 @@ var _3LAS = /** @class */ (function () {
console.log("Stream connection watchdog active."); console.log("Stream connection watchdog active.");
let intervalReconnectWatchdog = setInterval(() => { let intervalReconnectWatchdog = setInterval(() => {
if (Stream) { if (Stream) {
var endTimeConnectionWatchdog = performance.now(); let endTimeConnectionWatchdog = performance.now();
elapsedTimeConnectionWatchdog = endTimeConnectionWatchdog - window.startTimeConnectionWatchdog; elapsedTimeConnectionWatchdog = endTimeConnectionWatchdog - window.startTimeConnectionWatchdog;
//console.log(`Stream frame elapsed time: ${elapsedTimeConnectionWatchdog} ms`); //console.log(`Stream frame elapsed time: ${parseInt(elapsedTimeConnectionWatchdog)} ms`);
if (elapsedTimeConnectionWatchdog > 2000 && shouldReconnect) { if (elapsedTimeConnectionWatchdog > 2000 && shouldReconnect) {
clearInterval(intervalReconnectWatchdog); clearInterval(intervalReconnectWatchdog);
setTimeout(() => { setTimeout(() => {
clearInterval(intervalReconnectWatchdog); clearInterval(intervalReconnectWatchdog);
console.log("Unstable internet connection detected, reconnecting (" + elapsedTimeConnectionWatchdog + " ms)..."); console.log("Unstable internet connection detected, reconnecting... (" + parseInt(elapsedTimeConnectionWatchdog) + " ms)");
this.Stop(); this.Stop();
this.Start(); this.Start();
}, 2000); }, 2000);
@@ -93,10 +94,10 @@ var _3LAS = /** @class */ (function () {
this.WakeLock.Begin(); this.WakeLock.Begin();
try { try {
if (window.location.protocol === 'https:') { if (window.location.protocol === 'https:') {
this.WebSocket = new WebSocketClient(this.Logger, 'wss://' + this.Settings.SocketHost + ':' + location.port.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this)); this.WebSocket = new WebSocketClient(this.Logger, 'wss://' + this.Settings.SocketHost + ':' + this.Settings.SocketPort.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
} }
else { else {
this.WebSocket = new WebSocketClient(this.Logger, 'ws://' + this.Settings.SocketHost + ':' + location.port.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this)); this.WebSocket = new WebSocketClient(this.Logger, 'ws://' + this.Settings.SocketHost + ':' + this.Settings.SocketPort.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
} }
this.Logger.Log("Init of WebSocketClient succeeded"); this.Logger.Log("Init of WebSocketClient succeeded");
this.Logger.Log("Trying to connect to server."); this.Logger.Log("Trying to connect to server.");

View File

@@ -103,18 +103,29 @@ var WakeLock = /** @class */ (function () {
try { try {
navigator.wakeLock.request("screen").then(function (obj) { navigator.wakeLock.request("screen").then(function (obj) {
_this.Logger.Log("WakeLock request successful. Lock acquired."); _this.Logger.Log("WakeLock request successful. Lock acquired.");
_this.LockElement = obj; _this.LockElement = obj; // Not an audio/video element
console.log("WakeLock request successful.");
}, function () { }, function () {
_this.Logger.Log("WakeLock request failed."); _this.Logger.Log("WakeLock request failed.");
console.log("WakeLock request failed.");
}); });
} }
catch (err) { catch (err) {
this.Logger.Log("WakeLock request failed."); this.Logger.Log("WakeLock request failed.");
console.log("WakeLock request failed.");
} }
} }
else { else {
this.Logger.Log("WakeLock video loop started."); this.Logger.Log("WakeLock video loop started.");
this.LockElement.play();
// Ensure it's an audio/video element before calling play()
if (_this.LockElement instanceof HTMLMediaElement) {
_this.LockElement.play().catch(err => {
console.error("LockElement failed:", err);
});
} else {
console.warn("LockElement not a media element or already assigned.");
}
} }
}; };
WakeLock.AddSourceToVideo = function (element, type, dataURI) { WakeLock.AddSourceToVideo = function (element, type, dataURI) {