====== adv.startPushNotifications() ======
[[ixnx:wrtc:js:push_notifications|GCM push notifications]] are deprecated. wrtc_kit does not support push notifications at the moment.
wrtc.adv.startPushNotifications() starts [[ixnx:wrtc:js:push_notifications|GCM push notifications]] that allow user to receive phone calls even when browser is not open.
GCM push notifications is a Google specific push notification only available for the Chrome web server. Attempting to call wrtc.adv.startPushNotifications() on other web servers will fail silently.
First time wrtc.adv.startPushNotifications() is called the web browser will pop up a question box asking user to allow notifications:
{{:ixnx:wrtc:js:notifications_ask.png?nolink|}}
The user's allow/block selection will then be remembered, all future wrtc.adv.startPushNotifications() calls will be allowed/blocked by the browser itself without ever asking user again.
Therefore it is important to explain to user she needs to allow notifications before calling wrtc.adv.startPushNotifications() the first time. If user once blocked notifications it is difficult to enable them again.
===== Arguments =====
wrtc.adv.startPushNotifications(apiKey, senderId)
* apiKey - (optional) string containing Firebase Legacy server key
* senderId - (optional) string containing Firebase Sender ID
If arguments are omitted wrtc.adv.startPushNotifications() will use wrtc_kit's default test account with: \\
apiKey "AIzaSyDOK4MLYAlxidyHq2e5Pir9slk8KN5BySo" \\
senderId "279685133220"
[[ixnx:wrtc:js:push_notifications|If you have created your own cloud messaging account]] you need to supply its API key and Sender ID as arguments.
wrtc.adv.startPushNotifications("stop") stops push notifications again.
===== Returns =====
Nothing.
===== Usage =====
You usually store [[ixnx:wrtc:js:api:wrtc:adv.clientid|client ID]] in cookie after you have called wrtc.adv.startPushNotifications().
You should then [[ixnx:wrtc:js:push_notifications|attempt to restart push notifications]] in [[ixnx:wrtc:js:api:wrtc:onloggedin|wrtc.onLoggedIn()]] to detect if user has blocked notifications or not.
===== Events =====
[[ixnx:wrtc:js:api:wrtc:onnotifications|wrtc.onNotifications(true)]] will occur if web push notifications has been started successfully. (User or browser allowed notifications.)
[[ixnx:wrtc:js:api:wrtc:onnotifications|wrtc.onNotifications(false)]] will occur if user or browser has blocked notifications.
[[ixnx:wrtc:js:api:wrtc:onerror|wrtc.onError(null, {errorCode:621, errorMsg:": "})]] will occur if service worker or push notification could not be started correctly.
===== Example =====
wrtc.adv.startPushNotifications("AIzaSyDOK4MLYAlxidyHq2e5Pir9slk8KN5BySo", "279685133220");
===== Advanced =====
wrtc.adv.startPushNotifications() starts a service worker to be able to receive notifications even while browser is closed. The path to the service worker file [[ixnx:wrtc:js:push_notifications#sw.js|sw.js]] is stored in wrtc.i.swPath - if you are using your own webserver you need to store [[ixnx:wrtc:js:push_notifications#sw.js|sw.js]] (and [[ixnx:wrtc:js:push_notifications#manifest.json|manifest.json]]) on your own server, and set wrtc.i.swPath in [[ixnx:wrtc:js:api:wrtc:init|wrtc.init()]].
===== Also See =====
[[ixnx:wrtc:js:push_notifications|Push Notifications]]
[[ixnx:wrtc:js:api:wrtc:onnotifications|wrtc.onNotifications()]]