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
{{ message }}
Repository navigation
AngularFireMessaging is not compatible with the Angular Service Worker聽#34352
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. Your alternatives are to use WorkboxJS or just simply use the Firebase Messaging Service Worker, which is detailed below.
In the same situation. Currently having to add my own .js to overrule the Angular SW, which is very against my principles (100% .TS).
Also I have to skip DI:
export class NotificationRealService implements INotificationService {
messaging;
fcmToken: string;
currentMessage = new BehaviorSubject(null);
// Dont DI inject firebase messaging if you want Brave to work (meh)
constructor(@Inject(HTTP_CLIENT) private http: HttpClient,
@Inject('API_URL') private apiUrl: string,
@Inject('API2_URL') private api2Url: string,
@Inject(SNACKBAR_SERVICE) private snackBarService: SnackBarService,
@Inject(USER_SERVICE) private userService: UserService) {
if (!firebase.apps.length) {
firebase.initializeApp(environment.firebase);
this.messaging = firebase.messaging();
navigator.serviceWorker.getRegistration().then(swr => firebase.messaging().useServiceWorker(swr));
}
}
Reacted by davidzwa, Leonel Franchelli, Johan CHOUQUET, Darryl Brown, Claudio Del Valle, Camille V, Francesco Colasante, William Martins, JJ, Muhammad Zoabi and 6 more
Don't we all need FCM in our PWA though? (Not just on the web) How come this is not working, they are 2 Google products.
How can we help to speed up this process?
Sorry, no full working app example on shareable Github (private project), but if you create a Stackblitz, happy to look at where you getting stuck and add PWA code as intended in earlier post.
ps you are aware the Firebase Messaging SDK does not work on iOS devices?
To avoid any confusion regarding the deleted comment from yesterday, it is perfectly right to use a common value (e.g. 103953800507) for gcm_sender_id in the manifest. Source : Frank van Puffelen, Engineer at Firebase
Hello all, can anyone tell me why AngularFireMessaging is not compatible with the Angular Service Worker and what's the impact of having both working simultaneously?
Hello all, can anyone tell me why AngularFireMessaging is not compatible with the Angular Service Worker and what's the impact of having both working simultaneously?
Reading for the responses before and the renewed README on AngularFire messaging you can see it IS compatible and works flawlessly with the Angular service worker. You just need to configure it to use it.
I cant comment on having two service workers besides each other, but plainly for messaging and e.g. offline support, there is no need to have two.
The AngularFire team may do themselves a favour and posting a blog on blog.angular.io saying how cool it all works with the Angular service worker
First of all, thanks for your answer @Tommertom :)
But I'm working with Azure Notification Hub, and in order to create or update an installation/register based on any device, I need to send its device's token as a handle. Using AngularFireMessaging was easy because I could just call requestToken() and I got it. On the other hand, using Push API I got a PushSubscription object, which contains an endpoint, a pair of keys and an expirationTime.
Is there a way to register a device using a PushSubscription object?
In fact, I believe the readme should not say it is impossible. It just uses the default firebase sw which you need to overrule.
Snippets of code:
package.json
"@angular/fire": "^6.1.4",
"firebase": "^7.0 || ^8.0",
"@angular/service-worker": "~10.0.0",
import { FirebaseApp } from '@angular/fire';
....
constructor(
private swUpdate: SwUpdate,
private swPush: SwPush,
private firebase: FirebaseApp,
) { }
....
const serviceWorkerRegistration = await navigator.serviceWorker.getRegistration();
const messaging = this.firebase.messaging();
console.log('MESSAGING SW', serviceWorkerRegistration);
messaging.getToken({
vapidKey:
'BEYQVzBmAoN4......X0mpSy9sHSinAHyhBT534cwwrkr49A1qqNg-M',
serviceWorkerRegistration // this should be the fix for angularfire not working with ngsw
}
).then((currentToken) => {
console.log('TOKEN', currentToken);
this.swPush.messages.subscribe(msg => console.log('push message', msg));
this.swPush.notificationClicks.subscribe(click => console.log('notification click', click));
....
I tried building a porject like the one in the article that you posted. I struggle at the following point: if (!firebase.apps.length) { firebase.initializeApp(environment.firebase); navigator.serviceWorker.getRegistration().then(swr=> firebase.messaging().useServiceWorker(swr)); }
I saw you edited the constructor at the point quite a lot, but I can't figure out how to get it to work, even with your code snippets.
firebase.messaging().useServiceWorker(swr) in this line as swr is coming undefined inside getRegistration().then(swr).
if you could tell me how to fix the problem I would be really glad...
@Cironic, this might happen because the SW might not have been registered yet (it depends on the registrationStrategy). You could listener to controllerchange events before retrieving the SW registration; something like:
import{fromEvent,of}from'rxjs';import{filter,map,startWith,switchMap,take}from'rxjs/operators';// ...constswRegistration$=fromEvent(navigator.serviceWorker,'controllerchange').pipe(startWith(null),map(()=>navigator.serviceWorker.controller),filter((c): c is ServiceWorker=>!!c),// Uncomment the following line if you only need the first value. // take(1),switchMap(()=>navigator.serviceWorker.getRegistration()),);swRegistration$.subscribe(reg=>/* Pass `reg` to Firebase messaging. */);
@gkalpak, I hope you can help me, since I don't really get how to use your code in the example of the medium article.
Since the problem occurs in the constructor. EDIT: it worked all fine with @angular-devkit/build-angular": "~0.803.12"
And maybe you can answer me another question:
for Firebase messaging implementation is it correct to register the ngsw-worker as Serviceworker and not the firebase-messaging-sw?
AFAICT, the latest version of AnguarFireMessaging (AFM) is compatible with the Angular ServiceWorker (NGSW). The AngularFire team is working on documenting how to configure AFM to work with NGSW. For more details see angular/angularfire#1923 (reply in thread).
Based on that, I am going to close this issue. If there is anything else that needs to be fixed in the NGSW, please open a new issue.
Reacted by davidzwa, Ruben, donduni, irvjc82 and Fallenzone
Activity
spock123 commentedon Dec 12, 2019
Yeah I'm in the same situation, wanting to use Firebase (AnguilarFire) for messaging, finding it doesn't play well with the Angular Service Worker..
hcassar93 commentedon Dec 25, 2019
davidzwa commentedon Dec 31, 2019
In the same situation. Currently having to add my own .js to overrule the Angular SW, which is very against my principles (100% .TS).
Also I have to skip DI:
export class NotificationRealService implements INotificationService { messaging; fcmToken: string; currentMessage = new BehaviorSubject(null); // Dont DI inject firebase messaging if you want Brave to work (meh) constructor(@Inject(HTTP_CLIENT) private http: HttpClient, @Inject('API_URL') private apiUrl: string, @Inject('API2_URL') private api2Url: string, @Inject(SNACKBAR_SERVICE) private snackBarService: SnackBarService, @Inject(USER_SERVICE) private userService: UserService) { if (!firebase.apps.length) { firebase.initializeApp(environment.firebase); this.messaging = firebase.messaging(); navigator.serviceWorker.getRegistration().then(swr => firebase.messaging().useServiceWorker(swr)); } }N-Andronopoulos commentedon Jan 15, 2020
Related to #26413
johanchouquet commentedon Apr 17, 2020
Hi there,
What's the status of this issue please ?
Thanks a lot!
floogulinc commentedon May 5, 2020
Now that the Angular service worker has its own support for push notifications will that allow for using FCM with it?
dhrn commentedon May 11, 2020
davidzwa commentedon May 13, 2020
I found this recent blog https://blog.angular-university.io/angular-push-notifications/
with this github repo (note the branch) https://github.com/angular-university/angular-pwa-course/tree/1-notifications-finished.
I'd keep your implementation as FCM-less as possible: use a VAPID key and let SwPush figure out the rest:
I for one will be removing my firebase installs + sw override, because it is a great pain so far in Angular.
razfriman commentedon Jul 16, 2020
Would love this as well
11 remaining items
rubenheymans commentedon Jan 5, 2021
Don't we all need FCM in our PWA though? (Not just on the web) How come this is not working, they are 2 Google products.
How can we help to speed up this process?
jaspervanmegroot commentedon Jan 13, 2021
Do you maybe have an example on Github?
Tommertom commentedon Jan 13, 2021
Sorry, no full working app example on shareable Github (private project), but if you create a Stackblitz, happy to look at where you getting stuck and add PWA code as intended in earlier post.
ps you are aware the Firebase Messaging SDK does not work on iOS devices?
jornetsimon commentedon Feb 23, 2021
To avoid any confusion regarding the deleted comment from yesterday, it is perfectly right to use a common value (e.g. 103953800507) for gcm_sender_id in the manifest.
Source : Frank van Puffelen, Engineer at Firebase
rewtelize commentedon Mar 2, 2021
Hello all, can anyone tell me why AngularFireMessaging is not compatible with the Angular Service Worker and what's the impact of having both working simultaneously?
Tommertom commentedon Mar 2, 2021
Reading for the responses before and the renewed README on AngularFire messaging you can see it IS compatible and works flawlessly with the Angular service worker. You just need to configure it to use it.
I cant comment on having two service workers besides each other, but plainly for messaging and e.g. offline support, there is no need to have two.
The AngularFire team may do themselves a favour and posting a blog on blog.angular.io saying how cool it all works with the Angular service worker
rewtelize commentedon Mar 5, 2021
First of all, thanks for your answer @Tommertom :)
But I'm working with Azure Notification Hub, and in order to create or update an installation/register based on any device, I need to send its device's token as a handle. Using AngularFireMessaging was easy because I could just call requestToken() and I got it. On the other hand, using Push API I got a PushSubscription object, which contains an endpoint, a pair of keys and an expirationTime.
Is there a way to register a device using a PushSubscription object?
Cironic commentedon Mar 12, 2021
I tried building a porject like the one in the article that you posted. I struggle at the following point:
if (!firebase.apps.length) { firebase.initializeApp(environment.firebase); navigator.serviceWorker.getRegistration().then(swr=> firebase.messaging().useServiceWorker(swr)); }I saw you edited the constructor at the point quite a lot, but I can't figure out how to get it to work, even with your code snippets.
firebase.messaging().useServiceWorker(swr) in this line as swr is coming undefined inside getRegistration().then(swr).
if you could tell me how to fix the problem I would be really glad...
gkalpak commentedon Mar 12, 2021
@Cironic, this might happen because the SW might not have been registered yet (it depends on the registrationStrategy). You could listener to
controllerchangeevents before retrieving the SW registration; something like:Cironic commentedon Mar 15, 2021
@gkalpak, I hope you can help me, since I don't really get how to use your code in the example of the medium article.
Since the problem occurs in the constructor. EDIT: it worked all fine with @angular-devkit/build-angular": "~0.803.12"
And maybe you can answer me another question:
for Firebase messaging implementation is it correct to register the ngsw-worker as Serviceworker and not the firebase-messaging-sw?
And I guess here I could use another registrationStrategy so I don't have to use your code?
Sorry for all the questions, but you are my best bet right now to keep progressing on my project.
gkalpak commentedon Mar 16, 2021
I'not familiar with Firebase messaging tbh, but that is my understanding from a quick look at the article and the Firebase docs.
I don't think any registration strategy would make it safe to not use my code 馃槢
The SW registration is always an async operation.
gkalpak commentedon Apr 7, 2021
AFAICT, the latest version of AnguarFireMessaging (AFM) is compatible with the Angular ServiceWorker (NGSW). The AngularFire team is working on documenting how to configure AFM to work with NGSW. For more details see angular/angularfire#1923 (reply in thread).
Based on that, I am going to close this issue. If there is anything else that needs to be fixed in the NGSW, please open a new issue.
angular-automatic-lock-bot commentedon May 8, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.