UNPKG

4.36 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17import { FirebaseApp } from '@firebase/app';
18import { GetTokenOptions, MessagePayload, Messaging } from './interfaces/public-types';
19import { NextFn, Observer, Unsubscribe } from '@firebase/util';
20/**
21 * Retrieves a Firebase Cloud Messaging instance.
22 *
23 * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
24 *
25 * @public
26 */
27export declare function getMessagingInWindow(app?: FirebaseApp): Messaging;
28/**
29 * Retrieves a Firebase Cloud Messaging instance.
30 *
31 * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
32 *
33 * @public
34 */
35export declare function getMessagingInSw(app?: FirebaseApp): Messaging;
36/**
37 * Subscribes the {@link Messaging} instance to push notifications. Returns an Firebase Cloud
38 * Messaging registration token that can be used to send push messages to that {@link Messaging}
39 * instance.
40 *
41 * If a notification permission isn't already granted, this method asks the user for permission. The
42 * returned promise rejects if the user does not allow the app to show notifications.
43 *
44 * @param messaging - The {@link Messaging} instance.
45 * @param options - Provides an optional vapid key and an optinoal service worker registration
46 *
47 * @returns The promise resolves with an FCM registration token.
48 *
49 * @public
50 */
51export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
52/**
53 * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
54 * the {@link Messaging} instance from the push subscription.
55 *
56 * @param messaging - The {@link Messaging} instance.
57 *
58 * @returns The promise resolves when the token has been successfully deleted.
59 *
60 * @public
61 */
62export declare function deleteToken(messaging: Messaging): Promise<boolean>;
63/**
64 * When a push message is received and the user is currently on a page for your origin, the
65 * message is passed to the page and an `onMessage()` event is dispatched with the payload of
66 * the push message.
67 *
68 *
69 * @param messaging - The {@link Messaging} instance.
70 * @param nextOrObserver - This function, or observer object with `next` defined,
71 * is called when a message is received and the user is currently viewing your page.
72 * @returns To stop listening for messages execute this returned function.
73 *
74 * @public
75 */
76export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
77/**
78 * Called when a message is received while the app is in the background. An app is considered to be
79 * in the background if no active window is displayed.
80 *
81 * @param messaging - The {@link Messaging} instance.
82 * @param nextOrObserver - This function, or observer object with `next` defined, is called when a
83 * message is received and the app is currently in the background.
84 *
85 * @returns To stop listening for messages execute this returned function
86 *
87 * @public
88 */
89export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
90/**
91 * Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By
92 * default, message delivery metrics are not exported to BigQuery. Use this method to enable or
93 * disable the export at runtime.
94 *
95 * @param messaging - The `FirebaseMessaging` instance.
96 * @param enable - Whether Firebase Cloud Messaging should export message delivery metrics to
97 * BigQuery.
98 *
99 * @public
100 */
101export declare function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging: Messaging, enable: boolean): void;