@quintype/framework 7.33.6-fcm-fix-2.1 → 7.33.6-fcm-fix-2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,17 +14,37 @@ export function initializeFCM (firebaseConfig) {
14
14
  appId: firebaseConfig.appId
15
15
  })
16
16
  const messaging = m.getMessaging(app)
17
- m.onMessage(messaging, ({ notification }) => {
18
- console.log('========notification', messaging, notification)
19
- new Notification(notification.title, {
20
- body: notification.body,
21
- icon: notification.icon
22
- })
23
- })
17
+
24
18
  // No need to refresh token https://github.com/firebase/firebase-js-sdk/issues/4132
19
+ requestPermission(m, firebaseConfig)
25
20
  })
26
21
  .catch(err => {
27
22
  console.log('fcm initialization error---------', err)
28
23
  console.error(err)
29
24
  })
30
25
  }
26
+
27
+ async function requestPermission (m, firebaseConfig) {
28
+ console.log('request oermission------')
29
+ //requesting permission using Notification API
30
+ const permission = await Notification.requestPermission()
31
+
32
+ if (permission === 'granted') {
33
+ const token = await getToken(messaging, {
34
+ vapidKey: firebaseConfig.vapidKey
35
+ })
36
+
37
+ //We can send token to server
38
+ console.log('Token generated : ', token)
39
+ m.onMessage(messaging, ({ notification }) => {
40
+ console.log('========notification', messaging, notification)
41
+ new Notification(notification.title, {
42
+ body: notification.body,
43
+ icon: notification.icon
44
+ })
45
+ })
46
+ } else if (permission === 'denied') {
47
+ //notifications are blocked
48
+ alert('You denied for the notification')
49
+ }
50
+ }
package/client/start.js CHANGED
@@ -307,6 +307,7 @@ export function startApp(renderApplication, reducers, opts) {
307
307
  const mssgSenderId = fcm.messagingSenderId;
308
308
  const projectId = fcm.projectId;
309
309
  const apiKey = fcm.apiKey;
310
+ console.log("fcm start app")
310
311
  if (mssgSenderId && projectId && apiKey) initializeFCM(fcm);
311
312
  }
312
313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.33.6-fcm-fix-2.1",
3
+ "version": "7.33.6-fcm-fix-2.2",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {