mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-07-31 09:19:16 +02:00
bugfixes, refactor, code removal
This commit is contained in:
+18
-33
@@ -1,57 +1,42 @@
|
||||
var Stream;
|
||||
var DefaultVolume = 0.5;
|
||||
const DefaultVolume = 0.5;
|
||||
let Stream;
|
||||
|
||||
function Init(_ev) {
|
||||
// Load default settings
|
||||
var settings = new _3LAS_Settings();
|
||||
if (typeof RtcConfig == 'undefined')
|
||||
RtcConfig = {};
|
||||
settings.WebRTC.RtcConfig = RtcConfig;
|
||||
if (typeof SocketPort != 'undefined')
|
||||
settings.SocketPort = SocketPort;
|
||||
if (typeof SocketPath != 'undefined')
|
||||
settings.SocketPath = SocketPath;
|
||||
if (typeof AudioTagId == 'undefined')
|
||||
settings.WebRTC.AudioTag = null;
|
||||
else
|
||||
settings.WebRTC.AudioTag = document.getElementById(AudioTagId);
|
||||
try {
|
||||
const settings = new _3LAS_Settings();
|
||||
Stream = new _3LAS(null, settings);
|
||||
}
|
||||
catch (_ex) {
|
||||
console.log(_ex);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return;
|
||||
}
|
||||
|
||||
Stream.ConnectivityCallback = OnConnectivityCallback;
|
||||
$(".playbutton").on('click', OnPlayButtonClick);
|
||||
$("#volumeSlider").on("change", updateVolume);
|
||||
$("#volumeSlider").on("input", updateVolume);
|
||||
}
|
||||
|
||||
function OnConnectivityCallback(isConnected) {
|
||||
if (isConnected) {
|
||||
Stream.Volume = 1.0;
|
||||
}
|
||||
Stream.Volume = isConnected ? 1.0 : DefaultVolume;
|
||||
}
|
||||
|
||||
function OnPlayButtonClick(_ev) {
|
||||
try {
|
||||
if (Stream.ConnectivityFlag) {
|
||||
Stream.Stop();
|
||||
$('.playbutton').find('.fa-solid').removeClass('fa-pause').addClass('fa-play');
|
||||
} else {
|
||||
Stream.Start();
|
||||
$('.playbutton').find('.fa-solid').removeClass('fa-play').addClass('fa-stop');
|
||||
$('.playbutton').addClass('bg-gray');
|
||||
$('.playbutton').prop('disabled', true);
|
||||
|
||||
setTimeout(function() {
|
||||
$('.playbutton').removeClass('bg-gray');
|
||||
$('.playbutton').prop('disabled', false);
|
||||
const $playbutton = $('.playbutton');
|
||||
$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);
|
||||
}
|
||||
}
|
||||
catch (_ex) {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function updateVolume() {
|
||||
Stream.Volume = $(this).val();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user