Minore Tweeks

This commit is contained in:
Václav Španinger 2020-08-10 16:58:20 +02:00
parent 2db6d47475
commit facb6f4420

View File

@ -5,6 +5,7 @@ import axios from "axios";
import firebase from "firebase/app"; import firebase from "firebase/app";
import "firebase/messaging"; import "firebase/messaging";
var startPermission = Notification.permission;
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
if (Notification.permission === 'granted') { if (Notification.permission === 'granted') {
const firebaseConfig = { const firebaseConfig = {
@ -31,39 +32,14 @@ if (process.env.NODE_ENV === "production") {
Notification.requestPermission(function (status) { Notification.requestPermission(function (status) {
console.log("Status ", status); console.log("Status ", status);
if (status === 'granted' && startPermission !== 'granted') {
window.location.reload();
}
}) })
}, },
registered($registration) { registered($registration) {
if (Notification.permission === 'granted') { console.log("serwiceworker registered.");
const messaging = firebase.messaging.isSupported() ? firebase.messaging() : null subscribeFirebase($registration);
if (messaging != null) {
console.log("Service worker has been registered. ", $registration);
messaging.useServiceWorker($registration);
messaging.usePublicVapidKey('BEbiSQ7ishlWlO7v-_EJW3iFk6WmgdSFrPgfXsjLNflqljBqWEZwv-4iyaTaYYE1VM2y1fX9V50QoZ0c8ft5C0s');
messaging.getToken().then(function (token) {
console.log("Token: ", token)
console.log(JSON.stringify({ "token": token }));
//FIX: New URL
axios.post('https://api.gabenparadise.com/subscribe', {
"token" : token
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
});
} else {
document.getElementById("sub-identifi").className = "fa fa-bell-slash-o bell";
}
} else {
document.getElementById("sub-identifi").className = "fa fa-bell-slash-o bell";
}
}, },
cached() { cached() {
console.log("Content has been cached for offline use."); console.log("Content has been cached for offline use.");
@ -85,3 +61,37 @@ if (process.env.NODE_ENV === "production") {
} }
}); });
} }
function subscribeFirebase($registration) {
if (Notification.permission === 'granted') {
const messaging = firebase.messaging.isSupported() ? firebase.messaging() : null
if (messaging != null) {
console.log("Service worker has been registered. ", $registration);
messaging.useServiceWorker($registration);
messaging.usePublicVapidKey('BEbiSQ7ishlWlO7v-_EJW3iFk6WmgdSFrPgfXsjLNflqljBqWEZwv-4iyaTaYYE1VM2y1fX9V50QoZ0c8ft5C0s');
messaging.getToken().then(function (token) {
console.log("Token: ", token)
console.log(JSON.stringify({ "token": token }));
//FIX: New URL
axios.post('https://api.gabenparadise.com/api/subscribe', {
"token": token
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
).then(function (response) {
console.log(response);
}).catch(function (error) {
console.log(error);
});
});
} else {
document.getElementById("sub-identifi").className = "fa fa-bell-slash-o bell";
}
} else {
document.getElementById("sub-identifi").className = "fa fa-bell-slash-o bell";
}
}