WEB PUSH Johannes Brodwall
Outline
The low down Is it time? Implementation notes Firefox Chrome Safari Implementation bits
What’s up?
What
What Notification bubbles on web and mobile
What Based on (unstable) standards
What Using major push networks Google Cloud Messaging Apple Push Notification service
Why
No installation required Don’t need to be on webpage
Why Keep users up to date Notify of pending work
Why Reach more clients with less code
How
Set up application with push service provider(s)
How Client JavaScript: navigator.serviceWorker.register <- registration registration.pushManager.subscribe <- endpointId Sends endpointId to server Application server saves endpoint
How Application server Sends a proprietary command to Push Provider Client ServiceWorker registration.showNotification
What Why How
Potential and reality
Safari OS X Mavericks October, 2013
Safari announcement screenshot
Safari Web, but not iPhone Non-standard Technologically … advanced
Chrome 42, April 21 st, 2015
Chrome Mac, PC, Android, but not iPhone Based to open standards Pretty easy to implement
Others
Firefox nightly almost there Opera experimental, but doesn’t work Internet Explorer – never? Microsoft Edge – “Under consideration”
Trouble
Permissions HTTPS SSL (APNs)
Ready?
Today ~ 50% desktops and ~40% mobiles Optional value added feature
Yes – as optional feature
Implementation
Implementing registration 1. Setup application with push provider 2. Client starts JavaScript service worker 3. Client requests permissions 4. Client registers with push provider 5. Client sends endpointId to app server
Implementing notification 1. App server notifies push provider 2. Push service awakens service worker on client 3. Service worker fetches message from app server 4. Service worker shows notification
== Register a user for push notifications == User -> webpage: Click registration webpage -> serviceworker:register webpage -> browser: subscribe browser -> GCM: subscribe webpage <-- browser: endpointId webpage -> appserver: endpointId User -> webpage: Closes window
== Send push notifications == [-> appserver: Send message to user appserver -> GCM: POST endpoints GCM -> serviceworker: onpush() serviceworker -> appserver: GET /last-message serviceworker -> browser: showNotification browser -> User: Shows notification User -> browser: Clicks notification browser -> serviceworker: onnotificationclick() serviceworker -> browser: openWindow browser -> webpage: Display webpage webpage -> User
Firefox (Nightly)
No registration needed with Mozilla push Do HTTP PUT to endpointId
TODO: Code for app server
TODO: Code for service worker
Implementation bits
Promises Permissions ExpressJs
Implementation bits Promises Permissions ExpressJs
Implementation bits Promises Permissions ExpressJs
Chrome
Register application with Google Developer Console Do HTTP POST with a list of endpointIds as JSON payload
TODO: Code for service worker
Safari
Apple Push Notification service Get SSL certificate from Apple Create push package (zip file with ssl signature) Request push permission Send payload to Apple over ssh port 2195
Create push package
Open SSL reference 1. Getting the key and pem cert files openssl genrsa -out.key 2048 openssl req -new -sha256 -key.key –out.csr Sign.csr with Apple and get.cer openssl x509 –in website_aps_production.cer –inform DER –out website_aps_production.pem –outform PEM
Files.key – private key in PEM (readable) format – keep secret!.csr – Certificate signing request in in PEM (readable) format – give to Apple and then discard website_aps_production.cer – Valid certificate you get from Apple in DER (binary) format website_aps_production.pem – Valid certificate in PEM (readable) format
Open SSL reference 2. Signing files openssl smime -sign -signer certificate.pem -inkey.key -in -binary -outform DER -out signature file Verify signature (for debugging) openssl smime –verify –in signature file –inform DER –content –noverify
Registering client
Sending push notifications
Cordova
Cordova/Adobe Phonegap Supports Android, iOS, Windows Push notifications through 3 rd party plugin (not Windows) Uses APNs and GCM (like web push)
Azure
Azure notification hubs Provides common contact point Doesn’t actually solve the hard bits
Summary
Push API Provides web push to almost ½ of desktop market now Only web supported on Chrome (50%), but look out for Firefox (15%)! Replaces many apps on Android Easy to implement
Safari push Not supported on mobile Needlessly hard to implement, but APNs is also needed for iOS apps
Implementation bits Promises ExpressJS Permissions
My last mobile app used Cordova My next will be pure web for Android
THANK YOU