UNPKG

2.74 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 */
17
18import {
19 Observer,
20 Unsubscribe,
21 NextFn,
22 ErrorFn,
23 CompleteFn
24} from '@firebase/util';
25
26// Currently supported fcm notification display parameters. Note that
27// {@link https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/notifications/NotificationOptions}
28// defines a full list of display notification parameters. This interface we only include what the
29// SEND API support for clarity.
30export interface NotificationPayload {
31 title?: string;
32 body?: string;
33 image?: string;
34}
35
36export interface FcmOptions {
37 link?: string;
38 analyticsLabel?: string;
39}
40
41export interface MessagePayload {
42 notification?: NotificationPayload;
43 data?: { [key: string]: string };
44 fcmOptions?: FcmOptions;
45 from: string;
46 collapseKey: string;
47 messageId: string;
48}
49
50export interface FirebaseMessaging {
51 /** window controller */
52 deleteToken(): Promise<boolean>;
53 getToken(options?: {
54 vapidKey?: string;
55 serviceWorkerRegistration?: ServiceWorkerRegistration;
56 }): Promise<string>;
57 onMessage(
58 nextOrObserver: NextFn<any> | Observer<any>,
59 error?: ErrorFn,
60 completed?: CompleteFn
61 ): Unsubscribe;
62
63 /** service worker controller */
64 onBackgroundMessage(
65 nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>,
66 error?: ErrorFn,
67 completed?: CompleteFn
68 ): Unsubscribe;
69
70 /** @deprecated */
71 deleteToken(token: string): Promise<boolean>;
72 onTokenRefresh(
73 nextOrObserver: NextFn<any> | Observer<any>,
74 error?: ErrorFn,
75 completed?: CompleteFn
76 ): Unsubscribe;
77 /**
78 * @deprecated Use Notification.requestPermission() instead.
79 * https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission
80 */
81 requestPermission(): Promise<void>;
82 setBackgroundMessageHandler(
83 callback: (payload: any) => Promise<any> | void
84 ): void;
85 useServiceWorker(registration: ServiceWorkerRegistration): void;
86 usePublicVapidKey(b64PublicKey: string): void;
87}
88
89export type FirebaseMessagingName = 'messaging-compat';
90
91declare module '@firebase/component' {
92 interface NameServiceMapping {
93 'messaging-compat': FirebaseMessaging;
94 }
95}