commit 21/11/2025

This commit is contained in:
2025-11-21 13:33:37 +07:00
parent 46be98363a
commit 421ed661ad
7 changed files with 165 additions and 133 deletions

View File

@@ -55,7 +55,6 @@ function UpdateStreamerCard(values) {
const v = Number(value ?? 0);
const pct = Math.max(0, Math.min(100, Math.round((v / max) * 100)));
//if (index!==1) return; // only update index 1 for testing
//console.log(`setProgress: index=${index}, value=${v}, pct=${pct}`);
$bar
.attr('aria-valuenow', v) // semantic value
.css('width', pct + '%') // visual width
@@ -162,7 +161,6 @@ function fill_automaticqueuetablebody(vv) {
if (!Array.isArray(vv) || vv.length === 0) return;
vv.forEach(item => {
// fill index and description columns using item properties
//console.log("fill_automaticqueuetablebody: item", item);
$('#automaticqueuetable').append(`<tr>
<td>${item.index}</td>
<td>${item.date_Time}</td>
@@ -218,7 +216,6 @@ function reloadAutomaticQueue(APIURL = "QueueTable/") {
function RemovePagingQueueByIndex(index, APIURL = "QueuePaging/") {
fetchAPI(APIURL + "DeleteByIndex/" + index, "DELETE", {}, null, (okdata) => {
console.log("RemovePagingQueueByIndex: okdata", okdata);
reloadPagingQueue(APIURL);
}, (errdata) => {
console.log("RemovePagingQueueByIndex: errdata", errdata);
@@ -227,7 +224,6 @@ function RemovePagingQueueByIndex(index, APIURL = "QueuePaging/") {
function RemoveAutomaticQueueByIndex(index, APIURL = "QueueTable/") {
fetchAPI(APIURL + "DeleteByIndex/" + index, "DELETE", {}, null, (okdata) => {
console.log("RemoveAutomaticQueueByIndex: okdata", okdata);
reloadAutomaticQueue(APIURL);
}, (errdata) => {
console.log("RemoveAutomaticQueueByIndex: errdata", errdata);
@@ -258,16 +254,16 @@ function GetListeningZones() {
* @param {Function} cbFail callback function on failure
*/
function LiveAudioCommand(command, bz, cbOK = null, cbFail = null) {
function raise_cbOK(value=null){
function raise_cbOK(value = null) {
if (cbOK) cbOK(value);
}
function raise_cbFail(value){
function raise_cbFail(value) {
if (cbFail) cbFail(value);
}
if (command && command.length>0){
if (bz && bz.length>0){
if (command === 'Open' || command === 'Close'){
if (command && command.length > 0) {
if (bz && bz.length > 0) {
if (command === 'Open' || command === 'Close') {
let url = `/api/LiveAudio`;
let payload = {
method: 'POST',
@@ -281,22 +277,19 @@ function LiveAudioCommand(command, bz, cbOK = null, cbFail = null) {
};
fetch(url, payload)
.then(response => {
console.log(`Fetch response for Live Audio Command ${command}:`, JSON.stringify(response));
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(`Live Audio Command ${command} for Broadcast Zone: ${bz} executed on server.`, data);
raise_cbOK(data);
})
.catch(error => {
console.log(`Error executing Live Audio Command ${command} for Broadcast Zone: ${bz} on server. ${error}`);
raise_cbFail(error);
});
} else raise_cbFail("LiveAudioCommand: Unknown command "+command);
} else raise_cbFail("LiveAudioCommand: Unknown command " + command);
} else raise_cbFail("LiveAudioCommand: Broadcast Zone is empty");
} else raise_cbFail("LiveAudioCommand: command is empty");
}
@@ -308,7 +301,6 @@ let streamws = null;
let mediasource = null;
$(document).ready(function () {
console.log("overview.js loaded");
GetListeningZones();
@@ -316,8 +308,10 @@ $(document).ready(function () {
let bz = $("#listenzone").val();
let $icon = $(this).find('svg');
if ($icon.hasClass('fa-stop')) {
console.log("Stopping Live Audio for Broadcast Zone:", bz);
LiveAudioCommand('Close', bz, (okdata) =>{
LiveAudioCommand('Close', bz, (okdata) => {
if (okdata.message && okdata.message.length > 0) {
console.log("Live Audio Session Closed:", okdata.message);
}
$icon.toggleClass('fa-stop fa-play');
$("#listenzone").prop('disabled', false);
if (streamws) {
@@ -331,34 +325,37 @@ $(document).ready(function () {
let audio = document.getElementById('listenaudio');
audio.src = "";
}, (errdata) =>{
}, (errdata) => {
alert("Error stopping Live Audio: " + errdata);
});
} else {
console.log("Starting Live Audio for Broadcast Zone:", bz);
LiveAudioCommand('Open', bz, (okdata) =>{
LiveAudioCommand('Open', bz, (okdata) => {
if (okdata.message && okdata.message.length > 0) {
let uuid = okdata.message;
console.log("Live Audio Session UUID:", uuid);
}
$icon.toggleClass('fa-stop fa-play');
$("#listenzone").prop('disabled', true);
streamws = new WebSocket(`ws://${window.location.host}/LiveAudio/ws`);
streamws = new WebSocket(`ws://${window.location.host}/api/LiveAudio/ws`);
streamws.binaryType = 'arraybuffer';
mediasource = new MediaSource();
let audio = document.getElementById('listenaudio');
audio.src = URL.createObjectURL(mediasource);
mediasource.addEventListener('sourceopen', () => {
const sourceBuffer = mediasource.addSourceBuffer('audio/mpeg; codecs="mp3"');
streamws.binaryType = 'arraybuffer';
const sourceBuffer = mediasource.addSourceBuffer('audio/mpeg');
streamws.onmessage = (event) => {
if (event.data instanceof ArrayBuffer) {
const chunk = new Uint8Array(event.data);
sourceBuffer.appendBuffer(chunk);
}
}
};
});
}, (errdata) =>{
}, (errdata) => {
alert("Error starting Live Audio: " + errdata);
});
}
});
$('#clearpagingqueue').off('click').on('click', function () {
DoClear("QueuePaging/", "Paging Queue", (okdata) => {
@@ -445,7 +442,6 @@ $(document).ready(function () {
switch (cmd) {
case "getPagingQueue":
let pq = JSON.parse(data);
//console.log("getPagingQueue:", pq);
window.PagingQueue = [];
if (Array.isArray(pq) && pq.length > 0) {
window.PagingQueue.push(...pq);
@@ -454,7 +450,6 @@ $(document).ready(function () {
break;
case "getAASQueue":
let aq = JSON.parse(data);
//console.log("getAASQueue:", aq);
window.QueueTable = [];
if (Array.isArray(aq) && aq.length > 0) {
window.QueueTable.push(...aq);