Firebase - Firebase Cloud Message(FCM) Research Log
This article is focus on web version
You can easy to use web notification push notification to your web site.
Different with use pure web notification
- Browser support
- FCM - Chrome(desktop & Android) & Firefox(desktop & Android)
- pure notification api - Chrome(desktop & Android) & Firefox(desktop & Android) & Opera(desktop) & Safari(desktop)
- Android need service worker
- Service Worker
- FCM - require
- pure notification api - option
pure web notification only a notification object, you need handle connection push message from server.
But FCM had handle this connect.
Different whith use Service Worker or not use Service Worker
|use Service Worker||no use Service Worker|
|service open on browser tab and focus||receive||receive|
|service open on browser tab and not focus||receive||receive|
|service open not on browser tab||receive||can't receive|
- app server
- a server can send message
- web service need https for handle Service Worker
- set gcm send id
Use firebase console create a project(If you had project for your web service, you can skip this setp
Overview -> setting -> cloud messageand you can get
And then you can use the simple code from https://github.com/firebase/quickstart-js/tree/master/messaging
Web notification dosen't have
Instance ID so we only can use token
Build it to send message or do something like send topic message or personal message
You can bind user info & their token created from client web browser, then you can push personal message for user.
And it use api push notification like this
Authorization key is Firebase console server key
Multiple device push
It's base on sub / pub pattern, you can reference Publish/Subscribe pattern - MSDN - Microsoft
If you want to know any token push status and tracking which in this group, you can use group way
But you must handle group yourself
FCM web notification not support analytics
So you can add querystring on action url or add log on receive message on foreground
If user clear token on offline, need handle cleared token let app server and IID server know
Two way can handle this thing
- client initiative handle
If your web service provide unsubscribe function, you must handle this behavior.
And you need handle if user clear data from client, you need update token.
messaging.deleteToken() handle delete from IID server but delete token from app server need handle yourself.
- server side detect
When server push notification and response error make some error handle like delete
And you can log token active time, if long time not active, you can delete it from app server and also suggest delete it from IID server
On desktop device Chrome or Firefox not on process it can not receive message
But message will queued until Browser open
So don't worried about this thing
Notice don't send error target user
Notice don't send the push token that doesn't had any user or device
And then i find Firebase hosting seem doesn't support service worker, so it can't use FCM on Firebase hosting.