No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index-public.d.ts 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * Firebase Cloud Messaging
  3. *
  4. * @packageDocumentation
  5. */
  6. import { FirebaseApp } from '@firebase/app';
  7. import { NextFn , Observer , Unsubscribe } from '@firebase/util';
  8. /**
  9. * Deletes the registration token associated with this {@link Messaging} instance and unsubscribes
  10. * the {@link Messaging} instance from the push subscription.
  11. *
  12. * @param messaging - The {@link Messaging} instance.
  13. *
  14. * @returns The promise resolves when the token has been successfully deleted.
  15. *
  16. * @public
  17. */
  18. export declare function deleteToken(messaging: Messaging): Promise<boolean>;
  19. /**
  20. * Options for features provided by the FCM SDK for Web. See {@link
  21. * https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushfcmoptions |
  22. * WebpushFcmOptions}
  23. *
  24. * @public
  25. */
  26. export declare interface FcmOptions {
  27. /**
  28. * The link to open when the user clicks on the notification.
  29. */
  30. link?: string;
  31. /**
  32. * The label associated with the message's analytics data.
  33. */
  34. analyticsLabel?: string;
  35. }
  36. /* Excluded from this release type: _FirebaseMessagingName */
  37. /**
  38. * Retrieves a Firebase Cloud Messaging instance.
  39. *
  40. * @returns The Firebase Cloud Messaging instance associated with the provided firebase app.
  41. *
  42. * @public
  43. */
  44. export declare function getMessaging(app?: FirebaseApp): Messaging;
  45. /**
  46. * Subscribes the {@link Messaging} instance to push notifications. Returns an Firebase Cloud
  47. * Messaging registration token that can be used to send push messages to that {@link Messaging}
  48. * instance.
  49. *
  50. * If a notification permission isn't already granted, this method asks the user for permission. The
  51. * returned promise rejects if the user does not allow the app to show notifications.
  52. *
  53. * @param messaging - The {@link Messaging} instance.
  54. * @param options - Provides an optional vapid key and an optinoal service worker registration
  55. *
  56. * @returns The promise resolves with an FCM registration token.
  57. *
  58. * @public
  59. */
  60. export declare function getToken(messaging: Messaging, options?: GetTokenOptions): Promise<string>;
  61. /**
  62. * Options for {@link getToken}
  63. *
  64. * @public
  65. */
  66. export declare interface GetTokenOptions {
  67. /**
  68. * The public server key provided to push services. It is used to
  69. * authenticate the push subscribers to receive push messages only from sending servers that hold
  70. * the corresponding private key. If it is not provided, a default VAPID key is used. Note that some
  71. * push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended
  72. * to generate and import a VAPID key for your project with
  73. * {@link https://firebase.google.com/docs/cloud-messaging/js/client#configure_web_credentials_with_fcm | Configure Web Credentials with FCM}.
  74. * See
  75. * {@link https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol | The Web Push Protocol}
  76. * for details on web push services.
  77. */
  78. vapidKey?: string;
  79. /**
  80. * The service worker registration for receiving push
  81. * messaging. If the registration is not provided explicitly, you need to have a
  82. * `firebase-messaging-sw.js` at your root location. See
  83. * {@link https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token | Retrieve the current registration token}
  84. * for more details.
  85. */
  86. serviceWorkerRegistration?: ServiceWorkerRegistration;
  87. }
  88. /**
  89. * @license
  90. * Copyright 2020 Google LLC
  91. *
  92. * Licensed under the Apache License, Version 2.0 (the "License");
  93. * you may not use this file except in compliance with the License.
  94. * You may obtain a copy of the License at
  95. *
  96. * http://www.apache.org/licenses/LICENSE-2.0
  97. *
  98. * Unless required by applicable law or agreed to in writing, software
  99. * distributed under the License is distributed on an "AS IS" BASIS,
  100. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  101. * See the License for the specific language governing permissions and
  102. * limitations under the License.
  103. */
  104. /**
  105. * Checks if all required APIs exist in the browser.
  106. * @returns a Promise that resolves to a boolean.
  107. *
  108. * @public
  109. */
  110. export declare function isSupported(): Promise<boolean>;
  111. /**
  112. * Message payload that contains the notification payload that is represented with
  113. * {@link NotificationPayload} and the data payload that contains an arbitrary
  114. * number of key-value pairs sent by developers through the
  115. * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification | Send API}
  116. *
  117. * @public
  118. */
  119. export declare interface MessagePayload {
  120. /**
  121. * {@inheritdoc NotificationPayload}
  122. */
  123. notification?: NotificationPayload;
  124. /**
  125. * Arbitrary key/value payload.
  126. */
  127. data?: {
  128. [key: string]: string;
  129. };
  130. /**
  131. * {@inheritdoc FcmOptions}
  132. */
  133. fcmOptions?: FcmOptions;
  134. /**
  135. * The sender of this message.
  136. */
  137. from: string;
  138. /**
  139. * The collapse key of the message. See
  140. * {@link https://firebase.google.com/docs/cloud-messaging/concept-options#collapsible_and_non-collapsible_messages | Non-collapsible and collapsible messages}
  141. */
  142. collapseKey: string;
  143. /**
  144. * The message id of a message.
  145. */
  146. messageId: string;
  147. }
  148. /**
  149. * Public interface of the Firebase Cloud Messaging SDK.
  150. *
  151. * @public
  152. */
  153. export declare interface Messaging {
  154. /**
  155. * The {@link @firebase/app#FirebaseApp} this `Messaging` instance is associated with.
  156. */
  157. app: FirebaseApp;
  158. }
  159. export { NextFn };
  160. /**
  161. * Display notification details. They are sent through the
  162. * {@link https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification | Send API}
  163. *
  164. * @public
  165. */
  166. export declare interface NotificationPayload {
  167. /**
  168. * The notification's title.
  169. */
  170. title?: string;
  171. /**
  172. * The notification's body text.
  173. */
  174. body?: string;
  175. /**
  176. * The URL of an image that is downloaded on the device and displayed in the notification.
  177. */
  178. image?: string;
  179. /**
  180. * The URL to use for the notification's icon. If you don't send this key in the request,
  181. * FCM displays the launcher icon specified in your app manifest.
  182. */
  183. icon?: string;
  184. }
  185. export { Observer };
  186. /**
  187. * When a push message is received and the user is currently on a page for your origin, the
  188. * message is passed to the page and an `onMessage()` event is dispatched with the payload of
  189. * the push message.
  190. *
  191. *
  192. * @param messaging - The {@link Messaging} instance.
  193. * @param nextOrObserver - This function, or observer object with `next` defined,
  194. * is called when a message is received and the user is currently viewing your page.
  195. * @returns To stop listening for messages execute this returned function.
  196. *
  197. * @public
  198. */
  199. export declare function onMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
  200. export { Unsubscribe };
  201. export {};