first attempt with auto retry

This commit is contained in:
DJ2LS 2023-05-09 12:27:51 +02:00
parent 5ba9183af3
commit fd763e584b
2 changed files with 80 additions and 11 deletions

View file

@ -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 \
}';

View file

@ -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 = `
<div class="m-auto mt-1 p-0 w-50 rounded bg-secondary bg-gradient" id="msg-${obj._id}">
<p class="text-small text-white mb-0 text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-arrow-left-right"></i>snr: ${obj.snr} - ${timestamp} </p>
@ -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 = `
<div class="p-0 rounded m-auto mt-1 w-50 bg-info bg-gradient" id="msg-${obj._id}">
<p class="text-small text-white text-break" style="font-size: 0.7rem;"><i class="m-3 bi bi-broadcast"></i>snr: ${obj.snr} - ${timestamp} </p>
@ -1216,17 +1235,11 @@ update_chat = function (obj) {
<p class="card-text p-1 mb-0 text-white text-break text-wrap">${message_html}</p>
<p class="text-right mb-0 p-1 text-white" style="text-align: right; font-size : 0.9rem">
<span class="text-light" style="font-size: 0.7rem;">${timestamp} - </span>
<span class="text-white" id="msg-${
obj._id
}-status" style="font-size:0.8rem;">${get_icon_for_state(
obj.status
)}</span>
<span class="text-white" id="msg-${obj._id}-status" style="font-size:0.8rem;">${get_icon_for_state(obj.status)}</span>
</p>
<span class="position-absolute top-0 start-100 translate-middle badge rounded-1 bg-primary border border-white">
<span id="msg-${obj._id}-attempts-badge" class="position-absolute top-0 start-100 translate-middle badge rounded-1 bg-primary border border-white">
<span id="msg-${
obj._id
}-attempts" class="">${attempt}/${max_attempts}</span>
<span id="msg-${obj._id}-attempts" class="">${attempt}/${max_retry_attempts}</span>
<span class="visually-hidden">retries</span>
</span>
<div class="progress p-0 m-0 rounded-0 rounded-bottom bg-secondary" style="height: 10px;">
@ -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);
});
};