diff --git a/config.json b/config.json deleted file mode 100644 index c3166d8..0000000 --- a/config.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "ZelloUsername": "gtcdevice01", - "ZelloPassword": "GtcDev2025", - "ZelloChannel": "GtcDev2025", - "ZelloServer": "community", - "ZelloWorkNetworkName": "", - "ZelloEnterpriseServerDomain": "", - "M1": "", - "M2": "", - "M3": "", - "M4": "", - "M5": "", - "M6": "", - "M7": "", - "M8": "" - } \ No newline at end of file diff --git a/html/assets/js/prerecordedbroadcast.js b/html/assets/js/prerecordedbroadcast.js index 4ccc430..22f7f57 100644 --- a/html/assets/js/prerecordedbroadcast.js +++ b/html/assets/js/prerecordedbroadcast.js @@ -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); }; diff --git a/html/assets/js/setting.js b/html/assets/js/setting.js index 0241a02..c079b59 100644 --- a/html/assets/js/setting.js +++ b/html/assets/js/setting.js @@ -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 = $('').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 = $('').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) { diff --git a/html/prerecordedbroadcast.html b/html/prerecordedbroadcast.html index 00b7eb4..013b41a 100644 --- a/html/prerecordedbroadcast.html +++ b/html/prerecordedbroadcast.html @@ -43,7 +43,7 @@
File 01
+File 01
File 02
+File 02
File 03
+File 03
File 04
+File 04
File 05
+File 05
File 06
+File 06
File 07
+File 07
File 08
+File 08