diff --git a/Aida/airelay_init.html b/Aida/airelay_init.html index e253a71..4f2fc04 100644 --- a/Aida/airelay_init.html +++ b/Aida/airelay_init.html @@ -594,6 +594,14 @@ //var jsonbuf = JSON.parse('{ "name":"John", "age":30, "city":"New York"}'); var jsonbuf = JSON.parse(retdata); localStorage.setItem("events_default_version", jsonbuf["events_default_version"]); + if (localStorage.getItem('current_state_hide_or_open_label') == null) { + if (localStorage.getItem("events_default_version") != null && localStorage.getItem("events_default_version") == "4") { + localStorage.setItem('current_state_hide_or_open_label', 0); + } + else { + localStorage.setItem('current_state_hide_or_open_label', 1); + } + } //console.info(retdata); }, diff --git a/Aida/alarm.html b/Aida/alarm.html index 4545814..473a058 100644 --- a/Aida/alarm.html +++ b/Aida/alarm.html @@ -863,7 +863,7 @@   - + @@ -880,8 +880,8 @@ - - + + @@ -1103,10 +1103,22 @@ //document.body.style.transform = scale;// General //document.body.style.zoom = "100%"; - if (localStorage.getItem('current_state_hide_or_open_label') == null) - localStorage.setItem('current_state_hide_or_open_label', 1); - else + if (localStorage.getItem('current_state_hide_or_open_label') == null) { + localStorage.setItem('current_state_hide_or_open_label', 0); + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + else { current_state_hide_or_open_label = localStorage.getItem('current_state_hide_or_open_label'); + if (current_state_hide_or_open_label == 1) { + document.getElementById("hide_open_label").style.background = "#6c87d4"; + document.getElementById("hide_open_label").style.borderColor = "#6c87d4"; + } + else { + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + } if (localStorage.getItem('current_state_hide_or_open_direction') == null) localStorage.setItem('current_state_hide_or_open_direction', 0); diff --git a/Aida/alarm.js b/Aida/alarm.js index f128f35..06b8297 100644 --- a/Aida/alarm.js +++ b/Aida/alarm.js @@ -34,7 +34,7 @@ var MAX_WIDTH = G_VIEW_CANVAS_X; var g_check_cross = 0; -var current_state_hide_or_open_label = 1; +var current_state_hide_or_open_label = 0; var current_state_hide_or_open_direction = 0; var current_state_hide_or_open_speed = 0; var current_state_hide_or_open_getalarmmotion = 1; @@ -3269,8 +3269,8 @@ function GetAlarm(alarm_data) { ai_json.AiEngine[i].label_name == "barcode" || ai_json.AiEngine[i].label_name == "L._Plate_TWN") { - if (typeof (ai_json.AiEngine[i].properties !== 'undefined')) { - if (typeof (ai_json.AiEngine[i].properties.plate !== 'undefined')) { + if (ai_json.AiEngine[i].properties) { + if (ai_json.AiEngine[i].properties.plate) { var plate_name = ""; if (ai_json.AiEngine[i].label_name == "ambulance") plate_name = plate_name.concat(ai_json.AiEngine[i].label_name); diff --git a/Aida/alarm_on_airelay.html b/Aida/alarm_on_airelay.html index 1abf3e1..1e8a4cc 100644 --- a/Aida/alarm_on_airelay.html +++ b/Aida/alarm_on_airelay.html @@ -869,7 +869,7 @@   - + @@ -1004,8 +1004,8 @@
- - + + @@ -1259,10 +1259,22 @@ //document.body.style.transform = scale;// General //document.body.style.zoom = "100%"; - if (localStorage.getItem('current_state_hide_or_open_label') == null) - localStorage.setItem('current_state_hide_or_open_label', 1); - else + if (localStorage.getItem('current_state_hide_or_open_label') == null) { + localStorage.setItem('current_state_hide_or_open_label', 0); + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + else { current_state_hide_or_open_label = localStorage.getItem('current_state_hide_or_open_label'); + if (current_state_hide_or_open_label == 1) { + document.getElementById("hide_open_label").style.background = "#6c87d4"; + document.getElementById("hide_open_label").style.borderColor = "#6c87d4"; + } + else { + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + } if (localStorage.getItem('current_state_hide_or_open_direction') == null) localStorage.setItem('current_state_hide_or_open_direction', 0); diff --git a/Aida/alarm_on_airelay.js b/Aida/alarm_on_airelay.js index 9a3952d..9a99a95 100644 --- a/Aida/alarm_on_airelay.js +++ b/Aida/alarm_on_airelay.js @@ -41,7 +41,7 @@ var MAX_WIDTH = G_VIEW_CANVAS_X; var g_check_cross = 0; -var current_state_hide_or_open_label = 1; +var current_state_hide_or_open_label = 0; var current_state_hide_or_open_direction = 0; var current_state_hide_or_open_speed = 0; var current_state_hide_or_open_getalarmmotion = 1; @@ -3704,8 +3704,8 @@ function GetAlarm(alarm_data) { try { - if (typeof (ai_json.AiEngine[i].properties !== 'undefined')) { - if (typeof (ai_json.AiEngine[i].properties.plate !== 'undefined')) { + if (ai_json.AiEngine[i].properties) { + if (ai_json.AiEngine[i].properties.plate) { var plate_name = ""; if (ai_json.AiEngine[i].label_name == "ambulance") plate_name = plate_name.concat(ai_json.AiEngine[i].label_name); @@ -5179,6 +5179,10 @@ function func_checkGetRequest() { var counter = 0; var max_retry_time = 20; + if (g_getalarmmotion_last_fetch_time == null) { + g_getalarmmotion_last_fetch_time = Date.now(); + } + if (checkIntervalID) { clearInterval(checkIntervalID); } @@ -5199,11 +5203,13 @@ function func_checkGetRequest() { }, checkIntervalTime) } - - +var g_decoder = new TextDecoder('utf-8'); function GetRequest_Http_80port_fetch() { // console.log("[GetRequest_Http_80port_fetch] start"); localStorage.setItem("fetchHttpGetalarm", "Yes"); + if (g_getalarmmotion_last_fetch_time == null) { + g_getalarmmotion_last_fetch_time = Date.now(); + } func_initCounterMsg(); @@ -5219,65 +5225,98 @@ function GetRequest_Http_80port_fetch() { .then(response => { // console.log(response); var reader = response.body.getReader(); - var decoder = new TextDecoder('utf-8'); - function read() { - reader.read().then(({ done, value }) => { - // 08-24 以當前傳輸間隔換算1秒能傳的次數,沒物件資訊時,以 noJsonStringCounter 判斷是否須清除殘留物件 - var fetchIntervalTime = (Date.now() - g_getalarmmotion_last_fetch_time); - var refreshCounterThreshold = 1000 / fetchIntervalTime; - // console.log(`fetchIntervalTime : ${fetchIntervalTime} , refreshCounterThreshold : ${refreshCounterThreshold} , check noJsonStringCounter : ${noJsonStringCounter}`); - - // 紀錄最後收到資訊的時間,以供斷線重連檢查用 - g_getalarmmotion_last_fetch_time = Date.now(); - + var lastJsonString = ''; + var camTime = ''; + var check_if_start_to_receive_aiengine = 0; + var count_end = 0; + var check_if_receive_ok = 0; + //var g_fetchIntervalTime = 50; + + function read() + { + //console.log("Date:" + Date.now()); + reader.read().then(({ done, value }) => { if (done) { // console.log('http getalarmmotion complete'); - return; + //return; } + else { + // 08-24 以當前傳輸間隔換算1秒能傳的次數,沒物件資訊時,以 noJsonStringCounter 判斷是否須清除殘留物件 + var fetchIntervalTime = (Date.now() - g_getalarmmotion_last_fetch_time); + //g_fetchIntervalTime = fetchIntervalTime; + var refreshCounterThreshold = 1000 / fetchIntervalTime; + // console.log(`fetchIntervalTime : ${fetchIntervalTime} , refreshCounterThreshold : ${refreshCounterThreshold} , check noJsonStringCounter : ${noJsonStringCounter}`); + g_getalarmmotion_last_fetch_time = Date.now(); + // 紀錄最後收到資訊的時間,以供斷線重連檢查用 + + // 處理收到的資料 + var chunk = g_decoder.decode(value, { stream: true }); + // console.log('Received chunk:', chunk); + + var lines = chunk.split(/\r?\n/); + + lines.forEach(line => { + if (line.startsWith('CamTime:')) { + lastJsonString = ''; + check_if_start_to_receive_aiengine = 0; + count_end = 0; + camTime = line; + check_if_receive_ok = 0; + } + else if (line.startsWith('{"AiEngine"')) { + lastJsonString = line; + check_if_start_to_receive_aiengine = 1; + } + else if (line.length >= 2 && check_if_start_to_receive_aiengine == 1) { + lastJsonString += line; + } + else if (check_if_start_to_receive_aiengine == 1) { + count_end++; + } + }); - // 處理收到的資料 - var chunk = decoder.decode(value, { stream: true }); - // console.log('Received chunk:', chunk); - - var lines = chunk.split(/\r?\n/); - var lastJsonString = ''; - var camTime = ''; - lines.forEach(line => { - if (line.startsWith('CamTime:')) { - camTime = line; - } else if (line.startsWith('{') && line.endsWith('}')) { - lastJsonString = line; + if (count_end == 2) { + check_if_receive_ok = 1; } - }); - - // 不論有無 Json 字串都可能用到 - var max_protected_objects = g_max_protected_objects; - if (g_enable_show_pixel === 1) { - max_protected_objects = g_max_protected_objects + 2; - } - if (lastJsonString) { - // 80 port getalarmmotion 有物件才會有JSON字串,清理 canvas 要提早到這邊 - // 加入 click_mouse_set 條件,避免導致 Cold zone 設定過程取不到座標 - if (localStorage.getItem("fetchHttpGetalarm") == "Yes" && click_mouse_set == 0) { - // console.log("g_max_protected_objects:", g_max_protected_objects); - RefreshCanvasObject(max_protected_objects); - noJsonStringCounter = 0; - // console.log(`--- RefreshCanvasObject for normal getalarmmotion procedure and reset noJsonStringCounter : ${noJsonStringCounter}`); + // 不論有無 Json 字串都可能用到 + var max_protected_objects = g_max_protected_objects; + if (g_enable_show_pixel === 1) { + max_protected_objects = g_max_protected_objects + 2; } - var data = `${camTime}\r\n\r\n${lastJsonString}`; // 銜接原 WebSocket 傳 GetAlarm 格式 - // console.log('data:\n', data); - GetAlarm(data); - } else { - // 記錄沒傳 Json 字串的次數,判斷是否滿足約1秒能傳的次數,做 refresh 清除殘留物件 - noJsonStringCounter++; - if (noJsonStringCounter > refreshCounterThreshold && localStorage.getItem("fetchHttpGetalarm") == "Yes" && click_mouse_set == 0) { - RefreshCanvasObject(max_protected_objects); - noJsonStringCounter = 0; - // console.log(`=== RefreshCanvasObject for residual boxes and reset noJsonStringCounter : ${noJsonStringCounter}`); + + if (check_if_receive_ok == 1) { + // 80 port getalarmmotion 有物件才會有JSON字串,清理 canvas 要提早到這邊 + // 加入 click_mouse_set 條件,避免導致 Cold zone 設定過程取不到座標 + if (localStorage.getItem("fetchHttpGetalarm") == "Yes" && click_mouse_set == 0) { + // console.log("g_max_protected_objects:", g_max_protected_objects); + RefreshCanvasObject(max_protected_objects); + noJsonStringCounter = 0; + // console.log(`--- RefreshCanvasObject for normal getalarmmotion procedure and reset noJsonStringCounter : ${noJsonStringCounter}`); + } + var data = `${camTime}\r\n\r\n${lastJsonString}`; // 銜接原 WebSocket 傳 GetAlarm 格式 + // console.log('data:\n', data); + GetAlarm(data); + + lastJsonString = ''; + camTime = ''; + check_if_start_to_receive_aiengine = 0; + count_end = 0; + check_if_receive_ok = 0; + } else { + if (localStorage.getItem("events_default_version") != "4") + { + // 非 Live View 版本的 udp 傳輸機制不同,要偵測沒物件情況清理 canvas + // 記錄沒傳 Json 字串的次數,判斷是否滿足約1秒能傳的次數,做 refresh 清除殘留物件 + noJsonStringCounter++; + if (noJsonStringCounter > refreshCounterThreshold && localStorage.getItem("fetchHttpGetalarm") == "Yes" && click_mouse_set == 0) { + RefreshCanvasObject(max_protected_objects); + noJsonStringCounter = 0; + console.log(`=== RefreshCanvasObject for residual boxes and reset noJsonStringCounter : ${noJsonStringCounter}`); + } + } } } - read(); }); } @@ -5285,11 +5324,8 @@ function GetRequest_Http_80port_fetch() { }) .catch(error => { // 發生錯誤後稍等一段時間再重試 - try { - setTimeout(GetRequest_Http_80port_fetch, 3000); - } catch (error) { - console.error(error); - } + console.error("Fetch error:", error); + setTimeout(GetRequest_Http_80port_fetch, 2000); }); } diff --git a/Aida/alarm_on_nvr.html b/Aida/alarm_on_nvr.html index 3807a65..78be6e4 100644 --- a/Aida/alarm_on_nvr.html +++ b/Aida/alarm_on_nvr.html @@ -886,7 +886,7 @@   - +   @@ -1124,10 +1124,22 @@ //document.body.style.transform = scale;// General //document.body.style.zoom = "100%"; - if (localStorage.getItem('current_state_hide_or_open_label') == null) - localStorage.setItem('current_state_hide_or_open_label', 1); - else + if (localStorage.getItem('current_state_hide_or_open_label') == null) { + localStorage.setItem('current_state_hide_or_open_label', 0); + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + else { current_state_hide_or_open_label = localStorage.getItem('current_state_hide_or_open_label'); + if (current_state_hide_or_open_label == 1) { + document.getElementById("hide_open_label").style.background = "#6c87d4"; + document.getElementById("hide_open_label").style.borderColor = "#6c87d4"; + } + else { + document.getElementById("hide_open_label").style.background = "gray"; + document.getElementById("hide_open_label").style.borderColor = "gray"; + } + } if (localStorage.getItem('current_state_hide_or_open_direction') == null) localStorage.setItem('current_state_hide_or_open_direction', 0); diff --git a/Aida/cool_counter.html b/Aida/cool_counter.html index 88ff68a..52d30a6 100644 --- a/Aida/cool_counter.html +++ b/Aida/cool_counter.html @@ -451,7 +451,7 @@