You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/messaging/messaging.md
+16-11Lines changed: 16 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,16 @@
4
4
5
5
### AngularFireMessaging is not compatible with the Angular Service Worker
6
6
7
-
If you are using the Angular Service Worker, you are not currently able to use AngularFireMessaging. If you'd like this feature please file an issue in [either repository](https://github.com/angular/angular/tree/master/packages/service-worker). Your alternatives are to use [WorkboxJS](https://developers.google.com/web/tools/workbox/) or just simply use the Firebase Messaging Service Worker, which is detailed below.
7
+
If you are using the Angular Service Worker, you are not currently able to use AngularFireMessaging.
8
+
If you'd like this feature please add your 👍 to [this issue](https://github.com/angular/angular/issues/34352).
- The Firebase Messaging Service Worker, which is detailed below
8
13
9
14
### Import the `NgModule`
10
15
11
-
Push Notifications for AngularFire is contained in the `@angular/fire/messaging` module namespace. Import the `AngularFireMessagingModule` in your `NgModule`. This sets up the `AngularFireMessaging` service for dependency injection.
16
+
Push Notifications for AngularFire are contained in the `@angular/fire/messaging` module namespace. Import the `AngularFireMessagingModule` in your `NgModule`. This sets up the `AngularFireMessaging` service for dependency injection.
### Setting up the Firebase Messaging Service Worker
34
39
35
-
There are two parts Firebase Messaging, a Service Worker and the DOM API. AngularFireMessaging allows you to request permission, get tokens, delete tokens, and subscribe to messages on the DOM side. To register to receive notifications you need to set up the Service Worker. [The official Firebase documentation for setting up the details exactly how to do that](https://firebase.google.com/docs/cloud-messaging/js/client).
40
+
There are two parts to Firebase Messaging, a Service Worker and the DOM API. AngularFireMessaging allows you to request permission, get tokens, delete tokens, and subscribe to messages on the DOM side. To register to receive notifications you need to set up the Service Worker. [The official Firebase documentation for setting up the details exactly how to do that](https://firebase.google.com/docs/cloud-messaging/js/client).
36
41
37
-
You can either use the `firebase-messaging-sw.js` file provided in the docs or you can set your own Service Worker to import that script. Make sure to set up your `.angular-cli.json` file to copy over the Service Worker file:
42
+
You can either use the `firebase-messaging-sw.js` file provided in the docs or you can set your own Service Worker to import that script. Make sure to set up your `angular.json` file to copy over the Service Worker file:
38
43
39
44
```json
40
45
"assets": [
@@ -47,7 +52,7 @@ You can either use the `firebase-messaging-sw.js` file provided in the docs or y
47
52
48
53
### Requesting permission
49
54
50
-
Once you have the Firebase Messaging Service Worker setup and installed, you need to request permission to send a user notifications. While the browser will popup a UI for you, it is highly recommend to ask the user for permission with a custom UI and only ask when it makes sense. If you blindly ask for permission you have an extremely high chance of getting denied.
55
+
Once you have the Firebase Messaging Service Worker set up and installed, you need to request permission to send a user notifications. While the browser will popup a UI for you, it is highly recommend to ask the user for permission with a custom UI and only ask when it makes sense. If you blindly ask for permission, you have an extremely high chance of getting denied or blocked.
51
56
52
57
```ts
53
58
import { Component } from'@angular/core';
@@ -57,7 +62,7 @@ import { AngularFireMessaging } from '@angular/fire/messaging';
57
62
selector: 'app-root',
58
63
template: `
59
64
<button (click)="requestPermission()">
60
-
Hey this is a chat app, you should let us send you notifications for these reasons!
65
+
Hello this is a chat app. You should let us send you notifications for this reason.
61
66
</button>
62
67
`
63
68
})
@@ -84,7 +89,7 @@ import { mergeMapTo } from 'rxjs/operators';
84
89
selector: 'app-root',
85
90
template: `
86
91
<button (click)="requestPermission()">
87
-
Hey this is a chat app, you should let us send you notifications for these reasons!
92
+
Hello this is a chat app. You should let us send you notifications for this reason.
88
93
</button>
89
94
`
90
95
})
@@ -101,7 +106,7 @@ export class AppComponent {
101
106
}
102
107
```
103
108
104
-
Once you have a user's token, you need to save it to the server in order to send them notifications in response to events. Let's say ou want to send a push each time a user sends a chat message. Once a user grants permission, you can send the token to the Realtime Database or Cloud Firestore and associate it with a unique id, like a Firebase Auth UID. You can then create a Cloud Function trigger that looks up the user's token when a chat message is created.
109
+
Once you have a user's token, you need to save it to the server in order to send them notifications in response to events. Let's say you want to send a push each time a user sends a chat message. Once a user grants permission, you can send the token to the Realtime Database or Cloud Firestore and associate it with a unique id, like a Firebase Auth UID. You can then create a Cloud Function trigger that looks up the user's token when a chat message is created.
105
110
106
111
### Shortcutting token requests
107
112
@@ -115,7 +120,7 @@ import { AngularFireMessaging } from '@angular/fire/messaging';
115
120
selector: 'app-root',
116
121
template: `
117
122
<button (click)="requestPermission()">
118
-
Hey this is a chat app, you should let us send you notifications for these reasons!
123
+
Hello this is a chat app. You should let us send you notifications for this reason.
119
124
</button>
120
125
`
121
126
})
@@ -146,7 +151,7 @@ import { mergeMap } from 'rxjs/operators';
@@ -61,9 +61,9 @@ Using the `SETTINGS` DI Token (*default: {}*) will allow you to [configure Fireb
61
61
62
62
### Configure default values with `DEFAULTS`
63
63
64
-
Providing `DEFAULTS ({[key: string]: string | number | boolean})`has`AngularFireRemoteConfig` emit the provided defaults first, which allows you to count on Remote Config when the user is offline or in environments that the Remote Config service does not handle (i.e, Server Side Rendering).
64
+
Providing `DEFAULTS ({[key: string]: string | number | boolean})`tells`AngularFireRemoteConfig`to emit the provided defaults first. This allows you to count on Remote Config when the user is offline or in environments that the Remote Config service does not handle (i.e. Server Side Rendering).
// budget at most 800ms and return the freshest value possible in that time
115
-
// our budget pipe is similar to timeout but won't error or abort the pending server fetch (it won't emit it, if the deadline is exceeded, but it will have been fetched so can use the freshest values on next subscription)
115
+
// our budget pipe is similar to timeout but won't error or abort the pending server fetch
116
+
// (it won't emit it, if the deadline is exceeded, but it will have been fetched so can use the
117
+
// freshest values on next subscription)
116
118
budget(800),
117
119
last()
118
120
).subscribe(...)
119
121
120
-
// just like .changes, but scanned as into an array
122
+
// just like .changes, but scanned into an array
121
123
remoteConfig.parameters.subscribe(all=>...);
122
124
123
125
// or make promisified firebase().remoteConfig() calls direct off AngularFireRemoteConfig
0 commit comments