| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //使用 WebSocket 的網址向 Server 開啟連結
- //let ws = new WebSocket('ws://180.218.150.185:3030')
- let ws = new WebSocket('ws://125.227.151.69:3030')
- var client_id;
- //開啟後執行的動作,指定一個 function 會在連結 WebSocket 後執行
- ws.onopen = () => {
- console.log('open connection')
- }
- //關閉後執行的動作,指定一個 function 會在連結中斷後執行
- ws.onclose = () => {
- console.log('close connection')
- }
- //接收 Server 發送的訊息
- ws.onmessage = event => {
- var table;
- var x;
- if (event.data.includes("client")) {
- client_id = event.data.replace("client:","");
- console.log("this client id: " + client_id);
- } else {
-
- const user = JSON.parse(event.data);
- if(user != ""){
- console.log("user[0]:"+user[0]);
- if (user[0].hasOwnProperty('aid_id')) {
- console.log("warning: " + event.data);
-
- document.getElementById("warning-count").innerHTML = user.length;
- document.getElementById("warning-count2").innerHTML = user.length;
- document.getElementById("warning-none").innerHTML = "";
- document.getElementById("warning-style").style.display = "block";
- //$("#warning").click();
- if(document.URL == 'http://125.227.151.69:8800/C3Octopus/octopus/warning.php') {
- table = document.getElementById("warningTable");
- x = table.rows.length;
- for (var i = 0; i < x - 1; i++) {
- table.deleteRow(1);
- }
- for (var i = 0; i < user.length; i++) {
- var test = user[i].aid_id;
- var test2 = user[i].beacon_id;
- var test3 = user[i].created_at;
- var row = table.insertRow(-1);
- var cell1 = row.insertCell(0);
- var cell2 = row.insertCell(1);
- var cell3 = row.insertCell(2);
- cell1.innerHTML = test;
- cell2.innerHTML = test2;
- cell3.innerHTML = test3;
- }
-
- $("#click-to-close-error").click();
-
- }
-
- } else if(user[0].hasOwnProperty('status')){
- $("#warning").click();
- }else{
- console.log("error");
- }
- }else{
-
- document.getElementById("warning-count").innerHTML = 0;
- document.getElementById("warning-count2").innerHTML = 0;
- document.getElementById("warning-none").innerHTML = "No warning";
- document.getElementById("warning-style").style.display = "none";
-
- //$("#clear").click();
- if(document.URL == 'http://125.227.151.69:8800/C3Octopus/octopus/warning.php') {
- table = document.getElementById("warningTable");
- x = table.rows.length;
- for (var i = 0; i < x - 1; i++) {
- table.deleteRow(1);
- }
- $(".click-2-close").click();
- $("#click-to-close-success").click();
- }
-
-
- }
-
- }
-
-
-
-
- }
|