• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    CSS
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example website using Web Push Notifications with Realtime Pub/Sub Messaging service and Firebase Cloud Messaging

Web Push Notifications with Realtime

This project shows how to use the Web Push Notifications API in a website, allowing easy engagement with users that are currently not browsing the website. This project uses the Realtime Messaging JavaScript SDK and requires Chrome 50+ or Firefox 44+.

Realtime + Web Push Notifications guide

  • Register to get your free Realtime Messaging application key at https://accounts.realtime.co/signup/

  • Create a Firebase Cloud Messaging project. Follow this tutorial.

  • Open the index.html file and replace the Firebase initialization code shown below with the configuration code you got in the previous step:

        <!-- START INITIALIZATION CODE -->
        <script src="https://www.gstatic.com/firebasejs/3.5.0/firebase.js"></script>
        <script>
          // Initialize Firebase
          var config = {
            ...
          };
          firebase.initializeApp(config);
        </script>
        <!-- END INITIALIZATION CODE -->
    
  • In the index.js file replace the Realtime demo application key (K4xqxB) with your own Realtime application key:

      var RealtimeAppKey = "K4xqxB"; 
    
  • Edit the service-worker.js file enter your Firebase Sender ID in the messagingSenderId property:

      firebase.initializeApp({
        'messagingSenderId': '915139563807'
      });
    
  • Map a webserver to folder where you have cloned this repository, open http://localhost/index.html in your Chrome/Firefox browser and try it out. If it doesn't work as expected have a look at the limitations and troubleshooting sections below.

Limitations

  1. This will only work on Chrome 50+ and Firefox 44+
  2. If you are not using localhost you must use the https protocol (it will work on localhost with http)
  3. At least one Chrome/Firefox tab must be opened in order to receive push notifications

Troubleshooting

  • If you get the following error message it means you have changed the gcm_sender_id in your manifest.json file. Please update your manifest and enter the exact value shown in the message:

      Messaging: Please change your web app manifest's 'gcm_sender_id' value to '103953800507' to use Firebase messaging. (messaging/incorrect-gcm-sender-id).
    

