From fd763e584bdb3151663284dd5fe3524d330309dd Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Tue, 9 May 2023 12:27:51 +0200 Subject: [PATCH] first attempt with auto retry --- gui/main.js | 2 + gui/preload-chat.js | 89 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/gui/main.js b/gui/main.js index d38fea4e..5ff7b2e1 100644 --- a/gui/main.js +++ b/gui/main.js @@ -95,6 +95,8 @@ const configDefaultSettings = "shared_folder_path" : ".", \ "enable_request_profile" : "True", \ "enable_request_shared_folder" : "False", \ + "max_retry_attempts" : 5, \ + "enable_auto_retry" : "False", \ "tx_delay" : 0, \ "auto_start": 0 \ }'; diff --git a/gui/preload-chat.js b/gui/preload-chat.js index 04cf8c41..106e5a5f 100644 --- a/gui/preload-chat.js +++ b/gui/preload-chat.js @@ -940,7 +940,15 @@ update_chat = function (obj) { } else { var attempt = obj.attempt; } - var max_attempts = 3; + + if (typeof config.max_retry_attempts == "undefined") { + var max_retry_attempts = 3; + } else { + + var max_retry_attempts = parseInt(config.max_retry_attempts); + } + + // define shortmessage if (obj.msg == "null" || obj.msg == "NULL") { @@ -1119,6 +1127,13 @@ update_chat = function (obj) { if (!document.getElementById("msg-" + obj._id)) { if (obj.type == "ping") { + + // check for messages which failed and try to transmit them + if (config.enable_auto_retry.toUpperCase() == "TRUE") { + checkForWaitingMessages(obj.dxcallsign) + } + + var new_message = `

snr: ${obj.snr} - ${timestamp}

@@ -1133,6 +1148,10 @@ update_chat = function (obj) { `; } if (obj.type == "beacon") { + // check for messages which failed and try to transmit them + if (config.enable_auto_retry.toUpperCase() == "TRUE") { + checkForWaitingMessages(obj.dxcallsign) + } var new_message = `

snr: ${obj.snr} - ${timestamp}

@@ -1216,17 +1235,11 @@ update_chat = function (obj) {

${message_html}

${timestamp} - - ${get_icon_for_state( - obj.status - )} + ${get_icon_for_state(obj.status)}

- + - ${attempt}/${max_attempts} + ${attempt}/${max_retry_attempts} retries
@@ -1278,7 +1291,7 @@ update_chat = function (obj) { ).innerHTML = obj.percent + "% - " + obj.bytesperminute + " Bpm"; document.getElementById("msg-" + obj._id + "-attempts").innerHTML = - obj.attempt + "/" + max_attempts; + obj.attempt + "/" + max_retry_attempts; if (obj.status == "transmitted") { //document.getElementById('msg-' + obj._id + '-progress').classList.remove("progress-bar-striped"); @@ -2384,3 +2397,57 @@ function changeGuiDesign(design) { //update path to css file document.getElementById("bootstrap_theme").href = escape(theme_path); } + +function checkForWaitingMessages(dxcall) { +console.log(dxcall) + db.find({ + selector: { + dxcallsign: dxcall, + type: "transmit", + status: "failed", + //attempt: { $lt: parseInt(config.max_retry_attempts) } + + }, + }) + .then(function (result) { + // handle result + if (result.docs.length > 0) { + // only want to process the first available item object, then return + // this ensures, we are only sending one message at once + + if (typeof result.docs[0].attempt == "undefined") { + + db.upsert(obj._id, function (doc) { + if (!doc.attempt) { + doc.attempt = 1; + } + doc.attempt++; + return doc; + }) + console.log("old message found - adding attempt field") + result.docs[0].attempt = 1; + + } + + if (result.docs[0].attempt < config.max_retry_attempts){ + console.log("RESENDING MESSAGE TRIGGERED BY BEACON OR PING") + console.log(result.docs[0]); + document.getElementById("retransmit-msg-"+ result.docs[0]._id).click(); + } else { + console.log("max retries reached...can't auto repeat") + document.getElementById("msg-" + result.docs[0]._id + "-attempts-badge").classList.remove("bg-primary"); + document.getElementById("msg-" + result.docs[0]._id + "-attempts-badge").classList.add("bg-danger"); + + } + return; + + + } else { + console.log("nope") + } + }) + .catch(function (err) { + console.log(err); + }); + + }; \ No newline at end of file