web-manager 3.2.69 → 3.2.71
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +28 -8
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1088,13 +1088,13 @@ Manager.prototype.notifications = function(options) {
|
|
1088
1088
|
},
|
1089
1089
|
)
|
1090
1090
|
.then(function(data) {
|
1091
|
-
// self.log('Updated token:
|
1091
|
+
// self.log('Updated token:', token);
|
1092
1092
|
saveLocal();
|
1093
1093
|
resolve(true);
|
1094
1094
|
})
|
1095
1095
|
} else {
|
1096
1096
|
saveLocal();
|
1097
|
-
// self.log('Skip sync
|
1097
|
+
// self.log('Skip sync because server data exists');
|
1098
1098
|
resolve(false);
|
1099
1099
|
}
|
1100
1100
|
}
|
@@ -1109,7 +1109,7 @@ Manager.prototype.notifications = function(options) {
|
|
1109
1109
|
saveServer({exists: false})
|
1110
1110
|
})
|
1111
1111
|
} else {
|
1112
|
-
// self.log('Skip sync
|
1112
|
+
// self.log('Skip sync because recently done');
|
1113
1113
|
resolve(false);
|
1114
1114
|
}
|
1115
1115
|
|
@@ -1147,7 +1147,10 @@ function subscriptionManager(self, options_user) {
|
|
1147
1147
|
}))
|
1148
1148
|
)
|
1149
1149
|
.then(function (registration) {
|
1150
|
+
// Force Firebase to use the service worker
|
1150
1151
|
// firebase.messaging().useServiceWorker(registration);
|
1152
|
+
|
1153
|
+
// Set the registration to the properties
|
1151
1154
|
self.properties.references.serviceWorker = registration;
|
1152
1155
|
|
1153
1156
|
// TODO: https://googlechrome.github.io/samples/service-worker/post-message/
|
@@ -1187,19 +1190,36 @@ function subscriptionManager(self, options_user) {
|
|
1187
1190
|
//@@@NOTIFICATIONS
|
1188
1191
|
// _setupTokenRefreshHandler(self);
|
1189
1192
|
|
1193
|
+
// Force update the service worker
|
1194
|
+
registration.update();
|
1195
|
+
|
1196
|
+
// Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
|
1190
1197
|
try {
|
1191
|
-
// Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
|
1192
1198
|
firebase.messaging().onMessage(function (payload) {
|
1193
|
-
|
1199
|
+
// Get the notification data
|
1200
|
+
var notification = payload.notification;
|
1201
|
+
|
1202
|
+
// Log
|
1203
|
+
console.log('Message received', payload);
|
1204
|
+
|
1205
|
+
// Display notification
|
1206
|
+
new Notification(notification.title, notification)
|
1194
1207
|
.onclick = function(event) {
|
1195
|
-
|
1196
|
-
|
1208
|
+
// Quit if there is no click action
|
1209
|
+
if (!notification.click_action) {
|
1210
|
+
return;
|
1211
|
+
}
|
1212
|
+
|
1213
|
+
// prevent the browser from focusing the Notification's tab
|
1214
|
+
event.preventDefault();
|
1215
|
+
|
1216
|
+
// Open the click action
|
1217
|
+
window.open(notification.click_action, '_blank');
|
1197
1218
|
}
|
1198
1219
|
})
|
1199
1220
|
} catch (e) {
|
1200
1221
|
console.error(e);
|
1201
1222
|
}
|
1202
|
-
|
1203
1223
|
})
|
1204
1224
|
.catch(function (e) {
|
1205
1225
|
// console.log('***2');
|
package/package.json
CHANGED