diff --git a/Html/html/index.html b/Html/html/index.html
index 40e3565..09ddc22 100644
--- a/Html/html/index.html
+++ b/Html/html/index.html
@@ -10,6 +10,7 @@
+
@@ -109,7 +110,7 @@
-
diff --git a/Html/html/index.js b/Html/html/index.js
index 6d07cd0..9719dd3 100644
--- a/Html/html/index.js
+++ b/Html/html/index.js
@@ -12,213 +12,110 @@ let ws;
let camerastream;
-
+// socketio
+let socketio;
let files = [null,null,null,null,null];
let getbase64handle;
let getsysteminfohandle;
+let $zoom;
+let $mute;
+let $unmute;
+
window.addEventListener("unload",function (){
clearInterval(getbase64handle);
clearInterval(getsysteminfohandle);
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "STOP AUDIO",
- data: 0
- }));
-
- // wait a while
- const start = Date.now();
- while(Date.now()-start<200){}
- }
-
+ send_stop_audio();
+ // wait a while
+ const start = Date.now();
+ while(Date.now()-start<200){}
ws.close();
+
})
window.addEventListener("load", function (){
+ $zoom = $('#zoom');
+ $mute = $('#mute');
+ $unmute = $('#unmute');
+
camerastream = document.getElementById("camerastream");
+
+ // pilihan komunikasi, disable salah satu
+ initialize_socketio();
+ //initialize_websocket();
+
// Update camera stream every 50ms / 20fps
getbase64handle = setInterval(function (){
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "GET BASE64",
- data: video_quality
- }));
-
- } else update_camerastream(null);
+ send_get_base64();
},1000/15);
getsysteminfohandle = setInterval(function (){
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "GET SYSTEM INFO",
- data: 0
- }));
- }
+ send_get_system_info();
}, 5000);
-
- ws = new WebSocket("/ws");
-
- ws.onopen = function(){
- console.log("Connected to the server");
-
- // request basic parameters
- ws.send(JSON.stringify({
- command: "GET MAX ZOOM",
- data: 0
- }));
- ws.send(JSON.stringify({
- command: "GET VOLUME",
- data: 0
- }));
- ws.send(JSON.stringify({
- command: "GET ZOOM",
- data: 0
- }));
- ws.send(JSON.stringify({
- command: "GET RESOLUTION",
- data: 0
- }));
- ws.send(JSON.stringify({
- command: "GET AUDIOFILES",
- data: 0
- }))
-
- }
- ws.onmessage = function(event){
- //console.log("Received data from server: " + event.data);
- /**
- * @type {{reply: string, data: string|number, additional: string}} dx
- */
- let dx = JSON.parse(event.data);
- switch (dx.reply){
- case "GET BASE64":
- if (dx.data.startsWith("data:image/jpeg;base64,")){
- update_camerastream(dx.data);
- } else update_camerastream(null);
- if (dx.additional && dx.additional.length>0){
- let stat = JSON.parse(dx.additional);
- if (Array.isArray(stat) && stat.length === 3){
- $('#streaming_status').html("Streaming at "+stat[0]+"x"+stat[1]+" "+stat[2]+"fps");
- }
- }
- break;
- case "SET VOLUME":
- console.log("Set Volume: "+dx.data);
- break;
- case "GET VOLUME":
- console.log("Get Volume: "+dx.data);
- $('#customRange').val(dx.data);
- break;
- case "GET MAX ZOOM":
- console.log("Get Max Zoom: "+dx.data);
- let zoom = document.getElementById("zoom");
- zoom.min = 1;
- zoom.max = dx.data;
- break;
- case "GET ZOOM":
- document.getElementById("zoom").value = dx.data;
- console.log("Get Zoom: "+dx.data);
- break;
- case "GET RESOLUTION":
- console.log("Get Resolution: "+dx.data);
- break;
- case "PAN LEFT":
- console.log("Pan Left");
- break;
- case "PAN RIGHT":
- console.log("Pan Right");
- break;
- case "TILT UP":
- console.log("Tilt Up");
- break;
- case "TILT DOWN":
- console.log("Tilt Down");
- break;
- case "STOP MOVEMENT":
- console.log("Stop Movement");
- break;
- case "SET ZOOM":
- console.log("Set Zoom: "+dx.data);
- break;
- case "PLAY AUDIO":
- console.log("Play Audio: "+dx.data);
- if (dx.data.startsWith("Failed")){
- alert(dx.data);
- } else $('#status_player').html("Playing Audio "+dx.data);
- break;
- case "STOP AUDIO":
- console.log("Stop Audio");
- document.getElementById("status_player").innerHTML = "Stop Playback";
- break;
- case 'SET VIDEO QUALITY':
- console.log("Set Video Quality: "+dx.data);
- break;
- case "GET SYSTEM INFO":
- //console.log("Get System Info: "+dx.data);
- /**
- * @type {{cpu_temperature: string, ram_usage: string, cpu: string, cpu0: string, cpu1: string, cpu2: string, cpu3: string}} systeminfo
- */
- let systeminfo = JSON.parse(dx.data);
- if (systeminfo.cpu_temperature && systeminfo.cpu_temperature.length>0) $('#cpu_temperature').html(`${systeminfo.cpu_temperature} °C`);
- if (systeminfo.cpu && systeminfo.cpu.length>0) $('#cpu_usage').html(`${systeminfo.cpu} %`);
- if (systeminfo.ram_usage && systeminfo.ram_usage.length>0) $('#ram_usage').html(`${systeminfo.ram_usage} %`);
- break;
- case "GET AUDIOFILES":
- console.log("Get Audio Files: "+dx.data);
- let audiofiles = JSON.parse(dx.data);
- if (audiofiles.preset1 && audiofiles.preset1.length>0 && audiofiles.preset1!== "null") {
- files[0] = audiofiles.preset1;
- play_on(1);
- } else {
- files[0] = null;
- play_off(1);
- }
- if (audiofiles.preset2 && audiofiles.preset2.length>0 && audiofiles.preset2!== "null") {
- files[1] = audiofiles.preset2;
- play_on(2);
- } else {
- files[1] = null;
- play_off(2);
- }
- if (audiofiles.preset3 && audiofiles.preset3.length>0 && audiofiles.preset3!== "null") {
- files[2] = audiofiles.preset3;
- play_on(3);
- } else {
- files[2] = null;
- play_off(3);
- }
- if (audiofiles.preset4 && audiofiles.preset4.length>0 && audiofiles.preset4!== "null") {
- files[3] = audiofiles.preset4;
- play_on(4);
- } else {
- files[3] = null;
- play_off(4);
- }
- if (audiofiles.preset5 && audiofiles.preset5.length>0 && audiofiles.preset5!== "null") {
- files[4] = audiofiles.preset5;
- play_on(5);
- } else {
- files[4] = null;
- play_off(5);
- }
- break;
-
- }
-
- }
- ws.onclose = function(){
- console.log("Connection closed");
- }
- ws.onerror = function(){
- console.log("Error in connection");
- }
-
set_pan_speed(32);
set_tilt_speed(32);
})
+function initialize_socketio(){
+ socketio = io(":3001/socketio");
+ if (socketio){
+ socketio.on("connect",()=>{
+ console.log("Socket.io Connected to the server");
+ send_get_max_zoom();
+ send_get_volume();
+ send_get_zoom();
+ send_get_resolution();
+ send_get_audiofiles();
+ })
+ socketio.on("disconnect",(reason)=>{
+ console.log("Socket.io Disconnected from server because "+reason);
+ })
+ socketio.on("connect_error",(error)=>{
+ console.log("Socket.io Connection error "+error);
+ });
+
+ socketio.on("message",(data)=>{
+ let dx = JSON.parse(data);
+ //console.log("Received data from server: "+data);
+ process_command(dx);
+ });
+ }
+}
+
+function initialize_websocket(){
+ ws = new WebSocket("/ws");
+ if (ws){
+ ws.onopen = function(){
+ console.log("Connected to the server");
+
+ // request basic parameters
+ send_get_max_zoom();
+ send_get_volume();
+ send_get_zoom();
+ send_get_resolution();
+ send_get_audiofiles();
+
+ }
+ ws.onmessage = function(event){
+ //console.log("Received data from server: " + event.data);
+ /**
+ * @type {{reply: string, data: string|number, additional: string}} dx
+ */
+ let dx = JSON.parse(event.data);
+ process_command(dx);
+ }
+ ws.onclose = function(){
+ console.log("Connection closed");
+ }
+ ws.onerror = function(){
+ console.log("Error in connection");
+ }
+ }
+
+}
+
/**
@@ -237,37 +134,62 @@ function update_camerastream(value){
}
-
-
-
+/**
+ * Disable play button
+ * @param index 1 - 5
+ */
function play_off(index){
$('#div'+index).prop("className", "button-container div-disabled");
- $('#btn_play'+index).prop("className", "btn-play1 show text-light");
-
+ $('#btn_play'+index)
+ .prop("className", "btn-play1 show text-light");
}
+/**
+ * Enable play button
+ * @param index 1 - 5
+ */
function play_on(index){
+ let content = $('#desc_content'+index).html();
$('#div'+index).prop("className", "button-container");
- $('#btn_play'+index).prop("className", "btn-play1 show");
+ $('#btn_play'+index)
+ .prop("className", "btn-play1 show")
+ .prop("title","Play "+content);
+ $('#btn_stop'+index)
+ .prop("title","Stop "+content);
}
+/**
+ * Show play button and hide stop button
+ * @param index 1 - 5
+ */
function show_play_and_hide_stop(index){
$('#btn_play'+index).prop("className", "btn-play1 show");
$('#btn_stop'+index).prop("className", "btn-play1 hide");
}
+/**
+ * Show stop button and hide play button
+ * @param index 1 - 5
+ */
function show_stop_and_hide_play(index){
$('#btn_play'+index).prop("className", "btn-play1 hide");
$('#btn_stop'+index).prop("className", "btn-play1 show");
}
+/**
+ * Enable all play buttons
+ */
function allplay(){
for (let i = 0; i < 5; i++) {
if (files[i]) play_on(i+1);
}
}
+/**
+ * When play button is clicked
+ * @param index 1 - 5
+ */
function play_button(index){
show_stop_and_hide_play(index);
$('#status_player').html("Play");
@@ -277,26 +199,160 @@ function play_button(index){
send_play_audio(index);
}
+/**
+ * When stop button is clicked
+ * @param index 1 - 5
+ */
function stop_button(index){
show_play_and_hide_stop(index);
$('#status_player').html("Stop");
-
allplay();
send_stop_audio();
}
+function send_get_audiofiles(){
+ let cmd = JSON.stringify({
+ command: "GET AUDIOFILES",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState===WebSocket.OPEN){
+ ws.send(cmd)
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+}
+
+function send_get_resolution(){
+ let cmd = JSON.stringify({
+ command: "GET RESOLUTION",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_get_zoom(){
+ let cmd = JSON.stringify({
+ command: "GET ZOOM",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState===WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+
+}
+
+function send_get_volume(){
+ let cmd = JSON.stringify({
+ command: "GET VOLUME",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_get_max_zoom(){
+ let cmd = JSON.stringify({
+ command: "GET MAX ZOOM",
+ data: 0
+ });
+ if (ws){
+ if (ws && ws.readyState===WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ console.log("get_max_zoom sent using socketio")
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_get_system_info(){
+ let cmd = JSON.stringify({
+ command: "GET SYSTEM INFO",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
/**
* Send command to stop audio
*/
function send_stop_audio(){
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "STOP AUDIO",
- data: 0
- }));
- } else console.log("WebSocket is not open");
+ let cmd = JSON.stringify({
+ command: "STOP AUDIO",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_get_base64(){
+ let cmd = JSON.stringify({
+ command: "GET BASE64",
+ data: video_quality
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ return;
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ return;
+ } else console.log("Socket.io is not connected");
+ }
+
+ update_camerastream(null);
+
}
/**
@@ -304,114 +360,194 @@ function send_stop_audio(){
* @param {number} index 1 - 5
*/
function send_play_audio(index){
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "PLAY AUDIO",
- data: index
- }));
- } else console.log("WebSocket is not open");
+ let cmd = JSON.stringify({
+ command: "PLAY AUDIO",
+ data: index
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
}
-function unmute(){
- $('#mute').prop("className", "btn-mute show");
- $('#unmute').prop("className", "btn-mute hide");
- console.log("unmute")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "UNMUTE",
- data: 0
- }));
- } else console.log("WebSocket is not open");
-}
-function mute(){
- $('#mute').prop("className", "btn-mute hide");
- $('#unmute').prop("className", "btn-mute show");
+function send_unmute(){
+ let cmd = JSON.stringify({
+ command: "UNMUTE",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_mute(){
+ let cmd = JSON.stringify({
+ command: "MUTE",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_tilt_up(){
+ let cmd = JSON.stringify({
+ command: "TILT UP",
+ data: tilt_speed
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ btn_center_off()
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ btn_center_off()
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_tilt_down(){
+ let cmd = JSON.stringify({
+ command: "TILT DOWN",
+ data: tilt_speed
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ btn_center_off()
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ btn_center_off()
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_pan_left(){
+ let cmd = JSON.stringify({
+ command: "PAN LEFT",
+ data: pan_speed
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ btn_center_off();
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ btn_center_off();
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_pan_right(){
+ let cmd = JSON.stringify({
+ command: "PAN RIGHT",
+ data: pan_speed
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ btn_center_off()
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ btn_center_off()
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_stop_movement(){
+ let cmd = JSON.stringify({
+ command: "STOP MOVEMENT",
+ data: 0
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_set_zoom(value){
+ let cmd = JSON.stringify({
+ command: "SET ZOOM",
+ data: value
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
+
+}
+
+function send_set_volume(value){
+ let cmd = JSON.stringify({
+ command: "SET VOLUME",
+ data: value
+ });
+ if (ws){
+ if (ws.readyState === WebSocket.OPEN){
+ ws.send(cmd);
+ } else console.log("WebSocket is not open");
+ } else if (socketio){
+ if (socketio.connected){
+ socketio.emit("message",cmd);
+ } else console.log("Socket.io is not connected");
+ }
- console.log("mute")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "MUTE",
- data: 0
- }));
- } else console.log("WebSocket is not open");
}
function btn_center_off(){
$('#btn_center').prop("className", "btn-center-unactive fa-solid fa-circle");
}
-function btn_up(){
- console.log("btn_up")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "TILT UP",
- data: tilt_speed
- }));
- btn_center_off()
- } else console.log("WebSocket is not open");
-}
-function btn_left(){
- console.log("btn_left")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "PAN LEFT",
- data: pan_speed
- }));
- btn_center_off();
- } else console.log("WebSocket is not open");
-}
-function btn_right(){
- console.log("btn_right")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "PAN RIGHT",
- data: pan_speed
- }));
- btn_center_off()
- } else console.log("WebSocket is not open");
-}
-function btn_down(){
- console.log("btn_down")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "TILT DOWN",
- data: tilt_speed
- }));
- btn_center_off()
- } else console.log("WebSocket is not open");
-}
-
-function stop_movement(){
- console.log("stop_movement")
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "STOP MOVEMENT",
- data: 0
- }));
- } else console.log("WebSocket is not open");
-}
-
function set_zoom(){
- let zoom = document.getElementById("zoom");
- console.log("set_zoom "+zoom.value)
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "SET ZOOM",
- data: zoom.value
- }));
- } else console.log("WebSocket is not open");
+ send_set_zoom($('#zoom').val());
}
function set_volumeoutput(value){
$('#volumebarvalue').val(value);
-
- console.log("set_volumeoutput "+value)
- if (ws.readyState === WebSocket.OPEN){
- ws.send(JSON.stringify({
- command: "SET VOLUME",
- data: value
- }));
- } else console.log("WebSocket is not open");
+ send_set_volume(value);
}
function set_pan_speed(value){
@@ -477,5 +613,146 @@ function change_video_quality(){
video_quality = btn.checked?"HQ":"LQ";
}
+/**
+ * Process Command
+ * @param {{reply: string, data: string, additional: string}}dx
+ */
+function process_command(dx){
+ switch (dx.reply){
+ case "GET BASE64":
+ if (dx.data.startsWith("data:image/jpeg;base64,")){
+ update_camerastream(dx.data);
+ } else update_camerastream(null);
+ if (dx.additional && dx.additional.length>0){
+ let stat = JSON.parse(dx.additional);
+ if (Array.isArray(stat) && stat.length === 3){
+ $('#streaming_status').html("Streaming at "+stat[0]+"x"+stat[1]+" "+stat[2]+"fps");
+ }
+ }
+ break;
+ case "SET VOLUME":
+ console.log("Set Volume: "+dx.data);
+ break;
+ case "GET VOLUME":
+ console.log("Get Volume: "+dx.data);
+ $('#customRange').val(dx.data);
+ break;
+ case "GET MAX ZOOM":
+ $zoom
+ .prop("min", 1)
+ .prop("max", dx.data);
+ break;
+ case "GET ZOOM":
+ $zoom.val(dx.data);
+ break;
+ case "GET RESOLUTION":
+ console.log("Get Resolution: "+dx.data);
+ break;
+ case "PAN LEFT":
+ console.log("Pan Left");
+ break;
+ case "PAN RIGHT":
+ console.log("Pan Right");
+ break;
+ case "TILT UP":
+ console.log("Tilt Up");
+ break;
+ case "TILT DOWN":
+ console.log("Tilt Down");
+ break;
+ case "STOP MOVEMENT":
+ console.log("Stop Movement");
+ break;
+ case "SET ZOOM":
+ console.log("Set Zoom: "+dx.data);
+ break;
+ case "PLAY AUDIO":
+ console.log("Play Audio: "+dx.data);
+ if (dx.data.startsWith("Failed")){
+ alert(dx.data);
+ } else $('#status_player').html("Playing Audio "+dx.data);
+ break;
+ case "STOP AUDIO":
+ console.log("Stop Audio");
+ document.getElementById("status_player").innerHTML = "Stop Playback";
+ break;
+ case 'SET VIDEO QUALITY':
+ console.log("Set Video Quality: "+dx.data);
+ break;
+ case "MUTE":
+ console.log("Mute");
+ $mute.prop("className", "btn-mute hide");
+ $unmute.prop("className", "btn-mute show");
+ break;
+ case "UNMUTE":
+ console.log("Unmute");
+ $mute.prop("className", "btn-mute show");
+ $unmute.prop("className", "btn-mute hide");
+ break;
+ case "GET SYSTEM INFO":
+ //console.log("Get System Info: "+dx.data);
+ /**
+ * @type {{cpu_temperature: string, ram_usage: string, cpu: string, cpu0: string, cpu1: string, cpu2: string, cpu3: string}} systeminfo
+ */
+ let systeminfo = JSON.parse(dx.data);
+ if (systeminfo.cpu_temperature && systeminfo.cpu_temperature.length>0) $('#cpu_temperature').html(`${systeminfo.cpu_temperature} °C`);
+ if (systeminfo.cpu && systeminfo.cpu.length>0) $('#cpu_usage').html(`${systeminfo.cpu} %`);
+ if (systeminfo.ram_usage && systeminfo.ram_usage.length>0) $('#ram_usage').html(`${systeminfo.ram_usage} %`);
+ break;
+ case "GET AUDIOFILES":
+ console.log("Get Audio Files: "+dx.data);
+ let audiofiles = JSON.parse(dx.data);
+ if (audiofiles.preset1 && audiofiles.preset1.length>0 && audiofiles.preset1!== "null") {
+ files[0] = audiofiles.preset1;
+ $('#desc_content1').html(audiofiles.preset1);
+ play_on(1);
+ } else {
+ files[0] = null;
+ $('#desc_content1').html("");
+ play_off(1);
+ }
+ if (audiofiles.preset2 && audiofiles.preset2.length>0 && audiofiles.preset2!== "null") {
+ files[1] = audiofiles.preset2;
+ $('#desc_content2').html(audiofiles.preset2);
+ play_on(2);
+ } else {
+ files[1] = null;
+ $('#desc_content2').html("");
+ play_off(2);
+ }
+ if (audiofiles.preset3 && audiofiles.preset3.length>0 && audiofiles.preset3!== "null") {
+ files[2] = audiofiles.preset3;
+ $('#desc_content3').html(audiofiles.preset3);
+ play_on(3);
+ } else {
+ files[2] = null;
+ $('#desc_content3').html("");
+ play_off(3);
+ }
+ if (audiofiles.preset4 && audiofiles.preset4.length>0 && audiofiles.preset4!== "null") {
+ files[3] = audiofiles.preset4;
+ $('#desc_content4').html(audiofiles.preset4);
+ play_on(4);
+ } else {
+ files[3] = null;
+ $('#desc_content4').html("");
+ play_off(4);
+ }
+ if (audiofiles.preset5 && audiofiles.preset5.length>0 && audiofiles.preset5!== "null") {
+ files[4] = audiofiles.preset5;
+ $('#desc_content5').html(audiofiles.preset5);
+ play_on(5);
+ } else {
+ files[4] = null;
+ $('#desc_content5').html("");
+ play_off(5);
+ }
+ break;
+
+ }
+}
+
+
+
diff --git a/Html/html/public/images/airport-terminal.jpg b/Html/html/public/images/airport-terminal.jpg
index a380811..2b89b70 100644
Binary files a/Html/html/public/images/airport-terminal.jpg and b/Html/html/public/images/airport-terminal.jpg differ
diff --git a/pom.xml b/pom.xml
index 6ca52ab..5eb114f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,6 +190,19 @@
-->
+
+
+ com.corundumstudio.socketio
+ netty-socketio
+ 2.0.11
+
+
+
+ org.slf4j
+ slf4j-simple
+ 2.0.16
+
+
io.javalin
javalin
diff --git a/src/main/java/Camera/PanTiltController.java b/src/main/java/Camera/PanTiltController.java
index 0170344..bfae9c5 100644
--- a/src/main/java/Camera/PanTiltController.java
+++ b/src/main/java/Camera/PanTiltController.java
@@ -60,7 +60,7 @@ public class PanTiltController {
byte[] command = new byte[]{0, cameraid, 0, 0, 0, 0, 0};
command[6] = Checksum(command); // add checksum
command[0] = (byte) 0xFF; // add synchronization byte
- serialPort.writeBytes(command, command.length);
+ if (serialPort!=null && serialPort.isOpen()) serialPort.writeBytes(command, command.length);
}
/**
@@ -74,7 +74,7 @@ public class PanTiltController {
byte[] command = new byte[]{0, cameraid, 0, 4, speed, 0, 0};
command[6] = Checksum(command); // add checksum
command[0] = (byte) 0xFF; // add synchronization byte
- serialPort.writeBytes(command, command.length);
+ if (serialPort!=null && serialPort.isOpen()) serialPort.writeBytes(command, command.length);
}
/**
@@ -88,7 +88,7 @@ public class PanTiltController {
byte[] command = new byte[]{0, cameraid, 0, 2, speed, 0, 0};
command[6] = Checksum(command); // add checksum
command[0] = (byte) 0xFF; // add synchronization byte
- serialPort.writeBytes(command, command.length);
+ if (serialPort!=null && serialPort.isOpen()) serialPort.writeBytes(command, command.length);
}
/**
@@ -102,7 +102,7 @@ public class PanTiltController {
byte[] command = new byte[]{0, cameraid, 0, 8, speed, 0, 0};
command[6] = Checksum(command); // add checksum
command[0] = (byte) 0xFF; // add synchronization byte
- serialPort.writeBytes(command, command.length);
+ if (serialPort!=null && serialPort.isOpen()) serialPort.writeBytes(command, command.length);
}
/**
@@ -116,7 +116,7 @@ public class PanTiltController {
byte[] command = new byte[]{0, cameraid, 0, 16, speed, 0, 0};
command[6] = Checksum(command); // add checksum
command[0] = (byte) 0xFF; // add synchronization byte
- serialPort.writeBytes(command, command.length);
+ if (serialPort!=null && serialPort.isOpen()) serialPort.writeBytes(command, command.length);
}
/**
diff --git a/src/main/java/Web/WebServer.java b/src/main/java/Web/WebServer.java
index a147072..e738663 100644
--- a/src/main/java/Web/WebServer.java
+++ b/src/main/java/Web/WebServer.java
@@ -1,6 +1,8 @@
package Web;
import Other.SomeCodes;
+import com.corundumstudio.socketio.Configuration;
+import com.corundumstudio.socketio.SocketIOServer;
import io.javalin.Javalin;
import io.javalin.http.UploadedFile;
import io.javalin.util.FileUtil;
@@ -26,6 +28,8 @@ public class WebServer {
private @Getter @Setter String webpassword;
private final Javalin app;
private final Set connectedWebsocketClients = ConcurrentHashMap.newKeySet();
+ private final SocketIOServer socketServer;
+ private final Configuration socketConfig;
public WebServer(WebsocketEvent event, String webusername, String webpassword){
this.webusername = webusername;
this.webpassword = webpassword;
@@ -195,6 +199,27 @@ public class WebServer {
});
});
+
+ socketConfig = new Configuration();
+ socketConfig.setHostname("0.0.0.0");
+ socketConfig.setPort(3001);
+ socketServer = new SocketIOServer(socketConfig);
+ socketServer.addConnectListener(client -> {
+ Logger.info("SocketIO connected, id {} from {}", client.getSessionId(), client.getRemoteAddress());
+ });
+ socketServer.addDisconnectListener(client -> {
+ Logger.info("SocketIO disconnected, id {} from {}", client.getSessionId(), client.getRemoteAddress());
+ });
+ socketServer.addNamespace("/socketio").addEventListener("message", String.class, (client, data, ackSender) -> {
+ //Logger.info("SocketIO message from namespace /socketio from {}: {}", client.getRemoteAddress(), data);
+ WebsocketCommand command = gson.fromJson(data, WebsocketCommand.class);
+ if (event!=null) {
+ WebsocketReply reply = event.onWebsocketCommand(command);
+ if (reply!=null) client.sendEvent("message", gson.toJson(reply));
+ }
+ });
+
+
}
/**
@@ -202,7 +227,11 @@ public class WebServer {
* @param obj Object to send
*/
public void SendtoAll(Object obj){
- connectedWebsocketClients.forEach(wsContext -> wsContext.send(obj));
+
+ connectedWebsocketClients
+ .stream()
+ .filter(ws -> ws.session.isOpen())
+ .forEach(ws -> ws.send(obj));
}
/**
@@ -215,6 +244,8 @@ public class WebServer {
connectedWebsocketClients.forEach(WsContext::closeSession);
app.start(localip, port);
Logger.info("Web server started at {}:{}", localip, port);
+ socketServer.start();
+ Logger.info("SocketIO server started at {}:{}", socketConfig.getHostname(), socketConfig.getPort());
} catch (JavalinException e){
Logger.error("Web server failed to start: {}", e.getMessage());
}
@@ -227,6 +258,8 @@ public class WebServer {
try{
app.stop();
Logger.info("Web server stopped");
+ socketServer.stop();
+ Logger.info("SocketIO server stopped");
} catch (JavalinException e){
Logger.error("Web server failed to stop: {}", e.getMessage());
}