Commit 06/08/2025

This commit is contained in:
2025-08-06 16:35:20 +07:00
parent 662608550b
commit 446f031535
9 changed files with 307 additions and 191 deletions

View File

@@ -1,79 +1,106 @@
$(document).ready(function() {
$(document).ready(function () {
// Your code here
console.log('precordedbroadcast.js is ready!');
//console.log('precordedbroadcast.js is ready!');
const path = window.location.pathname;
const ws = new WebSocket('ws://' + window.location.host + path + '/ws');
for(let i = 1; i<=8; i++){
for (let i = 1; i <= 8; i++) {
$(`#fileM${i}`).val('');
$(`#playM${i}`).prop('disabled', true);
$(`#stopM${i}`).prop('disabled', true);
}
ws.onopen = function() {
console.log('WebSocket connection opened');
ws.onopen = function () {
//console.log('WebSocket connection opened');
$('#indicatorDisconnected').addClass('visually-hidden');
$('#indicatorConnected').removeClass('visually-hidden');
sendCommand({ command: "getMessageConfig" });
setInterval(function() {
setInterval(function () {
sendCommand({ command: "getPlaybackStatus" });
}, 5000);
}, 1000); // every second
};
ws.onmessage = function(event) {
console.log('WebSocket message received:', event.data);
ws.onmessage = function (event) {
//console.log('WebSocket message received:', event.data);
let msg = {};
try {
msg = JSON.parse(event.data);
} catch (e) {
return;
}
if (msg.reply === "getMessageConfig" && msg.data !== undefined) {
const messageConfigdata = msg.data;
console.log('Message Config Data:', messageConfigdata);
for(let i=1; i<=8; i++){
let filetitle = $(`#fileM${i}`);
let playButton = $(`#playM${i}`);
let stopButton = $(`#stopM${i}`);
let fileInput = messageConfigdata[`M${i}`] || '';
filetitle.val(fileInput);
if (fileInput.length>0){
playButton.prop('disabled', false);
stopButton.prop('disabled', false);
playButton.on('click', function() {
let cmd = {
command: "playMessage",
data: `M${i}`
if (msg.reply && msg.reply.length > 0 && msg.data && msg.data.length > 0) {
switch (msg.reply) {
case "playMessage":
if (msg.data !== "success")
{alert(msg.data);}
else{
$('#playbackStatus').text('Playback started');
}
sendCommand(cmd);
});
stopButton.on('click', function() {
let cmd = {
command: "stopMessage",
data: `M${i}`
break;
case "stopMessage":
if (msg.data !== "success")
{alert(msg.data);}
else{
$('#playbackStatus').text('Playback stopped');
}
sendCommand(cmd);
});
} else {
playButton.prop('disabled', true);
stopButton.prop('disabled', true);
break;
case "getMessageConfig":
const messageConfigdata = JSON.parse(msg.data);
//console.log('Message Config Data:', messageConfigdata);
for (let i = 1; i <= 8; i++) {
let filetitle = $(`#fileM${i}`);
let playButton = $(`#playM${i}`);
let stopButton = $(`#stopM${i}`);
let fileInput = messageConfigdata[`M${i}`];
if (fileInput && fileInput.length > 0) {
filetitle.text(fileInput);
playButton.prop('disabled', false);
stopButton.prop('disabled', false);
playButton.removeClass('invisible');
stopButton.removeClass('invisible');
playButton.on('click', function () {
let cmd = {
command: "playMessage",
data: `M${i}`
}
sendCommand(cmd);
});
stopButton.on('click', function () {
let cmd = {
command: "stopMessage",
data: `M${i}`
}
sendCommand(cmd);
});
} else {
filetitle.text('Not configured');
playButton.addClass('invisible');
stopButton.addClass('invisible');
}
}
break;
case "getPlaybackStatus":
$('#playbackStatus').text(msg.data);
break;
}
}
} else if (msg.reply === "getPlaybackStatus" && msg.data !== undefined && msg.data.length > 0) {
const playbackData = msg.data;
$('#playbackStatus').text(playbackData.status);
}
};
ws.onclose = function() {
console.log('WebSocket connection closed');
ws.onclose = function () {
//console.log('WebSocket connection closed');
$('#indicatorDisconnected').removeClass('visually-hidden');
$('#indicatorConnected').addClass('visually-hidden');
};
ws.onerror = function(error) {
ws.onerror = function (error) {
console.error('WebSocket error:', error);
};