Functions
Function | Description |
---|---|
function(app, ...) | |
getMessaging(app) | Retrieves a Firebase Cloud Messaging instance. |
function(messaging, ...) | |
deleteToken(messaging) | Deletes the registration token associated with this Messaging instance and unsubscribes the Messaging instance from the push subscription. |
getToken(messaging, options) | Subscribes the Messaging instance to push notifications. Returns a Firebase Cloud Messaging registration token that can be used to send push messages to that Messaging instance.If notification permission isn't already granted, this method asks the user for permission. The returned promise rejects if the user does not allow the app to show notifications. |
onMessage(messaging, nextOrObserver) | When a push message is received and the user is currently on a page for your origin, the message is passed to the page and an onMessage() event is dispatched with the payload of the push message. |
function() | |
isSupported() | Checks if all required APIs exist in the browser. |
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. |
function(app, ...)
getMessaging(app)
Retrieves a Firebase Cloud Messaging instance.
Signature:
export declare function getMessagingInWindow(app?: FirebaseApp): Messaging;
Parameters
Parameter | Type | Description |
---|---|---|
app | FirebaseApp |
Returns:
The Firebase Cloud Messaging instance associated with the provided firebase app.
function(messaging, ...)
deleteToken(messaging)
Deletes the registration token associated with this Messaging instance and unsubscribes the Messaging instance from the push subscription.
Signature:
export declare function deleteToken(messaging: Messaging): Promise<boolean>;
Parameters
Parameter | Type | Description |
---|---|---|
messaging | Messaging | The Messaging instance. |
Returns:
Promise<boolean>
The promise resolves when the token has been successfully deleted.
getToken(messaging, options)
Subscribes the Messaging instance to push notifications. Returns a Firebase Cloud Messaging registration token that can be used to send push messages to that Messaging instance.
If notification permission isn't already granted, this method asks the user for permission. The returned promise rejects if the user does not allow the app to show notifications.
Signature:
export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
Parameters
Parameter | Type | Description |
---|---|---|
messaging | Messaging | The Messaging instance. |
options | GetTokenOptions | Provides an optional vapid key and an optional service worker registration. |
Returns:
Promise<string>
The promise resolves with an FCM registration token.
onMessage(messaging, nextOrObserver)
When a push message is received and the user is currently on a page for your origin, the message is passed to the page and an onMessage()
event is dispatched with the payload of the push message.
Signature:
export declare function onMessage(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 user is currently viewing your page. |
Returns:
To stop listening for messages execute this returned function.
function()
isSupported()
Checks if all required APIs exist in the browser.
Signature:
export declare function isWindowSupported(): Promise<boolean>;
Returns:
Promise<boolean>
a Promise that resolves to a boolean.