@firebase/messaging

  • Version 0.9.1
  • Published
  • 724 kB
  • 6 dependencies
  • Apache-2.0 license

Install

npm i @firebase/messaging
yarn add @firebase/messaging
pnpm add @firebase/messaging

Overview

Firebase Cloud Messaging

Index

Functions

function deleteToken

deleteToken: (messaging: Messaging) => Promise<boolean>;
  • Deletes the registration token associated with this Messaging instance and unsubscribes the Messaging instance from the push subscription.

    Parameter messaging

    The Messaging instance.

    Returns

    The promise resolves when the token has been successfully deleted.

    Modifiers

    • @public

function getMessaging

getMessaging: (app?: any) => 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 an Firebase Cloud Messaging registration token that can be used to send push messages to that Messaging instance.

    If a 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 optinoal 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>
) => any;
  • 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.

link?: string;
  • The link to open when the user clicks on the notification.

interface GetTokenOptions

interface GetTokenOptions {}

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 Retrieve the current registration token for more details.

property vapidKey

vapidKey?: string;
  • The public server key provided to push services. It is used to authenticate the 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;

property data

data?: {
[key: string]: string;
};
  • Arbitrary key/value payload.

property fcmOptions

fcmOptions?: FcmOptions;

property from

from: string;
  • The sender of this message.

property messageId

messageId: string;
  • The message id of a message.

property notification

notification?: NotificationPayload;

interface Messaging

interface Messaging {}
  • Public interface of the Firebase Cloud Messaging SDK.

    Modifiers

    • @public

property app

app: FirebaseApp;

interface NotificationPayload

interface NotificationPayload {}
  • Display notification details. They are sent through the Send API

    Modifiers

    • @public

property body

body?: string;
  • The notification's body text.

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 onejsDocs.io badgeto 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
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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>