SHARE
TWEET

Untitled

a guest Sep 17th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
  2.  
  3. <script type="text/javascript">
  4.     /* global _config */
  5.  
  6.     {literal}
  7.     firebase.initializeApp(_config['firebase_config']);
  8.  
  9.     // Retrieve Firebase Messaging object.
  10.     const messaging = firebase.messaging();
  11.  
  12.     // Callback fired if Instance ID token is updated.
  13.     messaging.onTokenRefresh(function () {
  14.         messaging.getToken().then(function (refreshed_token) {
  15.             console.log('[Firepush] token refreshed.');
  16.  
  17.             // Indicate that the new Instance ID token has not yet been sent to the app server.
  18.             set_token_sent_to_server(false);
  19.  
  20.             // Send Instance ID token to app server.
  21.             send_token_to_server(refreshed_token);
  22.  
  23.         }).catch(function (err) {
  24.             console.log('[Firepush] unable to retrieve refreshed token ', err);
  25.         });
  26.     });
  27.  
  28.     if ('serviceWorker' in navigator) {
  29.         navigator.serviceWorker.register(_config['worker_link']).then(function (registration) {
  30.             messaging.useServiceWorker(registration);
  31.             console.log('[Firepush] ServiceWorker registration successful with scope: ', registration.scope);
  32.         }).catch(function (err) {
  33.             console.log('[Firepush] ServiceWorker registration failed: ', err);
  34.         });
  35.     }
  36.     {/literal}
  37. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top