Post on 23-May-2020
transcript
Push Notifications allows you to let your visitors subscribe events on your website in order to send them targeted notifications
In GittiGidiyor, we have lots of visitors comes from mobile web via mobile phone, and we aim to reach them via native notifications
Table of Contents
● What is Service Worker?● What is Promise?● Google Cloud Message Account Setup● Sending Push Notification to Chrome● Demo
Service Worker
● JS worker● Has no DOM access● Programmable network proxy● Extensive use of promises● HTTPS is required● Domain specific
var messagePromise = new Promise(function(resolve, reject) {
fetch(“/messages”).then(function(response) {
response.ok? resolve(response.json()): reject(“Error occurred”)
});
});
messagePromise.then(function(result) {
console.log(“Success”);
}, function(err) {
console.log(“Error”);
})
messages.js
FCM is the new version of GCM. Firebase
currently does not have API for Web Push
Notifications, but you can use
VAPID(Voluntary APplication server
IDentification for push message) to send
messages through FCM.
curl --header "Authorization: key=<API_KEY>"
--header Content-Type:"application/json"
https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"<SUBSCRIPTION_ID>\
"]}"