Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Albin Geraud Kouatcho Nkuigwa
PSE_Projekt
Commits
9cdcda2a
Commit
9cdcda2a
authored
Jun 20, 2018
by
Janik Münzenberger
Browse files
Notification onlick
parent
e9affafd
Changes
4
Hide whitespace changes
Inline
Side-by-side
package.json
View file @
9cdcda2a
...
...
@@ -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"
:
{
...
...
src/backend/controller/notification.js
View file @
9cdcda2a
...
...
@@ -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
:
'
../asset
s/icon.png
'
,
icon
:
'
/upload
s/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
));
}
...
...
src/service-worker/plugins/custom-listeners.js
0 → 100644
View file @
9cdcda2a
src/service-worker/rollup.js
0 → 100644
View file @
9cdcda2a
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment