SHARE
TWEET

Untitled

a guest Sep 17th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     _config['worker_link'] = '{$config.webroot}{$config.dashboard_worker}?v={$config.worker_version}';
  3.  
  4.     {literal}
  5.     _config['firebase_config'] = {
  6.         {/literal}
  7.         apiKey: "{$config.dashboard_push_api_key}",
  8.         authDomain: "{$config.fb_project[$config.dashboard_push_sender_id]}.firebaseapp.com",
  9.         databaseURL: "https://{$config.fb_project[$config.dashboard_push_sender_id]}.firebaseio.com",
  10.         storageBucket: "{$config.fb_project[$config.dashboard_push_sender_id]}.appspot.com",
  11.         messagingSenderId: "{$config.dashboard_push_sender_id}"
  12.         {literal}
  13.     };
  14.     {/literal}
  15. </script>
  16.  
  17. <script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
  18.  
  19. <script type="text/javascript">
  20.     /* global _config */
  21.  
  22.     {literal}
  23.     firebase.initializeApp(_config['firebase_config']);
  24.  
  25.     // Retrieve Firebase Messaging object.
  26.     const messaging = firebase.messaging();
  27.  
  28.     // Callback fired if Instance ID token is updated.
  29.     messaging.onTokenRefresh(function () {
  30.         messaging.getToken().then(function (refreshed_token) {
  31.             console.log('[Firepush] token refreshed.');
  32.  
  33.             // Indicate that the new Instance ID token has not yet been sent to the app server.
  34.             set_token_sent_to_server(false);
  35.  
  36.             // Send Instance ID token to app server.
  37.             send_token_to_server(refreshed_token);
  38.  
  39.         }).catch(function (err) {
  40.             console.log('[Firepush] unable to retrieve refreshed token ', err);
  41.         });
  42.     });
  43.  
  44.     if ('serviceWorker' in navigator) {
  45.         navigator.serviceWorker.register(_config['worker_link']).then(function (registration) {
  46.             messaging.useServiceWorker(registration);
  47.             console.log('[Firepush] ServiceWorker registration successful with scope: ', registration.scope);
  48.         }).catch(function (err) {
  49.             console.log('[Firepush] ServiceWorker registration failed: ', err);
  50.         });
  51.     }
  52.     {/literal}
  53. </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