Notifications Configurations added for web

This commit is contained in:
Eudes Inácio
2021-06-23 09:19:09 +01:00
parent dada970484
commit a6dbd09473
8 changed files with 254 additions and 76 deletions
+63 -3
View File
@@ -3990,6 +3990,13 @@
"debug": "^4.1.0",
"depd": "^1.1.2",
"humanize-ms": "^1.2.1"
},
"dependencies": {
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
}
}
},
"aggregate-error": {
@@ -4687,6 +4694,11 @@
"ms": "2.0.0"
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@@ -9243,9 +9255,9 @@
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="
},
"dependency-graph": {
"version": "0.7.2",
@@ -10025,6 +10037,11 @@
"ms": "2.0.0"
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
@@ -11003,6 +11020,11 @@
"toidentifier": "1.0.0"
},
"dependencies": {
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
@@ -11214,6 +11236,16 @@
"ms": "^2.0.0"
}
},
"ibm-mfp-web-push": {
"version": "8.0.2020052213",
"resolved": "https://registry.npmjs.org/ibm-mfp-web-push/-/ibm-mfp-web-push-8.0.2020052213.tgz",
"integrity": "sha512-I7Jv7Blagw7Ha7GtEJHnzvYiUop5g8c6ni0OrXddzuUPAzzdepyfPPA2or+chnYrYanSrX5H0RI+ZX97ChIXWw==",
"requires": {
"jssha": "^2.3.1",
"promiz": "^1.0.5",
"sjcl": "^1.0.8"
}
},
"ical.js": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/ical.js/-/ical.js-1.4.0.tgz",
@@ -12326,6 +12358,11 @@
}
}
},
"jssha": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/jssha/-/jssha-2.4.2.tgz",
"integrity": "sha512-/jsi/9C0S70zfkT/4UlKQa5E1xKurDnXcQizcww9JSR/Fv+uIbWM2btG+bFcL3iNoK9jIGS0ls9HWLr1iw0kFg=="
},
"jszip": {
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.6.0.tgz",
@@ -16106,6 +16143,11 @@
}
}
},
"promiz": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/promiz/-/promiz-1.0.5.tgz",
"integrity": "sha1-8m/bKYdWWJeC9lCaax61SnA40zU="
},
"promzard": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/promzard/-/promzard-0.3.0.tgz",
@@ -17494,6 +17536,11 @@
}
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
@@ -17544,6 +17591,14 @@
"inherits": "2.0.3",
"setprototypeof": "1.1.0",
"statuses": ">= 1.4.0 < 2"
},
"dependencies": {
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=",
"dev": true
}
}
},
"inherits": {
@@ -17784,6 +17839,11 @@
"is-arrayish": "^0.3.1"
}
},
"sjcl": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.8.tgz",
"integrity": "sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ=="
},
"slash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
+4 -4
View File
@@ -53,8 +53,8 @@
"@ng-bootstrap/ng-bootstrap": "^9.1.2",
"angular-calendar": "^0.28.22",
"angular-tag-cloud-module": "^5.2.2",
"cordova": "^10.0.0",
"bootstrap": "^4.5.0",
"cordova": "^10.0.0",
"cordova-plugin-camera": "^5.0.1",
"cordova-plugin-filepath": "^1.5.8",
"cordova-plugin-okhttp": "^2.0.0",
@@ -62,6 +62,8 @@
"cordova-sqlite-storage": "^5.1.0",
"crypto-js": "^4.0.0",
"date-fns": "^2.17.0",
"depd": "^2.0.0",
"ibm-mfp-web-push": "^8.0.2020052213",
"ionic-angular": "^3.9.10",
"ionic-selectable": "^4.7.1",
"ionic2-alpha-scroll": "^2.0.1",
@@ -127,9 +129,7 @@
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-camera": {
+2 -32
View File
@@ -18,6 +18,7 @@ import { ApproveEventModalPage } from '../pages/gabinete-digital/event-list/appr
import { PublicationDetailPage } from '../pages/publications/view-publications/publication-detail/publication-detail.page';
import { ToastService } from '../services/toast.service';
import { SuccessMessagePage } from '../shared/popover/success-message/success-message.page';
//import MFPPush from 'ibm-mfp-web-push';
/* const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins; */
@@ -78,11 +79,7 @@ export class HomePage implements OnInit {
}
ngOnInit() {
if (this.platform.is('desktop')) {
console.log('Notifications not supported')
} else {
this.wlCommonInit();
}
this.count();
}
@@ -120,34 +117,7 @@ export class HomePage implements OnInit {
}
mobileFirstTest() {
WLAuthorizationManager.obtainAccessToken("").then(
(token) => {
console.log('MobileFirst Server connect: Success ' + token);
var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/",
WLResourceRequest.GET
);
resourceRequest.setQueryParameter("name", "world");
resourceRequest.send().then(
(response) => {
// Will display "Hello world" in an alert dialog.
console.log("Connect with JavaAdapter Success: " + response.responseText);
//this.MFPushNotification();
},
(error) => {
alert("Connect with JavaAdapter Failure: " + JSON.stringify(error));
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure ' + error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
alert("Bummer...");
alert("Failed to connect to MobileFirst Server");
}); */
}
);
}
mobileFirstPush() {
@@ -166,7 +136,7 @@ export class HomePage implements OnInit {
);
MFPPush.registerDevice(null, function (successResponse) {
console.log("Successfully registered: " + successResponse);
console.log("Successfully registered: " + JSON.stringify(successResponse) );
},
function (failureResponse) {
console.log("Successfully failue: " + failureResponse);
+117
View File
@@ -0,0 +1,117 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
/* eslint-disable no-restricted-globals */
const regex = /{{\s*([^}]+)\s*}}/g;
var _pushVaribales = "";
function interpolate(messageData) {
return function interpolate(o) {
return messageData.replace(regex, function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
});
}
}
function createTemplateMessage(messageData) {
if (Object.keys(_pushVaribales).length > 0 ) {
var message = interpolate(messageData)(_pushVaribales);
return message;
} else {
return messageData;
}
}
function displayNotification(event) {
var messageJson = event.data.text();
messageJson = JSON.parse(messageJson);
var title = messageJson.title ? messageJson.title : "New message";
var imageUrl = messageJson.iconUrl ? messageJson.iconUrl : "images/icon.png";
// var tagJson = messageJson.payload;
// var tag = tagJson.tag ? tagJson.tag : "";
var bodyAlert = messageJson.alert ? messageJson.alert : "Example message"
var payloadData = messageJson.payload ? messageJson.payload : "Example message"
let messageTemp;
if ((messageTemp = regex.exec(bodyAlert)) !== null) {
bodyAlert = createTemplateMessage(bodyAlert);
}
self.registration.showNotification(title, {
body: bodyAlert,
icon: imageUrl,
data: payloadData,
// tag: tag
});
return Promise.resolve();
}
function triggerSeenEvent(strMsg) {
send_message_to_all_clients("msgEventSeen:" + strMsg);
}
function triggerOpenEvent(strMsg) {
send_message_to_all_clients("msgEventOpen:" + strMsg);
}
function onPushNotificationReceived(event) {
console.log('Push notification received : ', event);
if (event.data) {
console.log('Event data is : ', event.data.text());
}
event.waitUntil(displayNotification(event).then(() => triggerSeenEvent(event.data.text())));
};
self.addEventListener('push', onPushNotificationReceived);
function send_message_to_client(client, msg) {
return new Promise(function (resolve, reject) {
var msg_chan = new MessageChannel();
msg_chan.port1.onmessage = function (event) {
if (event.data.error) {
reject(event.data.error);
} else {
resolve(event.data);
}
};
client.postMessage(msg, [msg_chan.port2]);
});
}
function send_message_to_all_clients(msg) {
clients.matchAll().then(clients => {
clients.forEach(client => {
send_message_to_client(client, msg);
})
});
}
self.addEventListener('install', function (event) {
self.skipWaiting();
console.log('Installed Service Worker : ', event);
//event.postMessage("SW Says 'Hello back!'");
});
self.addEventListener('message', function (event) {
replyPort = event.ports[0];
_pushVaribales = event.data;
});
self.addEventListener('activate', function (event) {
console.log('Activated Service Worker : ', event);
event.waitUntil(self.clients.claim());
});
self.addEventListener('notificationclick', function (event) {
console.log('Notification clicked with tag' + event.notification.tag + " and data " + event.notification.data);
let nidjson = event.notification.data;
event.notification.close();
event.waitUntil(triggerOpenEvent(nidjson));
});
self.addEventListener('pushsubscriptionchange', function () {
console.log('Push Subscription change');
send_message_to_all_clients("updateRegistration:");
});
+4 -7
View File
@@ -1,11 +1,5 @@
function wlCommonInit() {
}
function mobileFirstTest() {
WLAuthorizationManager.obtainAccessToken("").then(
(token) => {
console.log('MobileFirst Server connect: Success ' + token);
@@ -34,4 +28,7 @@ function mobileFirstTest() {
}); */
}
);
}
}
+2 -2
View File
@@ -2,7 +2,7 @@ function wlCommonInit(){
// Override the default Direct Update interface.
//uncomment below function to get custom DU
/* wl_directUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
wl_directUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData, directUpdateContext) {
// Create a dialog.
navigator.notification.confirm(
'Actualização Disponivel',
@@ -17,6 +17,6 @@ function wlCommonInit(){
'Actualização Disponivel',
['Actualizar']
);
}; */
};
}
+4
View File
@@ -0,0 +1,4 @@
{
"name": "com.gpr.gabinetedigital",
"gcm_sender_id": "800733765231"
}
+30
View File
@@ -9,6 +9,35 @@
<script src="assets/js/index.js"></script>
<script src="assets/js/wldirectudpate.js"></script>
<script>
if (navigator.serviceWorker) {
navigator.serviceWorker.register("assets/js/MFPPushServiceWorker.js").then(function(reg) {
window.pushReg = reg;
if (reg.installing) {
console.info('Service worker installing');
} else if (reg.waiting) {
console.info('Service worker installed');
} else if (reg.active) {
console.info('Service worker active');
}
if (!(reg.showNotification)) {
console.info('Notifications aren\'t supported on service workers.');
}
// Check if push messaging is supported
if (!('PushManager' in window)) {
console.info("Push messaging isn't supported.");
}
if (Notification.permission === 'denied') {
console.info('The user has blocked notifications.');
}
}).catch(err => {
console.error(JSON.stringify(err));
});
} else {
console.info("Service workers aren't supported in this browser.");
}
</script>
<meta name="color-scheme" content="light dark" />
<meta name="viewport" content="viewport-fit=cover, width=device-width, height=device-hight, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
@@ -19,6 +48,7 @@
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.png" />
<link rel="manifest" href="assets/json/manifest.json">
<!-- add to homescreen for ios -->
<meta name="apple-mobile-web-app-capable" content="yes" />