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,46 +1,65 @@
|
||||
$(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++){
|
||||
|
||||
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');
|
||||
}
|
||||
break;
|
||||
case "stopMessage":
|
||||
if (msg.data !== "success")
|
||||
{alert(msg.data);}
|
||||
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}`] || '';
|
||||
filetitle.val(fileInput);
|
||||
if (fileInput.length>0){
|
||||
let fileInput = messageConfigdata[`M${i}`];
|
||||
if (fileInput && fileInput.length > 0) {
|
||||
filetitle.text(fileInput);
|
||||
playButton.prop('disabled', false);
|
||||
stopButton.prop('disabled', false);
|
||||
playButton.on('click', function() {
|
||||
playButton.removeClass('invisible');
|
||||
stopButton.removeClass('invisible');
|
||||
playButton.on('click', function () {
|
||||
let cmd = {
|
||||
command: "playMessage",
|
||||
data: `M${i}`
|
||||
@@ -48,7 +67,7 @@ $(document).ready(function() {
|
||||
|
||||
sendCommand(cmd);
|
||||
});
|
||||
stopButton.on('click', function() {
|
||||
stopButton.on('click', function () {
|
||||
let cmd = {
|
||||
command: "stopMessage",
|
||||
data: `M${i}`
|
||||
@@ -56,24 +75,32 @@ $(document).ready(function() {
|
||||
sendCommand(cmd);
|
||||
});
|
||||
} else {
|
||||
playButton.prop('disabled', true);
|
||||
stopButton.prop('disabled', true);
|
||||
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,25 +23,27 @@ $(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 ) {
|
||||
if (msg.reply && msg.reply.length > 0) {
|
||||
switch (msg.reply) {
|
||||
case "getConfig":
|
||||
const configData = JSON.parse(msg.data);
|
||||
console.log('Config Data:', configData);
|
||||
//console.log('Config Data:', configData);
|
||||
$('#zelloUsername').val(configData.zelloUsername || '');
|
||||
$('#zelloPassword').val(configData.zelloPassword || '');
|
||||
$('#zelloChannel').val(configData.zelloChannel || '');
|
||||
@@ -63,10 +65,10 @@ $(document).ready(function() {
|
||||
const dropdownMenu = $(`#dropdownM${i} .dropdown-menu`);
|
||||
const dropdownButton = $(`#dropdownM${i} button`);
|
||||
dropdownMenu.empty();
|
||||
const messages = configData[`MessageList`] || [];
|
||||
const messages = configData[`messageList`] || [];
|
||||
messages.forEach((msg, idx) => {
|
||||
const item = $('<a class="dropdown-item" href="#"></a>').text(msg);
|
||||
item.on('click', function() {
|
||||
item.on('click', function () {
|
||||
dropdownButton.text(msg);
|
||||
});
|
||||
dropdownMenu.append(item);
|
||||
@@ -78,60 +80,83 @@ $(document).ready(function() {
|
||||
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' : ''
|
||||
};
|
||||
}
|
||||
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",
|
||||
data: JSON.stringify({
|
||||
M1: $('#dropdownM1 button').text(),
|
||||
M2: $('#dropdownM2 button').text(),
|
||||
M3: $('#dropdownM3 button').text(),
|
||||
@@ -140,6 +165,8 @@ $(document).ready(function() {
|
||||
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.');
|
||||
@@ -164,6 +191,7 @@ $(document).ready(function() {
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
alert('File uploaded successfully.');
|
||||
sendCommand({ command: "getConfig" }); // Refresh config after upload
|
||||
} else {
|
||||
alert('File upload failed.');
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
48
src/Main.kt
48
src/Main.kt
@@ -2,7 +2,7 @@ import audio.AudioFilePlayer
|
||||
import audio.AudioUtility
|
||||
import audio.OpusStreamReceiver
|
||||
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.configFile
|
||||
import web.WsReply
|
||||
@@ -11,15 +11,17 @@ import zello.ZelloClient
|
||||
import zello.ZelloEvent
|
||||
import javafx.util.Pair
|
||||
import org.slf4j.LoggerFactory
|
||||
import somecodes.Codes.Companion.ValidFile
|
||||
import somecodes.Codes
|
||||
import web.WsCommand
|
||||
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
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
fun main() {
|
||||
val logger = LoggerFactory.getLogger("Main")
|
||||
val objectMapper = ObjectMapper()
|
||||
val objectMapper = jacksonObjectMapper()
|
||||
|
||||
val cfg = configFile()
|
||||
cfg.Load()
|
||||
@@ -33,7 +35,7 @@ fun main() {
|
||||
}
|
||||
}
|
||||
if (audioID!=0){
|
||||
val initsuccess = au.InitDevice(audioID)
|
||||
val initsuccess = au.InitDevice(audioID,44100)
|
||||
println("Audio Device $audioID initialized: $initsuccess")
|
||||
}
|
||||
|
||||
@@ -45,8 +47,25 @@ fun main() {
|
||||
when (source) {
|
||||
"setting" -> when(cmd.command){
|
||||
"getConfig" ->{
|
||||
logger.info("Get Config")
|
||||
WsReply(cmd.command,objectMapper.writeValueAsString(cfg) )
|
||||
val data = mapOf(
|
||||
"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" -> {
|
||||
try{
|
||||
@@ -57,7 +76,7 @@ fun main() {
|
||||
cfg.ZelloServer = xx["ZelloServer"]
|
||||
cfg.ZelloWorkNetworkName = xx["ZelloWorkNetworkName"]
|
||||
cfg.ZelloEnterpriseServerDomain = xx["ZelloEnterpriseServerDomain"]
|
||||
|
||||
cfg.Save()
|
||||
WsReply(cmd.command,"success")
|
||||
} catch (e: Exception){
|
||||
WsReply(cmd.command,"failed: ${e.message}")
|
||||
@@ -76,6 +95,7 @@ fun main() {
|
||||
cfg.M6 = xx["M6"]
|
||||
cfg.M7 = xx["M7"]
|
||||
cfg.M8 = xx["M8"]
|
||||
cfg.Save()
|
||||
WsReply(cmd.command,"success")
|
||||
} catch (e: Exception){
|
||||
WsReply(cmd.command,"failed: ${e.message}")
|
||||
@@ -101,7 +121,7 @@ fun main() {
|
||||
}
|
||||
"getPlaybackStatus" ->{
|
||||
if (afp!=null && true==afp?.isPlaying){
|
||||
WsReply(cmd.command, "Playing: ${afp?.filename}")
|
||||
WsReply(cmd.command, "Playing: ${afp?.ShortFileName()}")
|
||||
} else {
|
||||
WsReply(cmd.command, "Idle")
|
||||
}
|
||||
@@ -120,9 +140,12 @@ fun main() {
|
||||
null
|
||||
}
|
||||
}
|
||||
if (ValidFile(filename)){
|
||||
if (filename!=null){
|
||||
val completefilename = Codes.audioFilePath.resolve(filename)
|
||||
if (completefilename.isRegularFile()){
|
||||
try{
|
||||
val player= AudioFilePlayer(audioID, filename)
|
||||
|
||||
val player= AudioFilePlayer(audioID, completefilename.pathString)
|
||||
player.Play { _ -> afp = null}
|
||||
afp = player
|
||||
WsReply(cmd.command,"success")
|
||||
@@ -130,7 +153,10 @@ fun main() {
|
||||
} catch (e: Exception){
|
||||
WsReply(cmd.command, "failed: ${e.message}")
|
||||
}
|
||||
} else WsReply(cmd.command,"Invalid file : $filename")
|
||||
} else WsReply(cmd.command,"File Not Found : $filename")
|
||||
} else WsReply(cmd.command,"Invalid message name: ${cmd.data}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,16 +5,18 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.function.Consumer
|
||||
import kotlin.io.path.Path
|
||||
|
||||
/**
|
||||
* Audio Player for playing audio files.
|
||||
* Supported extensions : .wav, .mp3
|
||||
*/
|
||||
@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
|
||||
var filehandle = 0
|
||||
var isPlaying = false
|
||||
private val filepath = Path(filename)
|
||||
init{
|
||||
if (bass.BASS_SetDevice(deviceID)){
|
||||
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{
|
||||
if (bass.BASS_ChannelPlay(filehandle, false)){
|
||||
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
package somecodes
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import java.io.File
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@Suppress("unused")
|
||||
class Codes {
|
||||
private val objectMapper = ObjectMapper()
|
||||
|
||||
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 {
|
||||
if (s!=null){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package somecodes
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@@ -21,15 +22,14 @@ class configFile {
|
||||
|
||||
private val filepath : Path = Path(System.getProperty("user.dir"), "config.json")
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun Load(){
|
||||
if (filepath.toFile().exists()){
|
||||
// file found, then load the configuration to configFile object
|
||||
try{
|
||||
val json = filepath.toFile().readText()
|
||||
val configMap = json.split(",").associate { it ->
|
||||
val (key, value) = it.split(":").map { it.trim().removeSurrounding("\"") }
|
||||
key to value
|
||||
}
|
||||
val objectMapper = jacksonObjectMapper()
|
||||
val configMap = objectMapper.readValue(json, Map::class.java) as Map<String, String>
|
||||
|
||||
ZelloUsername = configMap["ZelloUsername"]
|
||||
ZelloPassword = configMap["ZelloPassword"]
|
||||
@@ -72,23 +72,25 @@ class configFile {
|
||||
fun Save(){
|
||||
try {
|
||||
// Convert the configFile object to JSON and write it to the file
|
||||
val json = """{
|
||||
"ZelloUsername": "$ZelloUsername",
|
||||
"ZelloPassword": "$ZelloPassword",
|
||||
"ZelloChannel": "$ZelloChannel",
|
||||
"ZelloServer": "$ZelloServer",
|
||||
"ZelloWorkNetworkName": "$ZelloWorkNetworkName",
|
||||
"ZelloEnterpriseServerDomain": "$ZelloEnterpriseServerDomain",
|
||||
"M1": "$M1",
|
||||
"M2": "$M2",
|
||||
"M3": "$M3",
|
||||
"M4": "$M4",
|
||||
"M5": "$M5",
|
||||
"M6": "$M6",
|
||||
"M7": "$M7",
|
||||
"M8": "$M8"
|
||||
}"""
|
||||
filepath.toFile().writeText(json)
|
||||
val js = mapOf(
|
||||
"ZelloUsername" to ZelloUsername,
|
||||
"ZelloPassword" to ZelloPassword,
|
||||
"ZelloChannel" to ZelloChannel,
|
||||
"ZelloServer" to ZelloServer,
|
||||
"ZelloWorkNetworkName" to ZelloWorkNetworkName,
|
||||
"ZelloEnterpriseServerDomain" to ZelloEnterpriseServerDomain,
|
||||
"M1" to M1,
|
||||
"M2" to M2,
|
||||
"M3" to M3,
|
||||
"M4" to M4,
|
||||
"M5" to M5,
|
||||
"M6" to M6,
|
||||
"M7" to M7,
|
||||
"M8" to M8
|
||||
)
|
||||
|
||||
val mapper = jacksonObjectMapper()
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(filepath.toFile(), js)
|
||||
} catch (e: Exception) {
|
||||
println("Error saving configuration: ${e.message}")
|
||||
}
|
||||
|
||||
@@ -2,10 +2,16 @@ package web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.javalin.Javalin;
|
||||
import io.javalin.http.HttpStatus;
|
||||
import javafx.util.Pair;
|
||||
import org.slf4j.Logger;
|
||||
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.Map;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -85,7 +91,7 @@ public class webApp {
|
||||
String message = wsMessageContext.message();
|
||||
try{
|
||||
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);
|
||||
wsMessageContext.send(reply);
|
||||
} catch (Exception e){
|
||||
@@ -99,14 +105,33 @@ public class webApp {
|
||||
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 -> {
|
||||
// Handle incoming WebSocket messages
|
||||
String message = wsMessageContext.message();
|
||||
//logger.info("Received message from setting.html/ws: {}", message);
|
||||
try{
|
||||
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);
|
||||
logger.info("Replying to setting.html/ws : {}", reply);
|
||||
//logger.info("Replying to setting.html/ws : {}", reply);
|
||||
wsMessageContext.send(reply);
|
||||
} catch (Exception e){
|
||||
logger.error("Error processing {} from setting.html/ws: {}", message, e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user