Commit 06/08/2025
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
// Your initialization code here
|
||||
console.log('setting.js is ready!');
|
||||
//console.log('setting.js is ready!');
|
||||
$('#dropdownM1 button').text('');
|
||||
$('#dropdownM2 button').text('');
|
||||
$('#dropdownM3 button').text('');
|
||||
@@ -23,123 +23,150 @@ $(document).ready(function() {
|
||||
const path = window.location.pathname;
|
||||
const ws = new WebSocket('ws://' + window.location.host + path + '/ws');
|
||||
|
||||
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: "getConfig" });
|
||||
|
||||
};
|
||||
|
||||
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 === "getConfig" && msg.data !== undefined ) {
|
||||
const configData = JSON.parse(msg.data);
|
||||
console.log('Config Data:', configData);
|
||||
$('#zelloUsername').val(configData.zelloUsername || '');
|
||||
$('#zelloPassword').val(configData.zelloPassword || '');
|
||||
$('#zelloChannel').val(configData.zelloChannel || '');
|
||||
if ("community" === configData.zelloServer) {
|
||||
$('#zellocommunity').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
} else if ("work" === configData.zelloServer) {
|
||||
$('#zellowork').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val(configData.zelloWorkNetworkName || '').prop('disabled', false);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
} else if ("enterprise" === configData.zelloServer) {
|
||||
$('#zelloenterprise').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').val(configData.zelloEnterpriseServerDomain || '').prop('disabled', false);
|
||||
}
|
||||
if (msg.reply && msg.reply.length > 0) {
|
||||
switch (msg.reply) {
|
||||
case "getConfig":
|
||||
const configData = JSON.parse(msg.data);
|
||||
//console.log('Config Data:', configData);
|
||||
$('#zelloUsername').val(configData.zelloUsername || '');
|
||||
$('#zelloPassword').val(configData.zelloPassword || '');
|
||||
$('#zelloChannel').val(configData.zelloChannel || '');
|
||||
if ("community" === configData.zelloServer) {
|
||||
$('#zellocommunity').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
} else if ("work" === configData.zelloServer) {
|
||||
$('#zellowork').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val(configData.zelloWorkNetworkName || '').prop('disabled', false);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
} else if ("enterprise" === configData.zelloServer) {
|
||||
$('#zelloenterprise').prop('checked', true);
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').val(configData.zelloEnterpriseServerDomain || '').prop('disabled', false);
|
||||
}
|
||||
|
||||
for (let i = 1; i <= 8; i++) {
|
||||
const dropdownMenu = $(`#dropdownM${i} .dropdown-menu`);
|
||||
const dropdownButton = $(`#dropdownM${i} button`);
|
||||
dropdownMenu.empty();
|
||||
const messages = configData[`MessageList`] || [];
|
||||
messages.forEach((msg, idx) => {
|
||||
const item = $('<a class="dropdown-item" href="#"></a>').text(msg);
|
||||
item.on('click', function() {
|
||||
dropdownButton.text(msg);
|
||||
});
|
||||
dropdownMenu.append(item);
|
||||
});
|
||||
// Set button text to selected message if present
|
||||
if (configData[`m${i}`]) {
|
||||
dropdownButton.text(configData[`m${i}`]);
|
||||
} else {
|
||||
dropdownButton.text('');
|
||||
}
|
||||
for (let i = 1; i <= 8; i++) {
|
||||
const dropdownMenu = $(`#dropdownM${i} .dropdown-menu`);
|
||||
const dropdownButton = $(`#dropdownM${i} button`);
|
||||
dropdownMenu.empty();
|
||||
const messages = configData[`messageList`] || [];
|
||||
messages.forEach((msg, idx) => {
|
||||
const item = $('<a class="dropdown-item" href="#"></a>').text(msg);
|
||||
item.on('click', function () {
|
||||
dropdownButton.text(msg);
|
||||
});
|
||||
dropdownMenu.append(item);
|
||||
});
|
||||
// Set button text to selected message if present
|
||||
if (configData[`m${i}`]) {
|
||||
dropdownButton.text(configData[`m${i}`]);
|
||||
} else {
|
||||
dropdownButton.text('');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "setZelloConfig":
|
||||
if (msg.data === "success") {
|
||||
alert('Zello configuration updated successfully.');
|
||||
} else {
|
||||
alert('Failed to update Zello configuration: ' + msg.data);
|
||||
}
|
||||
sendCommand({ command: "getConfig" }); // Refresh config after update
|
||||
break;
|
||||
case "setMessageConfig":
|
||||
if (msg.data === "success") {
|
||||
alert('Message configuration updated successfully.');
|
||||
} else {
|
||||
alert('Failed to update Message configuration: ' + msg.data);
|
||||
}
|
||||
sendCommand({ command: "getConfig" }); // Refresh config after update
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
$('#zellocommunity').on('click', function() {
|
||||
$('#zellocommunity').on('click', function () {
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
});
|
||||
$('#zellowork').on('click', function() {
|
||||
$('#zellowork').on('click', function () {
|
||||
$('#zelloWorkNetworkName').prop('disabled', false);
|
||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||
});
|
||||
$('#zelloenterprise').on('click', function() {
|
||||
$('#zelloenterprise').on('click', function () {
|
||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||
$('#zelloEnterpriseServerDomain').prop('disabled', false);
|
||||
});
|
||||
|
||||
|
||||
$('#btnApplyZello').on('click', function() {
|
||||
$('#btnApplyZello').on('click', function () {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
let xx = {
|
||||
command: "setZelloConfig"
|
||||
};
|
||||
let data = {
|
||||
command: "setZelloConfig",
|
||||
ZelloUsername: $('#zelloUsername').val(),
|
||||
ZelloPassword: $('#zelloPassword').val(),
|
||||
ZelloChannel: $('#zelloChannel').val(),
|
||||
ZelloServer: $('#zellocommunity').is(':checked') ? 'community' :
|
||||
$('#zellowork').is(':checked') ? 'work' :
|
||||
$('#zelloenterprise').is(':checked') ? 'enterprise' : ''
|
||||
};
|
||||
$('#zellowork').is(':checked') ? 'work' :
|
||||
$('#zelloenterprise').is(':checked') ? 'enterprise' : ''
|
||||
}
|
||||
if ($('#zellowork').is(':checked')) {
|
||||
data.ZelloWorkNetworkName = $('#zelloWorkNetworkName').val();
|
||||
}
|
||||
if ($('#zelloenterprise').is(':checked')) {
|
||||
data.ZelloEnterpriseServerDomain = $('#zelloEnterpriseServerDomain').val();
|
||||
}
|
||||
sendCommand(data);
|
||||
xx.data = JSON.stringify(data);
|
||||
sendCommand(xx);
|
||||
} else {
|
||||
console.warn('WebSocket is not open.');
|
||||
}
|
||||
});
|
||||
$('#btnApplyMessage').on('click', function() {
|
||||
$('#btnApplyMessage').on('click', function () {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
let data = {
|
||||
command: "setMessageConfig",
|
||||
M1: $('#dropdownM1 button').text(),
|
||||
M2: $('#dropdownM2 button').text(),
|
||||
M3: $('#dropdownM3 button').text(),
|
||||
M4: $('#dropdownM4 button').text(),
|
||||
M5: $('#dropdownM5 button').text(),
|
||||
M6: $('#dropdownM6 button').text(),
|
||||
M7: $('#dropdownM7 button').text(),
|
||||
M8: $('#dropdownM8 button').text()
|
||||
data: JSON.stringify({
|
||||
M1: $('#dropdownM1 button').text(),
|
||||
M2: $('#dropdownM2 button').text(),
|
||||
M3: $('#dropdownM3 button').text(),
|
||||
M4: $('#dropdownM4 button').text(),
|
||||
M5: $('#dropdownM5 button').text(),
|
||||
M6: $('#dropdownM6 button').text(),
|
||||
M7: $('#dropdownM7 button').text(),
|
||||
M8: $('#dropdownM8 button').text()
|
||||
})
|
||||
|
||||
};
|
||||
sendCommand(data);
|
||||
} else {
|
||||
@@ -147,7 +174,7 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
|
||||
$('#btnUploadContent').on('click', function() {
|
||||
$('#btnUploadContent').on('click', function () {
|
||||
const fileInput = document.getElementById('chosenFile');
|
||||
if (!fileInput || !fileInput.files.length) {
|
||||
alert('Please select a file to upload.');
|
||||
@@ -161,17 +188,18 @@ $(document).ready(function() {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
alert('File uploaded successfully.');
|
||||
} else {
|
||||
alert('File upload failed.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Upload error:', error);
|
||||
alert('An error occurred during upload.');
|
||||
});
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
alert('File uploaded successfully.');
|
||||
sendCommand({ command: "getConfig" }); // Refresh config after upload
|
||||
} else {
|
||||
alert('File upload failed.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Upload error:', error);
|
||||
alert('An error occurred during upload.');
|
||||
});
|
||||
});
|
||||
|
||||
function sendCommand(cmd) {
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM1">
|
||||
<h4 class="d-flex justify-content-center card-title">Message1</h4>
|
||||
<p class="text-start card-text" id="fileM1">File 01</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM1">File 01</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM1" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM1" type="button">Stop</button></div>
|
||||
@@ -55,7 +55,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM2">
|
||||
<h4 class="d-flex justify-content-center card-title">Message2</h4>
|
||||
<p class="text-start card-text" id="fileM2">File 02</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM2">File 02</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM2" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM2" type="button">Stop</button></div>
|
||||
@@ -69,7 +69,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM3">
|
||||
<h4 class="d-flex justify-content-center card-title">Message3</h4>
|
||||
<p class="text-start card-text" id="fileM3">File 03</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM3">File 03</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM3" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM3" type="button">Stop</button></div>
|
||||
@@ -81,7 +81,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM4">
|
||||
<h4 class="d-flex justify-content-center card-title">Message4</h4>
|
||||
<p class="text-start card-text" id="fileM4">File 04</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM4">File 04</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM4" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM4" type="button">Stop</button></div>
|
||||
@@ -95,7 +95,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM5">
|
||||
<h4 class="d-flex justify-content-center card-title">Message5</h4>
|
||||
<p class="text-start card-text" id="fileM5">File 05</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM5">File 05</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM5" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM5" type="button">Stop</button></div>
|
||||
@@ -107,7 +107,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM6">
|
||||
<h4 class="d-flex justify-content-center card-title">Message6</h4>
|
||||
<p class="text-start card-text" id="fileM6">File 06</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM6">File 06</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM6" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM6" type="button">Stop</button></div>
|
||||
@@ -121,7 +121,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM7">
|
||||
<h4 class="d-flex justify-content-center card-title">Message7</h4>
|
||||
<p class="text-start card-text" id="fileM7">File 07</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM7">File 07</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM7" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM7" type="button">Stop</button></div>
|
||||
@@ -133,7 +133,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body" id="cardM8">
|
||||
<h4 class="d-flex justify-content-center card-title">Message8</h4>
|
||||
<p class="text-start card-text" id="fileM8">File 08</p>
|
||||
<p class="d-flex justify-content-center card-text" id="fileM8">File 08</p>
|
||||
<div class="row">
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="playM8" type="button">Play</button></div>
|
||||
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM8" type="button">Stop</button></div>
|
||||
|
||||
Reference in New Issue
Block a user