| Current Path : /home/users/unlimited/www/dealnest.codeskitter.site/public/assets/js/custom/ |
| Current File : /home/users/unlimited/www/dealnest.codeskitter.site/public/assets/js/custom/firebase_config.js |
const firebaseConfig = {
apiKey: apiKey.value,
authDomain: authDomain.value,
projectId: projectId.value,
storageBucket: storageBucket.value,
messagingSenderId: messagingSenderId.value,
appId: appId.value,
measurementId: measurementId.value
};
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function () {
getRegToken();
})
.catch(function (err) {
console.log('Unable to get permission to notify.', err);
Swal.fire({
title: 'Allow Notification Permission!',
icon: 'error',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false
})
});
function getRegToken(argument) {
messaging.getToken()
.then(function (currentToken) {
saveToken(currentToken);
})
.catch(function (err) {
console.log('An error occurred while retrieving token. ', err);
});
}
function saveToken(currentToken) {
$.ajax({
url: "updateFCMID",
method: 'get',
data: {
token: currentToken,
id: 1
}
}).done(function (result) {
});
}
messaging.onMessage(function (payload) {
notificationTitle = payload.data.title;
notificationOptions = {
body: payload.data.body,
icon: payload.data.icon,
// image: payload.data.image,
data: {
time: new Date(Date.now()).toString(),
}
};
var notification = new Notification(notificationTitle, notificationOptions);
});