HTML5 Push Notifications - examples of other ways to push

2.5k views Asked by At

At Google IO 2015, there was a lot of talk of the push notifications for Chrome with HTML5 and service workers.

It's early days, and examples are thin on the ground. I'm looking for server side examples of how to implement the push from platforms other than Google Cloud Messaging - Azure Mobile Services, for example, or AWS.

2

There are 2 answers

0
Matt Gaunt On BEST ANSWER

At the moment push on Chrome is tied to GCM, there is a new standard being actively worked on that will make push services all use the same API. When this happens I'm hoping Chrome and GCM will implement it and you'll then be able to implement a single API. Firefox are already using an early version of the this standard in nightly builds. For now just bare in mind, things are likely to vary between Chrome and Firefox.

Regarding server side examples - I don't have any code for Azure, but if you check out this simple-push-demo there is a curl command that basically interacts with the GCM restful API to initiate a push message.

Example:

curl --header "Authorization: key=<YOUR_PUBLIC_API_KEY>"
     --header "Content-Type: application/json"
     https://android.googleapis.com/gcm/send
     -d "{\"registration_ids\":[\"<YOUR_REGISTRATION_ID>\"]}"

You can use this to get an idea of how the API works and implement it in whatever server side language you need (It's basically a post request with a special header).

The docs for the GCM API is here.

You can view the source code for the simple push demo on Github.

Backend code for sending a push message from the server in the demo (Written in Python for AppEngine) is on Github here.

Finally if you want a full tutorial then check out this article on html5rocks.

0
RickSaling On

This tutorial ( https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-android-get-started-push/ ) does use GCM, but the general technique is supported across all platforms, iOS and Windows so you are not tied to GCM (for example this tutorial: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-windows-universal-dotnet-get-started-push/ )