-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
60 lines (54 loc) · 2.55 KB
/
index.html
File metadata and controls
60 lines (54 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Push notifications</title>
</head>
<body>
<h1>Firebase push notifications</h1>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-app.js";
import { getMessaging, getToken } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-messaging.js";
//import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.14.0/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyBD57M4agHJZ_lWVA9gSrr0oNuCAQzcIp4",
authDomain: "pushnotificationssystem.firebaseapp.com",
projectId: "pushnotificationssystem",
storageBucket: "pushnotificationssystem.appspot.com",
messagingSenderId: "615114138461",
appId: "1:615114138461:web:f95bb5dd93902058b0feb4",
measurementId: "G-X513RBP47V"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
//const analytics = getAnalytics(app);
// Initialize Firebase Cloud Messaging and get a reference to the service
const messaging = getMessaging(app);
navigator.serviceWorker.register('SW.js').then((registration) => {
getToken(messaging, {
serviceWorkerRegistration: registration,
//forceRefresh: true,
vapidKey: 'BPB8G-OC73hlMeWULbL6Ss43vHsX7h5kAhXLz9b2K7gE84ASOTywD43UqRcHbidO5dSPwPQ7UnutfArAtu54RBA'}).then((currentToken) => {
if (currentToken) {
console.log('currentToken: ', currentToken);
// Send the token to your server and update the UI if necessary
// ...
} else {
// Show permission request UI
console.log('No registration token available. Request permission to generate one.');
// ...
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
// ...
});
});
</script>
</body>
</html>