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.

private.d.ts 6.9KB

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