Functions
| Function | Description |
|---|---|
| function(app, ...) | |
| getMessaging(app) | Retrieves a Firebase Cloud Messaging instance. |
| function(messaging, ...) | |
| experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) | Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime. |
| onBackgroundMessage(messaging, nextOrObserver) | Called when a message is received while the app is in the background. An app is considered to be in the background if no active window is displayed. |
| onRegistered(messaging, nextOrObserver) | Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID). Use the FID passed to the callback to upload it to your application server. When you receive an FID after calling register(), instruct your backend to remove any legacy token for this instance. |
| onUnregistered(messaging, nextOrObserver) | Subscribes to an event that the app instance is unregistered from FCM (FID no longer active). Use this to notify your backend to remove this FID to prevent 404 errors on send. |
| function() | |
| isSupported() | Checks whether all required APIs exist within SW Context |
Interfaces
| Interface | Description |
|---|---|
| FcmOptions | Options for features provided by the FCM SDK for Web. See WebpushFcmOptions. |
| GetTokenOptions | Options for getToken(). |
| MessagePayload | Message payload that contains the notification payload that is represented with NotificationPayload and the data payload that contains an arbitrary number of key-value pairs sent by developers through the Send API. |
| Messaging | Public interface of the Firebase Cloud Messaging SDK. |
| NotificationPayload | Display notification details. Details are sent through the Send API. |
| RegisterOptions | Options for register(). Same shape as GetTokenOptions for SW and VAPID configuration. |
function(app, ...)
getMessaging(app)
Retrieves a Firebase Cloud Messaging instance.
Signature:
export declare function getMessagingInSw(app?: FirebaseApp): Messaging;
Parameters
| Parameter | Type | Description |
|---|---|---|
| app | FirebaseApp |
Returns:
The Firebase Cloud Messaging instance associated with the provided firebase app.
function(messaging, ...)
experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable)
Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime.
Signature:
export declare function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging: Messaging, enable: boolean): void;
Parameters
| Parameter | Type | Description |
|---|---|---|
| messaging | Messaging | The FirebaseMessaging instance. |
| enable | boolean | Whether Firebase Cloud Messaging should export message delivery metrics to BigQuery. |
Returns:
void
onBackgroundMessage(messaging, nextOrObserver)
Called when a message is received while the app is in the background. An app is considered to be in the background if no active window is displayed.
Signature:
export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
Parameters
| Parameter | Type | Description |
|---|---|---|
| messaging | Messaging | The Messaging instance. |
| nextOrObserver | NextFn<MessagePayload> | Observer<MessagePayload> | This function, or observer object with next defined, is called when a message is received and the app is currently in the background. |
Returns:
To stop listening for messages execute this returned function.
onRegistered(messaging, nextOrObserver)
Subscribes to an event that the app instance is registered with FCM via Firebase Installation ID (FID). Use the FID passed to the callback to upload it to your application server. When you receive an FID after calling register(), instruct your backend to remove any legacy token for this instance.
Signature:
export declare function onRegistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
Parameters
| Parameter | Type | Description |
|---|---|---|
| messaging | Messaging | The Messaging instance. |
| nextOrObserver | NextFn<string> | Observer<string> | A function or observer object called when an FID is registered. |
Returns:
Unsubscribe function to stop listening.
onUnregistered(messaging, nextOrObserver)
Subscribes to an event that the app instance is unregistered from FCM (FID no longer active). Use this to notify your backend to remove this FID to prevent 404 errors on send.
Signature:
export declare function onUnregistered(messaging: Messaging, nextOrObserver: NextFn<string> | Observer<string>): Unsubscribe;
Parameters
| Parameter | Type | Description |
|---|---|---|
| messaging | Messaging | The Messaging instance. |
| nextOrObserver | NextFn<string> | Observer<string> | A function or observer object called with the unregistered FID. |
Returns:
Unsubscribe function to stop listening.
function()
isSupported()
Checks whether all required APIs exist within SW Context
Signature:
export declare function isSwSupported(): Promise<boolean>;
Returns:
Promise<boolean>
a Promise that resolves to a boolean.