Not receiving push notifications

  • Check that you are running the example from a webserver (e.g. http://localhost) and not from the file system (e.g. file:///C:/web/WebPushNotifications-master/index.html);

  • Check that you have entered the right Firebase configurations;

  • Don't forget to give permissions for the push notifications when your browser requests them;

  • Make sure your webserver is properly configured to serve the file manifest.json (check if there are no 404 errors in your browsers Developers Tool network tab). IIS users may need to add the MIME type;

  • If you're not using localhost make sure you are using the https protocol with a valid SSL certificate for the domain you are using;

  • Check if you have any other browser tab opened using the website you're testing. If you do, make sure that page has a Realtime connection established and is subscribing the push notification channel. Push notifications won't be displayed to users that are currently browsing the site that originated the push.

Private channel vs Global channel

If you want to control to which users you are sending each push you should use a private channel for each user. If you want to broadcast a push notification to all users you should use a global channel that every user subscribes.

A mixed private/global channel strategy can also be used, it really depends on your use case.

On-line example

You can test the Realtime Web Push Notifications here.

More Repositories

1

ChromePushNotifications

Sample website using Chrome Push Notifications with Realtime Pub/Sub Messaging service
116
star
2

Messaging

The Realtime Cloud Messaging examples
Objective-C
67
star
3

RCTRealtimeMessagingAndroid

Realtime Cloud Messaging React Native SDK for Android
Java
52
star
4

MessagingAndroidChat

Android real-time group chat using Realtime Messaging (includes FCM push notifications)
Java
48
star
5

Storage

The Realtime Cloud Storage Examples
HTML
36
star
6

RCTRealtimeMessagingIOS

Realtime Cloud Messaging React Native SDK for iOS
Objective-C
30
star
7

RCTRealtimeNews

Enterprise mobile app using React Native and the Realtime Platform
JavaScript
29
star
8

CordovaPush

Cordova/Ionic/PhoneGap plugin with Realtime Messaging (for in-app messaging) and Push Notifications support for the iOS and Android platforms
Objective-C
14
star
9

MessagingObjectivecChat

iOS real-time group chat using Realtime Messaging and ObjectiveC (includes APNS push notifications)
Objective-C
12
star
10

unity3d-plugin

Unity3d plugin for Realtime Cloud Messaging and Realtime Cloud Storage
C#
12
star
11

MessagingSwiftChat

iOS real-time group chat using Realtime Messaging and Swift
Swift
12
star
12

MessagingIonicChat

Cross-platform mobile chat built with Ionic 1 and Realtime Messaging (including mobile push notifications)
JavaScript
10
star
13

RCTRealtimeMessaging

Realtime Cloud Messaging React Native SDK
9
star
14

RealtimeMessaging-Android

Realtime Cloud Messaging Android SDK
Java
8
star
15

RCTRealtimeCloudStorage

Realtime Cloud Storage React Native SDK for iOS
8
star
16

StorageReactNativeTodo

Todo example using Realtime Cloud Storage and React Native for iOS
JavaScript
7
star
17

RealtimeMessaging-Go

Realtime Cloud Messaging Go SDK
Go
7
star
18

MessagingIonic2Chat

Cross-platform mobile chat built with Ionic 2 and Realtime Messaging (including mobile push notifications)
TypeScript
7
star
19

RealtimeMessaging-Cocos2d-x

Realtime Messaging SDK for Cocos2d-x
C++
7
star
20

RealtimeMessaging-ReactNativeIOSExample

Realtime Cloud Messaging React Native Example (including APNS mobile push notifications)
JavaScript
6
star
21

multiplayer-flappy-bird

A multi-player Flappy Bird style game for iOS using the Realtime Framework for game sync
Objective-C
6
star
22

MessagingSwift3Chat

iOS real-time group chat using Realtime Messaging and Swift 3
Swift
6
star
23

MessagingJavascriptConsole

JavaScript developer console using Realtime Messaging
JavaScript
5
star
24

TitaniumPush

Titanium example for a cross-platform Realtime app using push notifications from GCM and APNS
JavaScript
5
star
25

tessel-dashboard

Real-time Tessel web dashboard using Realtime Messaging. Broadcast sensor data and remotely control the camera.
JavaScript
5
star
26

RealtimeMessaging-ReactNativeAndroidExample

Realtime Cloud Messaging React Native for Android Example (including GCM mobile push notifications)
JavaScript
5
star
27

TitaniumAndroidPush

Titanium app using Realtime and Push Notifications for Android (GCM)
4
star
28

RealtimeMessaging-Javascript

Realtime Cloud Messaging JavaScript SDK
JavaScript
4
star
29

RealtimeMessaging-DotNetCore

Realtime Messaging SDK for .NET Core
C#
4
star
30

RealtimeMessaging-iOS

Realtime Cloud Messaging iOS Objective-C SDK
Objective-C
4
star
31

RealtimeMessaging-PHP

Realtime Cloud Messaging PHP SDK
PHP
4
star
32

RealtimeMessaging-Java

Realtime Cloud Messaging Java SDK
Java
4
star
33

RealtimeMessaging-C

Realtime Cloud Messaging C SDK
C
3
star
34

MessagingReactChat

Simple chat example using React and Realtime Messaging
JavaScript
3
star
35

RCTRealtimeStorageAndroid

Realtime Cloud Storage React Native SDK for Android
Java
3
star
36

MessagingPhonegap

PhoneGap sample using Realtime Messaging and Adobe PhoneGap Build
JavaScript
2
star
37

StorageiOSChat

iOS group chat with persistence using Realtime Cloud Storage (includes APNS Push Notifications)
Objective-C
2
star
38

StorageAndroidChat

Android group chat with persistence using Realtime Cloud Storage (includes GCM Push Notifications)
Java
2
star
39

RealtimeMessaging-Portable

[DEPRECATED] Realtime Messaging SDK for Xamarin applications (SDK is PCL 256)
2
star
40

RealtimeMessaging-dotnet

Realtime Cloud Messaging .NET SDK
C#
2
star
41

RealtimeMessaging-UWP

Realtime Cloud Messaging SDK for Universal Windows Platform apps (Windows 10, Hololens, ...)
C#
2
star
42

realtime-news-swift

The Swift version of the Realtime Code Hosting example app, Realtime News
Objective-C
2
star
43

phonegap-push

Adobe PhoneGap Build app using Realtime and Push Notifications for iOS and Android (APNS/GCM)
HTML
2
star
44

realtime-news-backoffice

The content management system for the Realtime Code Hosting example app, Realtime News
JavaScript
1
star
45

RealtimeMessaging-Appcelerator

Realtime Messaging modules for Appcelerator
Java
1
star
46

RealtimeMessaging-iOS-Swift

Realtime Cloud Messaging iOS Swift SDK
Swift
1
star
47

MessagingWindows8.1-Example

The Universal Windows App Realtime Messaging example (Windows 8.1 and Windows Phone 8.1)
C#
1
star
48

RealtimeMessaging-Tessel

The Realtime Messaging Node.js client for Tessel
JavaScript
1
star
49

RealtimeMessaging-Node

Realtime Cloud Messaging Node.js SDK
JavaScript
1
star
50

UWP-SpokenChat

A simple "spoken" chat built using the Realtime Universal Windows Platform (UWP) SDK and the Windows Media SpeechRecognition API
C#
1
star