We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Webpush Channels

Formal Metadata

Title
Webpush Channels
Subtitle
The pub-sub channels based push service...
Alternative Title
Webpush notifications for Kinto
Title of Series
Number of Parts
611
Author
License
CC Attribution 2.0 Belgium:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language
Production Year2017

Content Metadata

Subject Area
Genre
Abstract
After introducing the Kinto project I am working on, I will explain why pushnotifications can be useful in the web environment and how I integrated theweb push API in Python in Kinto as well as on the client using serviceworkers. What is Kinto? Kinto is a minimalist JSON storage service with synchronisationand sharing abilities. It is easy to use and to self-host. Kinto is used anddeveloped at Mozilla and released under the Apache v2 licence. Why use Kinto? Kinto lets you focus on writing great user-facing interfacesand takes care of storing, sharing and synchronizing your application statewith multiple devices or users. It is often a big deal for developers todevelop web APIs that handle CORS, are secure, respect users privacy bysupporting encryption when building applications that work offline, store dataremotely, and synchronise across devices. Existing solutions either rely onbig corporations that crave user data, or require a non-trivial amount of timeand expertise to develop a new server for every new project. We want to helpdevelopers focus on their business logic and value proposition, and we don’twant the challenge of storing user data or developing backends to get in theirway. The path between a new idea and deploying to production should be short!Also, we are firm believers of the fact that data belongs to users, and notnecessarily to the application authors. Applications should be decoupled fromthe storage location, and users should be able to choose where their personaldata is stored. The backend can often be universal, generic and reusable. Weenvision mutualisation of services and self-hosting: the backend is deployed,secured and scaled only once for several applications, which is amazing! Why Web Push? Push notifications allow users to opt-in to timely updates fromthe sites they love and allow you to effectively re-engage them with not onlycustomized and engaging content but also enable real time interactions withother users of the application, realtime updates and real time data sharingthrough websockets With Web Push, the notification payload is encrypted by theserver sending the notification which makes it really secure and privacyaware. Web push is a browser API feature so that you don't need to pay or todeploy anything on the server side to have it working out of the box. HOW TO PUSH: What is a service worker? A service worker is a worker working in thebackground of your browser that can handle events for a given origin and path.It takes the form of a JavaScript file that can control the web page/site itis associated with. They will also allow handling of push notification eventsand background sync APIs. Service workers keep working after the page orwebsite is closed and between browser restarts. How to use push notifications? On the client side, it means to setup a serviceworker and to get a subscription for the user browser. The resultingPushSubscription includes all the information that the application needs to beable to send a push message: an endpoint and the encryption key needed forauthenticating and encrypting the data. What is the Kinto Push Service? In the Kinto use case, all users of the sameweb application will probably want to receive notifications informing themabout the creation, updation or deletion of a collection or a record fromanother device. Each device will have its own subscription endpoint andencryption key and the payload will need to be sent to each one of them. Myproject was about creating a service that can handle subscriptions managementand notification broadcast for a given channel. When the web applicationstarts, it will start a service worker that will be configured to receive pushnotification and sent them back to all the active browser pages of the webapplication. The application will call the push service to register the pushsubscription on some events. A Kinto plugin will be triggered each time theapplication collection changes and it will call the ‘send the notifications’on the push service channel. The push service will get the notification,encrypt it and publish it to all the subscriptions for that user. Role of the PushAPI: \- So, once you’ve got the permission for notifs,registered the service worker and suscribed to push notifs! Congratulations,major breakthrough has been achieved already. \- Send the endpoint associatedwith the subscription and generate a client public key(PushSubscription.endpoint and PushSubscription.getKey()) to the server so itcan send push message when required. \- Using the Channel Messaging API set upa new message channel (MessageChannel.MessageChannel()) to communicate withthe service worker and by calling Worker.postMessage() on the service worker,in order to open up the communication channel. \- On the server side, storethe endpoint and any other required details so they are available when a pushmessage needs to be sent to a push subscriber. In a production app, it needsto be…