forked from firebase/firebase-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firebase-messaging-externs.js
165 lines (154 loc) · 5.66 KB
/
firebase-messaging-externs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* @license Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Firebase Messaging API.
* @externs
*/
/**
* Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
* default app or a given app.
*
* `firebase.messaging()` can be called with no arguments to access the default
* app's {@link firebase.messaging.Messaging `Messaging`} service or as
* `firebase.messaging(app)` to access the
* {@link firebase.messaging.Messaging `Messaging`} service associated with a
* specific app.
*
* Calling `firebase.messaging()` in a service worker results in Firebase
* generating notifications if the push message payload has a `notification`
* parameter.
*
* @example
* // Get the Messaging service for the default app
* var defaultMessaging = firebase.messaging();
*
* @example
* // Get the Messaging service for a given app
* var otherMessaging = firebase.messaging(otherApp);
*
* @namespace
* @param {!firebase.app.App=} app The app to create a Messaging service for.
* If not passed, uses the default app.
*
* @return {!firebase.messaging.Messaging}
*/
firebase.messaging = function(app) {};
/**
* Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
* current app.
*
* @example
* var messaging = app.messaging();
* // The above is shorthand for:
* // var messaging = firebase.messaging(app);
*
* @return {!firebase.messaging.Messaging}
*/
firebase.app.App.prototype.messaging = function() {};
/**
* The Firebase Messaging service interface.
*
* Do not call this constructor directly. Instead, use
* {@link firebase.messaging `firebase.messaging()`}.
*
* See
* {@link
* https://firebase.google.com/docs/cloud-messaging/js/client
* Set Up a JavaScript Firebase Cloud Messaging Client App}
* for a full guide on how to use the Firebase Messaging service.
*
* @interface
*/
firebase.messaging.Messaging = function() {};
/**
* Notification permissions are required to send a user push messages.
* Calling this method displays the permission dialog to the user and
* resolves if the permission is granted.
*
* @return {firebase.Promise} The promise resolves if permission is
* granted. Otherwise, the promise is rejected with an error.
*/
firebase.messaging.Messaging.prototype.requestPermission = function() {};
/**
* After calling `requestPermission()` you can call this method to get an FCM
* registration token that can be used to send push messages to this user.
*
* @return {firebase.Promise<string>} The promise resolves if an FCM token can
* be retrieved. This method returns null if the current origin does not have
* permission to show notifications.
*/
firebase.messaging.Messaging.prototype.getToken = function() {};
/**
* You should listen for token refreshes so your web app knows when FCM
* has invalidated your existing token and you need to call `getToken()`
* to get a new token.
*
* @param {!firebase.Observer<Object, void>|!function(!Object)}
* nextOrObserver This function, or observer object with `next` defined,
* is called when a token refresh has occurred.
* @return {firebase.Unsubscribe} To stop listening for token
* refresh events execute this returned function.
*/
firebase.messaging.Messaging.prototype.onTokenRefresh = function(
nextOrObserver
) {};
/**
* 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.
*
* NOTE: These events are dispatched when you have called
* `setBackgroundMessageHandler()` in your service worker.
*
* @param {!firebase.Observer<Object, void>|!function(!Object)}
* nextOrObserver This function, or observer object with `next` defined,
* is called when a message is received and the user is currently viewing your page.
* @return {firebase.Unsubscribe} To stop listening for messages
* execute this returned function.
*/
firebase.messaging.Messaging.prototype.onMessage = function(nextOrObserver) {};
/**
* To forceably stop a registration token from being used, delete it
* by calling this method.
*
* @param {!string} token The token to delete.
* @return {firebase.Promise} The promise resolves when the token has been
* successfully deleted.
*/
firebase.messaging.Messaging.prototype.deleteToken = function(token) {};
/**
* To use your own service worker for receiving push messages, you
* can pass in your service worker registration in this method.
*
* @param {!ServiceWorkerRegistration} registration The service worker
* registration you wish to use for push messaging.
*/
firebase.messaging.Messaging.prototype.useServiceWorker = function(
registration
) {};
/**
* FCM directs push messages to your web page's `onMessage()` callback
* if the user currently has it open. Otherwise, it calls
* your callback passed into `setBackgroundMessageHandler()`.
*
* Your callback should return a promise that, once resolved, has
* shown a notification.
*
* @param {!function(!Object)} callback The function to handle the push message.
*/
firebase.messaging.Messaging.prototype.setBackgroundMessageHandler = function(
callback
) {};