Commit 06/08/2025
This commit is contained in:
16
config.json
16
config.json
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"ZelloUsername": "gtcdevice01",
|
|
||||||
"ZelloPassword": "GtcDev2025",
|
|
||||||
"ZelloChannel": "GtcDev2025",
|
|
||||||
"ZelloServer": "community",
|
|
||||||
"ZelloWorkNetworkName": "",
|
|
||||||
"ZelloEnterpriseServerDomain": "",
|
|
||||||
"M1": "",
|
|
||||||
"M2": "",
|
|
||||||
"M3": "",
|
|
||||||
"M4": "",
|
|
||||||
"M5": "",
|
|
||||||
"M6": "",
|
|
||||||
"M7": "",
|
|
||||||
"M8": ""
|
|
||||||
}
|
|
||||||
@@ -1,79 +1,106 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
// Your code here
|
// Your code here
|
||||||
console.log('precordedbroadcast.js is ready!');
|
//console.log('precordedbroadcast.js is ready!');
|
||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
const ws = new WebSocket('ws://' + window.location.host + path + '/ws');
|
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('');
|
$(`#fileM${i}`).val('');
|
||||||
$(`#playM${i}`).prop('disabled', true);
|
$(`#playM${i}`).prop('disabled', true);
|
||||||
$(`#stopM${i}`).prop('disabled', true);
|
$(`#stopM${i}`).prop('disabled', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function () {
|
||||||
console.log('WebSocket connection opened');
|
//console.log('WebSocket connection opened');
|
||||||
$('#indicatorDisconnected').addClass('visually-hidden');
|
$('#indicatorDisconnected').addClass('visually-hidden');
|
||||||
$('#indicatorConnected').removeClass('visually-hidden');
|
$('#indicatorConnected').removeClass('visually-hidden');
|
||||||
|
|
||||||
sendCommand({ command: "getMessageConfig" });
|
sendCommand({ command: "getMessageConfig" });
|
||||||
setInterval(function() {
|
setInterval(function () {
|
||||||
sendCommand({ command: "getPlaybackStatus" });
|
sendCommand({ command: "getPlaybackStatus" });
|
||||||
}, 5000);
|
}, 1000); // every second
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function (event) {
|
||||||
console.log('WebSocket message received:', event.data);
|
//console.log('WebSocket message received:', event.data);
|
||||||
let msg = {};
|
let msg = {};
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(event.data);
|
msg = JSON.parse(event.data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
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}`
|
|
||||||
}
|
|
||||||
|
|
||||||
sendCommand(cmd);
|
if (msg.reply && msg.reply.length > 0 && msg.data && msg.data.length > 0) {
|
||||||
});
|
switch (msg.reply) {
|
||||||
stopButton.on('click', function() {
|
case "playMessage":
|
||||||
let cmd = {
|
if (msg.data !== "success")
|
||||||
command: "stopMessage",
|
{alert(msg.data);}
|
||||||
data: `M${i}`
|
else{
|
||||||
|
$('#playbackStatus').text('Playback started');
|
||||||
}
|
}
|
||||||
sendCommand(cmd);
|
break;
|
||||||
});
|
case "stopMessage":
|
||||||
} else {
|
if (msg.data !== "success")
|
||||||
playButton.prop('disabled', true);
|
{alert(msg.data);}
|
||||||
stopButton.prop('disabled', true);
|
else{
|
||||||
|
$('#playbackStatus').text('Playback stopped');
|
||||||
|
}
|
||||||
|
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() {
|
ws.onclose = function () {
|
||||||
console.log('WebSocket connection closed');
|
//console.log('WebSocket connection closed');
|
||||||
$('#indicatorDisconnected').removeClass('visually-hidden');
|
$('#indicatorDisconnected').removeClass('visually-hidden');
|
||||||
$('#indicatorConnected').addClass('visually-hidden');
|
$('#indicatorConnected').addClass('visually-hidden');
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = function(error) {
|
ws.onerror = function (error) {
|
||||||
console.error('WebSocket error:', error);
|
console.error('WebSocket error:', error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
// Your initialization code here
|
// Your initialization code here
|
||||||
console.log('setting.js is ready!');
|
//console.log('setting.js is ready!');
|
||||||
$('#dropdownM1 button').text('');
|
$('#dropdownM1 button').text('');
|
||||||
$('#dropdownM2 button').text('');
|
$('#dropdownM2 button').text('');
|
||||||
$('#dropdownM3 button').text('');
|
$('#dropdownM3 button').text('');
|
||||||
@@ -23,123 +23,150 @@ $(document).ready(function() {
|
|||||||
const path = window.location.pathname;
|
const path = window.location.pathname;
|
||||||
const ws = new WebSocket('ws://' + window.location.host + path + '/ws');
|
const ws = new WebSocket('ws://' + window.location.host + path + '/ws');
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function () {
|
||||||
console.log('WebSocket connection opened');
|
//console.log('WebSocket connection opened');
|
||||||
$('#indicatorDisconnected').addClass('visually-hidden');
|
$('#indicatorDisconnected').addClass('visually-hidden');
|
||||||
$('#indicatorConnected').removeClass('visually-hidden');
|
$('#indicatorConnected').removeClass('visually-hidden');
|
||||||
sendCommand({ command: "getConfig" });
|
sendCommand({ command: "getConfig" });
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function (event) {
|
||||||
console.log('WebSocket message received:', event.data);
|
//console.log('WebSocket message received:', event.data);
|
||||||
let msg = {};
|
let msg = {};
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(event.data);
|
msg = JSON.parse(event.data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.reply === "getConfig" && msg.data !== undefined ) {
|
if (msg.reply && msg.reply.length > 0) {
|
||||||
const configData = JSON.parse(msg.data);
|
switch (msg.reply) {
|
||||||
console.log('Config Data:', configData);
|
case "getConfig":
|
||||||
$('#zelloUsername').val(configData.zelloUsername || '');
|
const configData = JSON.parse(msg.data);
|
||||||
$('#zelloPassword').val(configData.zelloPassword || '');
|
//console.log('Config Data:', configData);
|
||||||
$('#zelloChannel').val(configData.zelloChannel || '');
|
$('#zelloUsername').val(configData.zelloUsername || '');
|
||||||
if ("community" === configData.zelloServer) {
|
$('#zelloPassword').val(configData.zelloPassword || '');
|
||||||
$('#zellocommunity').prop('checked', true);
|
$('#zelloChannel').val(configData.zelloChannel || '');
|
||||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
if ("community" === configData.zelloServer) {
|
||||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
$('#zellocommunity').prop('checked', true);
|
||||||
} else if ("work" === configData.zelloServer) {
|
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||||
$('#zellowork').prop('checked', true);
|
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||||
$('#zelloWorkNetworkName').val(configData.zelloWorkNetworkName || '').prop('disabled', false);
|
} else if ("work" === configData.zelloServer) {
|
||||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
$('#zellowork').prop('checked', true);
|
||||||
} else if ("enterprise" === configData.zelloServer) {
|
$('#zelloWorkNetworkName').val(configData.zelloWorkNetworkName || '').prop('disabled', false);
|
||||||
$('#zelloenterprise').prop('checked', true);
|
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
} else if ("enterprise" === configData.zelloServer) {
|
||||||
$('#zelloEnterpriseServerDomain').val(configData.zelloEnterpriseServerDomain || '').prop('disabled', false);
|
$('#zelloenterprise').prop('checked', true);
|
||||||
}
|
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||||
|
$('#zelloEnterpriseServerDomain').val(configData.zelloEnterpriseServerDomain || '').prop('disabled', false);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 1; i <= 8; i++) {
|
for (let i = 1; i <= 8; i++) {
|
||||||
const dropdownMenu = $(`#dropdownM${i} .dropdown-menu`);
|
const dropdownMenu = $(`#dropdownM${i} .dropdown-menu`);
|
||||||
const dropdownButton = $(`#dropdownM${i} button`);
|
const dropdownButton = $(`#dropdownM${i} button`);
|
||||||
dropdownMenu.empty();
|
dropdownMenu.empty();
|
||||||
const messages = configData[`MessageList`] || [];
|
const messages = configData[`messageList`] || [];
|
||||||
messages.forEach((msg, idx) => {
|
messages.forEach((msg, idx) => {
|
||||||
const item = $('<a class="dropdown-item" href="#"></a>').text(msg);
|
const item = $('<a class="dropdown-item" href="#"></a>').text(msg);
|
||||||
item.on('click', function() {
|
item.on('click', function () {
|
||||||
dropdownButton.text(msg);
|
dropdownButton.text(msg);
|
||||||
});
|
});
|
||||||
dropdownMenu.append(item);
|
dropdownMenu.append(item);
|
||||||
});
|
});
|
||||||
// Set button text to selected message if present
|
// Set button text to selected message if present
|
||||||
if (configData[`m${i}`]) {
|
if (configData[`m${i}`]) {
|
||||||
dropdownButton.text(configData[`m${i}`]);
|
dropdownButton.text(configData[`m${i}`]);
|
||||||
} else {
|
} else {
|
||||||
dropdownButton.text('');
|
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() {
|
ws.onclose = function () {
|
||||||
console.log('WebSocket connection closed');
|
//console.log('WebSocket connection closed');
|
||||||
$('#indicatorDisconnected').removeClass('visually-hidden');
|
$('#indicatorDisconnected').removeClass('visually-hidden');
|
||||||
$('#indicatorConnected').addClass('visually-hidden');
|
$('#indicatorConnected').addClass('visually-hidden');
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = function(error) {
|
ws.onerror = function (error) {
|
||||||
console.error('WebSocket error:', error);
|
console.error('WebSocket error:', error);
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#zellocommunity').on('click', function() {
|
$('#zellocommunity').on('click', function () {
|
||||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||||
});
|
});
|
||||||
$('#zellowork').on('click', function() {
|
$('#zellowork').on('click', function () {
|
||||||
$('#zelloWorkNetworkName').prop('disabled', false);
|
$('#zelloWorkNetworkName').prop('disabled', false);
|
||||||
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
$('#zelloEnterpriseServerDomain').val('').prop('disabled', true);
|
||||||
});
|
});
|
||||||
$('#zelloenterprise').on('click', function() {
|
$('#zelloenterprise').on('click', function () {
|
||||||
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
$('#zelloWorkNetworkName').val('').prop('disabled', true);
|
||||||
$('#zelloEnterpriseServerDomain').prop('disabled', false);
|
$('#zelloEnterpriseServerDomain').prop('disabled', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#btnApplyZello').on('click', function() {
|
$('#btnApplyZello').on('click', function () {
|
||||||
if (ws.readyState === WebSocket.OPEN) {
|
if (ws.readyState === WebSocket.OPEN) {
|
||||||
|
let xx = {
|
||||||
|
command: "setZelloConfig"
|
||||||
|
};
|
||||||
let data = {
|
let data = {
|
||||||
command: "setZelloConfig",
|
|
||||||
ZelloUsername: $('#zelloUsername').val(),
|
ZelloUsername: $('#zelloUsername').val(),
|
||||||
ZelloPassword: $('#zelloPassword').val(),
|
ZelloPassword: $('#zelloPassword').val(),
|
||||||
ZelloChannel: $('#zelloChannel').val(),
|
ZelloChannel: $('#zelloChannel').val(),
|
||||||
ZelloServer: $('#zellocommunity').is(':checked') ? 'community' :
|
ZelloServer: $('#zellocommunity').is(':checked') ? 'community' :
|
||||||
$('#zellowork').is(':checked') ? 'work' :
|
$('#zellowork').is(':checked') ? 'work' :
|
||||||
$('#zelloenterprise').is(':checked') ? 'enterprise' : ''
|
$('#zelloenterprise').is(':checked') ? 'enterprise' : ''
|
||||||
};
|
}
|
||||||
if ($('#zellowork').is(':checked')) {
|
if ($('#zellowork').is(':checked')) {
|
||||||
data.ZelloWorkNetworkName = $('#zelloWorkNetworkName').val();
|
data.ZelloWorkNetworkName = $('#zelloWorkNetworkName').val();
|
||||||
}
|
}
|
||||||
if ($('#zelloenterprise').is(':checked')) {
|
if ($('#zelloenterprise').is(':checked')) {
|
||||||
data.ZelloEnterpriseServerDomain = $('#zelloEnterpriseServerDomain').val();
|
data.ZelloEnterpriseServerDomain = $('#zelloEnterpriseServerDomain').val();
|
||||||
}
|
}
|
||||||
sendCommand(data);
|
xx.data = JSON.stringify(data);
|
||||||
|
sendCommand(xx);
|
||||||
} else {
|
} else {
|
||||||
console.warn('WebSocket is not open.');
|
console.warn('WebSocket is not open.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#btnApplyMessage').on('click', function() {
|
$('#btnApplyMessage').on('click', function () {
|
||||||
if (ws.readyState === WebSocket.OPEN) {
|
if (ws.readyState === WebSocket.OPEN) {
|
||||||
let data = {
|
let data = {
|
||||||
command: "setMessageConfig",
|
command: "setMessageConfig",
|
||||||
M1: $('#dropdownM1 button').text(),
|
data: JSON.stringify({
|
||||||
M2: $('#dropdownM2 button').text(),
|
M1: $('#dropdownM1 button').text(),
|
||||||
M3: $('#dropdownM3 button').text(),
|
M2: $('#dropdownM2 button').text(),
|
||||||
M4: $('#dropdownM4 button').text(),
|
M3: $('#dropdownM3 button').text(),
|
||||||
M5: $('#dropdownM5 button').text(),
|
M4: $('#dropdownM4 button').text(),
|
||||||
M6: $('#dropdownM6 button').text(),
|
M5: $('#dropdownM5 button').text(),
|
||||||
M7: $('#dropdownM7 button').text(),
|
M6: $('#dropdownM6 button').text(),
|
||||||
M8: $('#dropdownM8 button').text()
|
M7: $('#dropdownM7 button').text(),
|
||||||
|
M8: $('#dropdownM8 button').text()
|
||||||
|
})
|
||||||
|
|
||||||
};
|
};
|
||||||
sendCommand(data);
|
sendCommand(data);
|
||||||
} else {
|
} else {
|
||||||
@@ -147,7 +174,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#btnUploadContent').on('click', function() {
|
$('#btnUploadContent').on('click', function () {
|
||||||
const fileInput = document.getElementById('chosenFile');
|
const fileInput = document.getElementById('chosenFile');
|
||||||
if (!fileInput || !fileInput.files.length) {
|
if (!fileInput || !fileInput.files.length) {
|
||||||
alert('Please select a file to upload.');
|
alert('Please select a file to upload.');
|
||||||
@@ -161,17 +188,18 @@ $(document).ready(function() {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert('File uploaded successfully.');
|
alert('File uploaded successfully.');
|
||||||
} else {
|
sendCommand({ command: "getConfig" }); // Refresh config after upload
|
||||||
alert('File upload failed.');
|
} else {
|
||||||
}
|
alert('File upload failed.');
|
||||||
})
|
}
|
||||||
.catch(error => {
|
})
|
||||||
console.error('Upload error:', error);
|
.catch(error => {
|
||||||
alert('An error occurred during upload.');
|
console.error('Upload error:', error);
|
||||||
});
|
alert('An error occurred during upload.');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendCommand(cmd) {
|
function sendCommand(cmd) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body" id="cardM1">
|
<div class="card-body" id="cardM1">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message1</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM2">
|
<div class="card-body" id="cardM2">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message2</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM3">
|
<div class="card-body" id="cardM3">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message3</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM4">
|
<div class="card-body" id="cardM4">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message4</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM5">
|
<div class="card-body" id="cardM5">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message5</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM6">
|
<div class="card-body" id="cardM6">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message6</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM7">
|
<div class="card-body" id="cardM7">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message7</h4>
|
<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="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="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>
|
<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">
|
||||||
<div class="card-body" id="cardM8">
|
<div class="card-body" id="cardM8">
|
||||||
<h4 class="d-flex justify-content-center card-title">Message8</h4>
|
<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="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="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>
|
<div class="col d-flex justify-content-center"><button class="btn btn-primary w-75" id="stopM8" type="button">Stop</button></div>
|
||||||
|
|||||||
62
src/Main.kt
62
src/Main.kt
@@ -2,7 +2,7 @@ import audio.AudioFilePlayer
|
|||||||
import audio.AudioUtility
|
import audio.AudioUtility
|
||||||
import audio.OpusStreamReceiver
|
import audio.OpusStreamReceiver
|
||||||
import com.fasterxml.jackson.core.type.TypeReference
|
import com.fasterxml.jackson.core.type.TypeReference
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import somecodes.Codes.Companion.ValidString
|
import somecodes.Codes.Companion.ValidString
|
||||||
import somecodes.configFile
|
import somecodes.configFile
|
||||||
import web.WsReply
|
import web.WsReply
|
||||||
@@ -11,15 +11,17 @@ import zello.ZelloClient
|
|||||||
import zello.ZelloEvent
|
import zello.ZelloEvent
|
||||||
import javafx.util.Pair
|
import javafx.util.Pair
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import somecodes.Codes.Companion.ValidFile
|
import somecodes.Codes
|
||||||
import web.WsCommand
|
import web.WsCommand
|
||||||
import java.util.function.BiFunction
|
import java.util.function.BiFunction
|
||||||
|
import kotlin.io.path.isRegularFile
|
||||||
|
import kotlin.io.path.pathString
|
||||||
|
|
||||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||||
fun main() {
|
fun main() {
|
||||||
val logger = LoggerFactory.getLogger("Main")
|
val logger = LoggerFactory.getLogger("Main")
|
||||||
val objectMapper = ObjectMapper()
|
val objectMapper = jacksonObjectMapper()
|
||||||
|
|
||||||
val cfg = configFile()
|
val cfg = configFile()
|
||||||
cfg.Load()
|
cfg.Load()
|
||||||
@@ -33,7 +35,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (audioID!=0){
|
if (audioID!=0){
|
||||||
val initsuccess = au.InitDevice(audioID)
|
val initsuccess = au.InitDevice(audioID,44100)
|
||||||
println("Audio Device $audioID initialized: $initsuccess")
|
println("Audio Device $audioID initialized: $initsuccess")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +47,25 @@ fun main() {
|
|||||||
when (source) {
|
when (source) {
|
||||||
"setting" -> when(cmd.command){
|
"setting" -> when(cmd.command){
|
||||||
"getConfig" ->{
|
"getConfig" ->{
|
||||||
logger.info("Get Config")
|
val data = mapOf(
|
||||||
WsReply(cmd.command,objectMapper.writeValueAsString(cfg) )
|
"zelloUsername" to cfg.ZelloUsername,
|
||||||
|
"zelloPassword" to cfg.ZelloPassword,
|
||||||
|
"zelloChannel" to cfg.ZelloChannel,
|
||||||
|
"zelloServer" to cfg.ZelloServer,
|
||||||
|
"zelloWorkNetworkName" to cfg.ZelloWorkNetworkName,
|
||||||
|
"zelloEnterpriseServerDomain" to cfg.ZelloEnterpriseServerDomain,
|
||||||
|
"m1" to cfg.M1,
|
||||||
|
"m2" to cfg.M2,
|
||||||
|
"m3" to cfg.M3,
|
||||||
|
"m4" to cfg.M4,
|
||||||
|
"m5" to cfg.M5,
|
||||||
|
"m6" to cfg.M6,
|
||||||
|
"m7" to cfg.M7,
|
||||||
|
"m8" to cfg.M8,
|
||||||
|
"messageList" to Codes.getAudioFiles()
|
||||||
|
)
|
||||||
|
|
||||||
|
WsReply(cmd.command, objectMapper.writeValueAsString(data).trim())
|
||||||
}
|
}
|
||||||
"setZelloConfig" -> {
|
"setZelloConfig" -> {
|
||||||
try{
|
try{
|
||||||
@@ -57,7 +76,7 @@ fun main() {
|
|||||||
cfg.ZelloServer = xx["ZelloServer"]
|
cfg.ZelloServer = xx["ZelloServer"]
|
||||||
cfg.ZelloWorkNetworkName = xx["ZelloWorkNetworkName"]
|
cfg.ZelloWorkNetworkName = xx["ZelloWorkNetworkName"]
|
||||||
cfg.ZelloEnterpriseServerDomain = xx["ZelloEnterpriseServerDomain"]
|
cfg.ZelloEnterpriseServerDomain = xx["ZelloEnterpriseServerDomain"]
|
||||||
|
cfg.Save()
|
||||||
WsReply(cmd.command,"success")
|
WsReply(cmd.command,"success")
|
||||||
} catch (e: Exception){
|
} catch (e: Exception){
|
||||||
WsReply(cmd.command,"failed: ${e.message}")
|
WsReply(cmd.command,"failed: ${e.message}")
|
||||||
@@ -76,6 +95,7 @@ fun main() {
|
|||||||
cfg.M6 = xx["M6"]
|
cfg.M6 = xx["M6"]
|
||||||
cfg.M7 = xx["M7"]
|
cfg.M7 = xx["M7"]
|
||||||
cfg.M8 = xx["M8"]
|
cfg.M8 = xx["M8"]
|
||||||
|
cfg.Save()
|
||||||
WsReply(cmd.command,"success")
|
WsReply(cmd.command,"success")
|
||||||
} catch (e: Exception){
|
} catch (e: Exception){
|
||||||
WsReply(cmd.command,"failed: ${e.message}")
|
WsReply(cmd.command,"failed: ${e.message}")
|
||||||
@@ -101,7 +121,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
"getPlaybackStatus" ->{
|
"getPlaybackStatus" ->{
|
||||||
if (afp!=null && true==afp?.isPlaying){
|
if (afp!=null && true==afp?.isPlaying){
|
||||||
WsReply(cmd.command, "Playing: ${afp?.filename}")
|
WsReply(cmd.command, "Playing: ${afp?.ShortFileName()}")
|
||||||
} else {
|
} else {
|
||||||
WsReply(cmd.command, "Idle")
|
WsReply(cmd.command, "Idle")
|
||||||
}
|
}
|
||||||
@@ -120,17 +140,23 @@ fun main() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ValidFile(filename)){
|
if (filename!=null){
|
||||||
try{
|
val completefilename = Codes.audioFilePath.resolve(filename)
|
||||||
val player= AudioFilePlayer(audioID, filename)
|
if (completefilename.isRegularFile()){
|
||||||
player.Play { _ -> afp = null}
|
try{
|
||||||
afp = player
|
|
||||||
WsReply(cmd.command,"success")
|
val player= AudioFilePlayer(audioID, completefilename.pathString)
|
||||||
|
player.Play { _ -> afp = null}
|
||||||
|
afp = player
|
||||||
|
WsReply(cmd.command,"success")
|
||||||
|
|
||||||
|
} catch (e: Exception){
|
||||||
|
WsReply(cmd.command, "failed: ${e.message}")
|
||||||
|
}
|
||||||
|
} else WsReply(cmd.command,"File Not Found : $filename")
|
||||||
|
} else WsReply(cmd.command,"Invalid message name: ${cmd.data}")
|
||||||
|
|
||||||
|
|
||||||
} catch (e: Exception){
|
|
||||||
WsReply(cmd.command, "failed: ${e.message}")
|
|
||||||
}
|
|
||||||
} else WsReply(cmd.command,"Invalid file : $filename")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,18 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
import kotlin.io.path.Path
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audio Player for playing audio files.
|
* Audio Player for playing audio files.
|
||||||
* Supported extensions : .wav, .mp3
|
* Supported extensions : .wav, .mp3
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class AudioFilePlayer(deviceID: Int, val filename: String?, device_samplingrate: Int = 48000) {
|
class AudioFilePlayer(deviceID: Int, filename: String, device_samplingrate: Int = 48000) {
|
||||||
val bass: Bass = Bass.Instance
|
val bass: Bass = Bass.Instance
|
||||||
var filehandle = 0
|
var filehandle = 0
|
||||||
var isPlaying = false
|
var isPlaying = false
|
||||||
|
private val filepath = Path(filename)
|
||||||
init{
|
init{
|
||||||
if (bass.BASS_SetDevice(deviceID)){
|
if (bass.BASS_SetDevice(deviceID)){
|
||||||
filehandle = bass.BASS_StreamCreateFile(false, filename, 0, 0, 0)
|
filehandle = bass.BASS_StreamCreateFile(false, filename, 0, 0, 0)
|
||||||
@@ -32,6 +34,10 @@ class AudioFilePlayer(deviceID: Int, val filename: String?, device_samplingrate:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ShortFileName() : String {
|
||||||
|
return filepath.fileName.toString()
|
||||||
|
}
|
||||||
|
|
||||||
fun Play(finished: Consumer<Any> ) : Boolean{
|
fun Play(finished: Consumer<Any> ) : Boolean{
|
||||||
if (bass.BASS_ChannelPlay(filehandle, false)){
|
if (bass.BASS_ChannelPlay(filehandle, false)){
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,30 @@
|
|||||||
package somecodes
|
package somecodes
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.io.path.Path
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class Codes {
|
class Codes {
|
||||||
private val objectMapper = ObjectMapper()
|
|
||||||
companion object{
|
companion object{
|
||||||
|
val audioFilePath = Path(System.getProperty("user.dir"), "audiofile")
|
||||||
|
private val validAudioExtensions = setOf("wav", "mp3")
|
||||||
|
fun getAudioFiles() : Array<String> {
|
||||||
|
val audioDir = audioFilePath.toFile()
|
||||||
|
if (!audioDir.exists()) {
|
||||||
|
audioDir.mkdirs() // Create directory if it doesn't exist
|
||||||
|
}
|
||||||
|
val ll = audioDir.listFiles()?.filter { it.isFile && validAudioExtensions.contains(it.extension) }?.map { it.name } ?: emptyList()
|
||||||
|
return ll.toTypedArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getaudioFileFullPath(filename: String) : String {
|
||||||
|
if (ValidString(filename)) {
|
||||||
|
val file = audioFilePath.resolve(filename)
|
||||||
|
return file.toAbsolutePath().toString()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
fun ValidFile(s: String?) : Boolean {
|
fun ValidFile(s: String?) : Boolean {
|
||||||
if (s!=null){
|
if (s!=null){
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package somecodes
|
package somecodes
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
|
|
||||||
@@ -21,15 +22,14 @@ class configFile {
|
|||||||
|
|
||||||
private val filepath : Path = Path(System.getProperty("user.dir"), "config.json")
|
private val filepath : Path = Path(System.getProperty("user.dir"), "config.json")
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun Load(){
|
fun Load(){
|
||||||
if (filepath.toFile().exists()){
|
if (filepath.toFile().exists()){
|
||||||
// file found, then load the configuration to configFile object
|
// file found, then load the configuration to configFile object
|
||||||
try{
|
try{
|
||||||
val json = filepath.toFile().readText()
|
val json = filepath.toFile().readText()
|
||||||
val configMap = json.split(",").associate { it ->
|
val objectMapper = jacksonObjectMapper()
|
||||||
val (key, value) = it.split(":").map { it.trim().removeSurrounding("\"") }
|
val configMap = objectMapper.readValue(json, Map::class.java) as Map<String, String>
|
||||||
key to value
|
|
||||||
}
|
|
||||||
|
|
||||||
ZelloUsername = configMap["ZelloUsername"]
|
ZelloUsername = configMap["ZelloUsername"]
|
||||||
ZelloPassword = configMap["ZelloPassword"]
|
ZelloPassword = configMap["ZelloPassword"]
|
||||||
@@ -72,23 +72,25 @@ class configFile {
|
|||||||
fun Save(){
|
fun Save(){
|
||||||
try {
|
try {
|
||||||
// Convert the configFile object to JSON and write it to the file
|
// Convert the configFile object to JSON and write it to the file
|
||||||
val json = """{
|
val js = mapOf(
|
||||||
"ZelloUsername": "$ZelloUsername",
|
"ZelloUsername" to ZelloUsername,
|
||||||
"ZelloPassword": "$ZelloPassword",
|
"ZelloPassword" to ZelloPassword,
|
||||||
"ZelloChannel": "$ZelloChannel",
|
"ZelloChannel" to ZelloChannel,
|
||||||
"ZelloServer": "$ZelloServer",
|
"ZelloServer" to ZelloServer,
|
||||||
"ZelloWorkNetworkName": "$ZelloWorkNetworkName",
|
"ZelloWorkNetworkName" to ZelloWorkNetworkName,
|
||||||
"ZelloEnterpriseServerDomain": "$ZelloEnterpriseServerDomain",
|
"ZelloEnterpriseServerDomain" to ZelloEnterpriseServerDomain,
|
||||||
"M1": "$M1",
|
"M1" to M1,
|
||||||
"M2": "$M2",
|
"M2" to M2,
|
||||||
"M3": "$M3",
|
"M3" to M3,
|
||||||
"M4": "$M4",
|
"M4" to M4,
|
||||||
"M5": "$M5",
|
"M5" to M5,
|
||||||
"M6": "$M6",
|
"M6" to M6,
|
||||||
"M7": "$M7",
|
"M7" to M7,
|
||||||
"M8": "$M8"
|
"M8" to M8
|
||||||
}"""
|
)
|
||||||
filepath.toFile().writeText(json)
|
|
||||||
|
val mapper = jacksonObjectMapper()
|
||||||
|
mapper.writerWithDefaultPrettyPrinter().writeValue(filepath.toFile(), js)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println("Error saving configuration: ${e.message}")
|
println("Error saving configuration: ${e.message}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,16 @@ package web;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.javalin.Javalin;
|
import io.javalin.Javalin;
|
||||||
|
import io.javalin.http.HttpStatus;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import somecodes.Codes;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@@ -85,7 +91,7 @@ public class webApp {
|
|||||||
String message = wsMessageContext.message();
|
String message = wsMessageContext.message();
|
||||||
try{
|
try{
|
||||||
var command = objectMapper.readValue(message, WsCommand.class);
|
var command = objectMapper.readValue(message, WsCommand.class);
|
||||||
logger.info("Received command from prerecordedbroadcast.html/ws : {}", command);
|
//logger.info("Received command from prerecordedbroadcast.html/ws : {}", command);
|
||||||
var reply = callback.apply("prerecordedbroadcast", command);
|
var reply = callback.apply("prerecordedbroadcast", command);
|
||||||
wsMessageContext.send(reply);
|
wsMessageContext.send(reply);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
@@ -99,14 +105,33 @@ public class webApp {
|
|||||||
ctx.redirect("/index.html");
|
ctx.redirect("/index.html");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
post("/upload", ctx -> {
|
||||||
|
// Handle file upload
|
||||||
|
var file = ctx.uploadedFile("file");
|
||||||
|
if (file != null ) {
|
||||||
|
// Process the uploaded file
|
||||||
|
try(InputStream in = file.content()) {
|
||||||
|
var savetarget = Codes.Companion.getAudioFilePath().resolve(file.filename());
|
||||||
|
Files.copy(in, savetarget, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
logger.info("File uploaded: {}", file.filename());
|
||||||
|
ctx.status(HttpStatus.OK).result("File uploaded successfully: " + file.filename());
|
||||||
|
} catch (Exception e){
|
||||||
|
ctx.status(HttpStatus.INTERNAL_SERVER_ERROR).result("File upload failed: " + file.filename());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ctx.status(HttpStatus.BAD_REQUEST).result("No file uploaded");
|
||||||
|
}
|
||||||
|
});
|
||||||
ws("/ws", wshandler -> wshandler.onMessage(wsMessageContext -> {
|
ws("/ws", wshandler -> wshandler.onMessage(wsMessageContext -> {
|
||||||
// Handle incoming WebSocket messages
|
// Handle incoming WebSocket messages
|
||||||
String message = wsMessageContext.message();
|
String message = wsMessageContext.message();
|
||||||
|
//logger.info("Received message from setting.html/ws: {}", message);
|
||||||
try{
|
try{
|
||||||
var command = objectMapper.readValue(message, WsCommand.class);
|
var command = objectMapper.readValue(message, WsCommand.class);
|
||||||
logger.info("Received command from setting.html/ws : {}", command);
|
//logger.info("Received command from setting.html/ws : {}", command);
|
||||||
var reply = callback.apply("setting", command);
|
var reply = callback.apply("setting", command);
|
||||||
logger.info("Replying to setting.html/ws : {}", reply);
|
//logger.info("Replying to setting.html/ws : {}", reply);
|
||||||
wsMessageContext.send(reply);
|
wsMessageContext.send(reply);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
logger.error("Error processing {} from setting.html/ws: {}", message, e.getMessage());
|
logger.error("Error processing {} from setting.html/ws: {}", message, e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user