call roster notifications using push notifications

This commit is contained in:
Christian Bayer 2023-08-30 23:06:10 -04:00
parent 361e5653c2
commit 0500aecfb1
No known key found for this signature in database
GPG key ID: 090D0F8B431A7C88
3 changed files with 94 additions and 6 deletions

View file

@ -469,6 +469,7 @@ GT.unconfirmedCalls = new Map();
GT.tracker = {};
GT.lastTrasmissionTimeSec = timeNowSec();
GT.getPostBuffer = getPostBuffer;
const PSKREPORTER_INTERVAL_IN_SECONDS = 5 * 60;

View file

@ -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();

View file

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