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
Several fixes
* Fixed rare unprompted auto-restart stream bug (bkram) [/web/js/3las/main.js] * Fixed multiple tooltip bug while RDS PS is tentatively loaded [/web/js/main.js] * Changed copying of plugin files to symlinks (junction for Windows) [/server/plugins.js] * Auto-reconnect audio stream on restored/changed internet connection [/web/js/3las/3las.js] * Main WebSocket connection can be shared with plugins [/web/js/websocket.js] [/web/index.ejs]
This commit is contained in:
@@ -1,43 +1,69 @@
|
||||
const DefaultVolume = 0.5;
|
||||
let Stream;
|
||||
let shouldReconnect = true;
|
||||
let newVolumeGlobal = 1;
|
||||
|
||||
function Init(_ev) {
|
||||
try {
|
||||
const settings = new _3LAS_Settings();
|
||||
if (!Stream) { // Ensure Stream is not re-initialized
|
||||
Stream = new _3LAS(null, settings);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return;
|
||||
}
|
||||
|
||||
Stream.ConnectivityCallback = OnConnectivityCallback;
|
||||
$(".playbutton").off('click').on('click', OnPlayButtonClick); // Ensure only one event handler is attached
|
||||
$("#volumeSlider").off("input").on("input", updateVolume); // Ensure only one event handler is attached
|
||||
}
|
||||
|
||||
function createStream() {
|
||||
try {
|
||||
const settings = new _3LAS_Settings();
|
||||
Stream = new _3LAS(null, settings);
|
||||
Stream.ConnectivityCallback = OnConnectivityCallback;
|
||||
} catch (error) {
|
||||
console.error("Initialization Error: ", error);
|
||||
}
|
||||
}
|
||||
|
||||
function destroyStream() {
|
||||
if (Stream) {
|
||||
Stream.Stop();
|
||||
Stream = null;
|
||||
}
|
||||
}
|
||||
|
||||
function OnConnectivityCallback(isConnected) {
|
||||
Stream.Volume = isConnected ? 1.0 : DefaultVolume;
|
||||
console.log("Connectivity changed:", isConnected);
|
||||
if (Stream) {
|
||||
Stream.Volume = isConnected ? 1.0 : DefaultVolume;
|
||||
} else {
|
||||
console.warn("Stream is not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
function OnPlayButtonClick(_ev) {
|
||||
const $playbutton = $('.playbutton');
|
||||
$playbutton.find('.fa-solid').toggleClass('fa-play fa-stop');
|
||||
|
||||
if (Stream.ConnectivityFlag) {
|
||||
Stream.Stop();
|
||||
if (Stream) {
|
||||
console.log("Stopping stream...");
|
||||
shouldReconnect = false;
|
||||
destroyStream();
|
||||
$playbutton.find('.fa-solid').toggleClass('fa-stop fa-play');
|
||||
} else {
|
||||
console.log("Starting stream...");
|
||||
shouldReconnect = true;
|
||||
createStream();
|
||||
Stream.Start();
|
||||
$playbutton.addClass('bg-gray').prop('disabled', true);
|
||||
setTimeout(() => {
|
||||
$playbutton.removeClass('bg-gray').prop('disabled', false);
|
||||
}, 3000);
|
||||
$playbutton.find('.fa-solid').toggleClass('fa-play fa-stop');
|
||||
}
|
||||
$playbutton.addClass('bg-gray').prop('disabled', true);
|
||||
setTimeout(() => {
|
||||
$playbutton.removeClass('bg-gray').prop('disabled', false);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function updateVolume() {
|
||||
Stream.Volume = $(this).val();
|
||||
if (Stream) {
|
||||
const newVolume = $(this).val();
|
||||
newVolumeGlobal = newVolume;
|
||||
console.log("Volume updated to:", newVolume);
|
||||
Stream.Volume = newVolume;
|
||||
} else {
|
||||
console.warn("Stream is not initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(Init);
|
||||
$(document).ready(Init);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user