1var config = { 2 apiKey: "AIzaSyDUCg71JjIB41Y6Vcl7jsWLRtLFq2a68nA", 3 authDomain: "mbarendezvous-174205.firebaseapp.com", 4 databaseURL: "https://mbarendezvous-174205.firebaseio.com", 5 projectId: "mbarendezvous-174205", 6 storageBucket: "mbarendezvous-174205.appspot.com", 7 messagingSenderId: "22163932727" 8}; 9firebase.initializeApp(config); 10const messaging = firebase.messaging(); 11messaging.requestPermission().then(function () { 12 console.log('Notification permission granted.'); 13 return messaging.getToken(); 14}) 15 .then(function (token) { 16 if (token) { 17 sendTokenToServer(token); 18 } else { 19 console.log('No Instance ID token available. Request permission to generate one.'); 20 setTokenSentToServer(false); 21 } 22 }) 23 .catch(function (err) { 24 console.log('Unable to get permission to notify.', err); 25 }); 26 27messaging.onMessage(function (payload) { 28 title = payload.data.title; 29 options = { 30 body: payload.data.body, 31 icon: payload.data.icon 32 }; 33 var notificaton = new Notification(title, options); 34}); 35 36function sendTokenToServer(currentToken) { 37 if (!isTokenSentToServer()) { 38 console.log('Sending token to server...'); 39 sendTokenDb(currentToken); 40 // TODO(developer): Send the current token to your server. 41 42 console.log(currentToken); 43 setTokenSentToServer(true); 44 } else { 45 console.log(currentToken); 46 console.log('Token already sent to server so won\'t send it again ' + 47 'unless it changes'); 48 } 49} 50function isTokenSentToServer() { 51 return window.localStorage.getItem('sentToServer') === '1'; 52} 53 54function setTokenSentToServer(sent) { 55 window.localStorage.setItem('sentToServer', sent ? '1' : '0'); 56} 57messaging.onTokenRefresh(function () { 58 messaging.getToken().then(function (refreshedToken) { 59 console.log('Token refreshed.'); 60 // Indicate that the new Instance ID token has not yet been sent to the 61 // app server.
62 setTokenSentToServer(false); 63 // Send Instance ID token to app server. 64 sendTokenToServer(refreshedToken); 65 // [START_EXCLUDE] 66 // Display new Instance ID token and clear UI of all previous messages. 67 // [END_EXCLUDE] 68 }).catch(function (err) { 69 console.log('Unable to retrieve refreshed token ', err); 70 }); 71}); 72 73function sendTokenDb(token) { 74 $.ajax({ 75 type: 'POST', 76 url: '/sendpushtoken', 77 data: {'token': token}, 78 success: function (data) { 79 console.log(data); 80 }, 81 error: function (data) { 82 console.log('Error:', data); 83 }, 84 async: false 85 }); 86}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.