Commit 9cdcda2a authored by Janik Münzenberger's avatar Janik Münzenberger
Browse files

Notification onlick

parent e9affafd
......@@ -11,14 +11,14 @@
"start": "npm run backend",
"live": "ng serve",
"deploy": "node ./src/backend/server.js && ng build --prod",
"build": "ng build --prod",
"build": "ng build --prod && node ./src/service-worker/rollup.js",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"backend": "set NODE_ENV=prod&& node ./src/backend/server.js",
"backend_dev": "set NODE_ENV=dev&& nodemon ./src/backend/server.js",
"backend_test": "set NODE_ENV=test&& mocha ./src/backend/test/ --timeout 15000 --exit",
"postinstall": "ng build --aot --prod"
"postinstall": "ng build --aot --prod && node ./src/service-worker/rollup.js"
},
"private": true,
"dependencies": {
......
......@@ -6,7 +6,7 @@ const winston = require('winston');
function postNotification (req, res) {
const subscription = req.body.subscription;
console.log(subscription);
const notificationPayload = {
notification: {
title: "You`re result is there!",
......@@ -14,7 +14,7 @@ function postNotification (req, res) {
icon: '/uploads/icon.png',
vibrate: [100, 50, 100],
data: {
url: "localhost:3000/result/" + req.body.job
url: "/result/" + req.body.job
}
}
};
......@@ -25,13 +25,13 @@ function postNotification (req, res) {
}
function sendPushNotification(job){
const url = `${config.base_url}/result/${job._id}`;
const url = `/result/${job._id}`;
const notificationPayload = {
notification: {
title: "You`re result is there!",
body: `We received the results for your analysed plant! Follow ${url}`,
icon: '../assets/icon.png',
icon: '/uploads/icon.png',
vibrate: [100, 50, 100],
data: {
url: url
......@@ -39,7 +39,7 @@ function sendPushNotification(job){
}
};
winston.info("Sending push notification!");
console.log(job.subscription);
pushWeb.sendNotification(JSON.parse(job.subscription), JSON.stringify(notificationPayload))
.catch(err => winston.error(err));
}
......
const fs = require('fs');
const search = "this.scope.addEventListener('push', (event) => this.onPush(event));";
const ngsw_worker = "./dist/ngsw-worker.js";
const code = `\nthis.scope.addEventListener('notificationclick', (event) => {
console.log('[Service Worker] Notification click Received. event', event);
event.notification.close();
console.log(event.notification.data.url);
if (clients.openWindow && event.notification.data.url) {
event.waitUntil(clients.openWindow(event.notification.data.url));
}
});`;
console.log('Rollup: Modify ngsw-worker.js for notificationclick event');
fs.readFile(ngsw_worker, (err, text)=> {
if(err) {
console.error(err);
throw err;
}
else{
let insertIndex = text.indexOf(search) + search.length;
let t = Buffer.concat([
text.subarray(0, insertIndex),
Buffer.from(code, 'utf-8'),
text.subarray(insertIndex, text.length)]);
fs.writeFile(ngsw_worker, t, (err) => {
if(err){
console.error(err);
throw err;
}
});
}
});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment