diff --git a/package.nw/lib/gt.js b/package.nw/lib/gt.js index f46097e..3973acb 100644 --- a/package.nw/lib/gt.js +++ b/package.nw/lib/gt.js @@ -469,6 +469,7 @@ GT.unconfirmedCalls = new Map(); GT.tracker = {}; GT.lastTrasmissionTimeSec = timeNowSec(); +GT.getPostBuffer = getPostBuffer; const PSKREPORTER_INTERVAL_IN_SECONDS = 5 * 60; diff --git a/package.nw/lib/gtws.js b/package.nw/lib/gtws.js index bb0dfd2..4cb5224 100644 --- a/package.nw/lib/gtws.js +++ b/package.nw/lib/gtws.js @@ -567,7 +567,7 @@ function htmlEntities(str) .replace(/"/g, """); } -function sendSimplePushMessage(cid, jsmesg) +function sendSimplePushMessage(jsmesg) { const url = "https://api.simplepush.io/send"; let data = { key: GT.msgSettings.msgSimplePushApiKey, title: "GridTracker Chat Message", msg: jsmesg.call + ": " + jsmesg.msg }; @@ -584,7 +584,7 @@ function sendSimplePushMessage(cid, jsmesg) ); } -function sendPushOverMessage(cid, jsmesg) +function sendPushOverMessage(jsmesg) { const url = "https://api.pushover.net/1/messages.json"; let data = { @@ -631,12 +631,12 @@ function gtChatMessage(jsmesg) if (GT.msgSettings.msgSimplepush && GT.msgSettings.msgSimplePushApiKey != null) { - sendSimplePushMessage(cid, jsmesg); + sendSimplePushMessage(jsmesg); } if (GT.msgSettings.msgPushover && GT.msgSettings.msgPushoverUsername != null && GT.msgSettings.msgPushoverToken != null) { - sendPushOverMessage(cid, jsmesg); + sendPushOverMessage(jsmesg); } if (newChatMessage(cid, jsmesg) == false) alertChatMessage(); diff --git a/package.nw/lib/roster/sendAlerts.js b/package.nw/lib/roster/sendAlerts.js index 0d77830..b3e53ca 100644 --- a/package.nw/lib/roster/sendAlerts.js +++ b/package.nw/lib/roster/sendAlerts.js @@ -110,8 +110,95 @@ function sendAlerts(callRoster, rosterSettings) { conosle.log(e); } - CR.scriptReport = Object(); } - else CR.scriptReport = Object(); + if (window.opener.GT.msgSettings.msgPushover) + { + sendPushOverAlert(parseCRJson(CR.scriptReport)); + } + if (window.opener.GT.msgSettings.msgSimplepush) + { + sendSimplePushMessage(parseCRJson(CR.scriptReport)); + } + CR.scriptReport = Object(); } } + +function sendSimplePushMessage(message) +{ + const url = "https://api.simplepush.io/send"; + let data = { + key: window.opener.GT.msgSettings.msgSimplePushApiKey, + title: "GridTracker Alert " + window.opener.GT.appSettings.myCall, + msg: message + }; + window.opener.GT.getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "simplepush" + ); +} +function sendPushOverAlert(message) +{ + const url = "https://api.pushover.net/1/messages.json"; + let data = { + user: window.opener.GT.msgSettings.msgPushoverUsername, + token: window.opener.GT.msgSettings.msgPushoverToken, + title: + "GridTracker Alert " + window.opener.GT.appSettings.myCall, + message: message + }; + window.opener.GT.getPostBuffer( + url, + null, // callback, + null, + "https", + 443, + data, + 500, // timeoutMs, + null, // timeoutCallback, + "pushover" + ); +} + +function parseCRJson(data) +{ + let message = ""; + for (let callsign in data) + { + if (data[callsign].shouldAlert === true && data[callsign].alerted === false) + { + if (data[callsign].grid) + { + if (data[callsign].state) + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].grid + ", " + data[callsign].band + ", " + data[callsign].state + "\n"; + } + else + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].grid + ", " + data[callsign].band + "\n"; + } + } + else + { + if (!data[callsign].grid) + { + if (data[callsign].state) + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].band + ", " + data[callsign].state + "\n"; + } + else + { + message = message + callsign + ", " + data[callsign].dxccName + ", " + data[callsign].RSTsent.toString() + ", " + data[callsign].band + "\n"; + } + } + } + } + } + return message; +}