This repository contains an example using Firebase Realtime Database and Firebase Cloud Messaging that I will use in my theorical project of DAW (Diseño de Aplicaciones Web).
In order to make it work, you have to:
- Clone the repository
- Set your own variable and keys in the next files:
- js/fcm.js (lines 2-6, 80)
- firebase-messaging-sw.js (lines 5-9)
- Set the Firebase Security Rules of the Database to 'true':
{
"rules": {
".read": "true",
".write": "true"
}
}
- At this point, you will be able to receive Push notifications and to use the HTML form to send JSON Objets to the Realtime database.
You can use the Firebase Console to send Push notifications, but also you can use the cURL command that are in /res/notifications.txt to send a Push notification to a specific user or to a specific topic (remember to set your server key).
Figure 1 - Interface
Figure 2 - Push Notification received