@@ -14,7 +14,6 @@ notification_options = {
14
14
}
15
15
16
16
function dispatchNotification ( ) {
17
- console . log ( 'dispatchingNotification' ) ;
18
17
self . registration . showNotification ( 'Please continue your Survey' , notification_options ) ;
19
18
20
19
}
@@ -31,18 +30,41 @@ self.addEventListener('activate', function(event) {
31
30
32
31
33
32
self . addEventListener ( 'push' , function ( event ) {
34
- console . log ( 'Got a push event' ) ;
35
33
if ( ! ( self . Notification && self . Notification . permission === 'granted' ) ) {
36
34
return ;
37
35
}
38
- dispatchNotification ( ) ;
36
+
37
+ if ( event . data ) {
38
+ console . log ( 'there is data...' ) ;
39
+ var data = event . data . json ( ) ;
40
+ console . log ( data ) ;
41
+ console . log ( data . msg ) ;
42
+ console . log ( data . url ) ;
43
+ }
44
+ let notification_options = {
45
+ "icon" : "assets/site/img/logo.png" ,
46
+ "image" : "assets/site/img/logo.png" ,
47
+ "vibrate" : [ 300 , 100 , 400 ] ,
48
+ "requireInteraction" : true ,
49
+ "data" : data ,
50
+ tag : 'renotify' ,
51
+ renotify : true ,
52
+ }
53
+
54
+ self . registration . showNotification ( data . msg , notification_options ) ;
55
+
56
+ //dispatchNotification();
39
57
} ) ;
40
58
41
59
self . addEventListener ( 'notificationclick' , function ( event ) {
42
60
var notification = event . notification ;
43
61
var action = event . action ;
44
62
45
- console . log ( notification ) ;
63
+ if ( event . notification . data ) {
64
+ console . log ( event . notification . data ) ;
65
+ console . log ( event . notification . data . msg ) ;
66
+ console . log ( event . notification . data . url ) ;
67
+ }
46
68
47
69
if ( action === 'confirm' ) {
48
70
console . log ( 'Confirm was chosen' ) ;
@@ -57,10 +79,10 @@ self.addEventListener('notificationclick', function(event) {
57
79
} ) ;
58
80
59
81
if ( client !== undefined ) {
60
- client . navigate ( 'https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest' ) ;
82
+ client . navigate ( event . notification . data . url ) ;
61
83
client . focus ( ) ;
62
84
} else {
63
- clients . openWindow ( 'https://www.uni-muenster.de/PsyTD/formr-entwicklung/NeuesQueuingSystemTest' ) ;
85
+ clients . openWindow ( event . notification . data . url ) ;
64
86
}
65
87
notification . close ( ) ;
66
88
} )
0 commit comments