@firebase/messaging
- Version 0.12.17
- Published
- 772 kB
- 6 dependencies
- Apache-2.0 license
Install
npm i @firebase/messaging
yarn add @firebase/messaging
pnpm add @firebase/messaging
Overview
The Firebase Cloud Messaging Web SDK. This SDK does not work in a Node.js environment.
Index
Functions
function deleteToken
deleteToken: (messaging: Messaging) => Promise<boolean>;
function getMessaging
getMessaging: (app?: FirebaseApp) => Messaging;
Retrieves a Firebase Cloud Messaging instance.
Returns
The Firebase Cloud Messaging instance associated with the provided firebase app.
Modifiers
@public
function getToken
getToken: (messaging: Messaging, options?: GetTokenOptions) => Promise<string>;
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.
Parameter messaging
The Messaging instance.
Parameter options
Provides an optional vapid key and an optional service worker registration.
Returns
The promise resolves with an FCM registration token.
Modifiers
@public
function isSupported
isSupported: () => Promise<boolean>;
Checks if all required APIs exist in the browser.
Returns
a Promise that resolves to a boolean.
Modifiers
@public
function onMessage
onMessage: ( messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>) => Unsubscribe;
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.Parameter messaging
The Messaging instance.
Parameter nextOrObserver
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.
Modifiers
@public
Interfaces
interface FcmOptions
interface FcmOptions {}
Options for features provided by the FCM SDK for Web. See WebpushFcmOptions.
Modifiers
@public
property analyticsLabel
analyticsLabel?: string;
The label associated with the message's analytics data.
property link
link?: string;
The link to open when the user clicks on the notification.
interface GetTokenOptions
interface GetTokenOptions {}
Options for getToken.
Modifiers
@public
property serviceWorkerRegistration
serviceWorkerRegistration?: ServiceWorkerRegistration;
The service worker registration for receiving push messaging. If the registration is not provided explicitly, you need to have a
firebase-messaging-sw.js
at your root location. See Access the registration token for more details.
property vapidKey
vapidKey?: string;
The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with Configure Web Credentials with FCM. See The Web Push Protocol for details on web push services.
interface MessagePayload
interface 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.
Modifiers
@public
property collapseKey
collapseKey: string;
The collapse key of the message. See Non-collapsible and collapsible messages
property data
data?: { [key: string]: string;};
Arbitrary key/value payload.
property fcmOptions
fcmOptions?: FcmOptions;
See documentation for FcmOptions.
property from
from: string;
The sender of this message.
property messageId
messageId: string;
The message ID of a message.
property notification
notification?: NotificationPayload;
See documentation for NotificationPayload.
interface Messaging
interface Messaging {}
Public interface of the Firebase Cloud Messaging SDK.
Modifiers
@public
property app
app: FirebaseApp;
The @firebase/app#FirebaseApp this
Messaging
instance is associated with.
interface NotificationPayload
interface NotificationPayload {}
Display notification details. Details are sent through the Send API.
Modifiers
@public
property body
body?: string;
The notification's body text.
property icon
icon?: string;
The URL to use for the notification's icon. If you don't send this key in the request, FCM displays the launcher icon specified in your app manifest.
property image
image?: string;
The URL of an image that is downloaded on the device and displayed in the notification.
property title
title?: string;
The notification's title.
Package Files (1)
Dependencies (6)
Dev Dependencies (6)
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@firebase/messaging
.
- Markdown[](https://www.jsdocs.io/package/@firebase/messaging)
- HTML<a href="https://www.jsdocs.io/package/@firebase/messaging"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3737 ms. - Missing or incorrect documentation? Open an issue for this package.