Upload
-
View
897
Download
0
Embed Size (px)
Citation preview
Web Push NotificationYulia Oletskaya / Konstantin Reido
WebPush Notification?
Advantages
Timely and relevantEasy to accessGo straight to the
detailsFull control
● More visitors
Google Chrome
What is Web App Manifest?JSON file that intended to be
a centralized place to put metadata associated with a
web application
This includes, but is not limited to:
the web application's namelinks to iconsthe preferred URL to open
when a user launches the web application
a default orientation for web application
display mode for the application (e.g., in fullscreen)
Google Developers Console
What is Service Worker?
A service worker is a script that is run by browser in the background, separate from a web page, opening the door to features which don't need a web page or user interaction.
What is Service Worker?
It's a JavaScript Worker, so it can't access the DOM directly. Instead, a service worker can communicate with the pages by postMessage interface.
HTTPS is Needed.
Service worker is a programmable network proxy, that allows to control how network requests from web page are handled.
It will be terminated when not in use, and restarted when it's next needed.
Service workers make extensive use of promises.
Note: localStorage works in a similar way to service worker’s cache, but it is synchronous, so not allowed in service workers.
Service Worker Use Cases
Background data synchronization
Prefetching and/or caching data for later use
Code syntax highlighting or other real-time text formatting
Hooks for background services
Spell checker
Analyzing video or audio data
Background I/O or polling of webservices
Processing large arrays or humungous JSON responses
Image filtering in <canvas>
Reacting to push messages
Register a Service Worker
Service Worker Initial State
Subscribe a Service Worker
Unsubscribe a Service Worker
Send Out Push Notifications
Service Worker Example
Quick Flow Scheme
Safari
Local vs Web Push Notifications
TLS/SSLAsynchronous binary interface over TCP socket:
gateway.push.apple.com, port 2195gateway.sandbox.push.apple.com, port 2195
Feedback Servicefeedback.push.apple.com, port 2196feedback.sandbox.push.apple.com, port 2196
Notification payload{ "aps": { "alert": { "title": "Flight A998 Now Boarding", "body": "Boarding has begun for Flight A998.", "action": "View" }, "url-args": ["boarding", "A998"] }}
● API● Push Package
{
"websiteName": "Bay Airlines",
"websitePushID": "web.com.domain",
"allowedDomains": ["http://domain.com"],
"urlFormatString": "http://domain.com/%@/?flight=%@",
"authenticationToken": "19f8d7a6e9fb8a7f6d9330dabe",
"webServiceURL": "https://domain.com/push"
}
{ "website.json": "96838c4...d7760fa4043a8", "icon.iconset/icon_16x16.png": "865f1...93796a6341", ...}
Best Practices
rpushThe push notification service for Ruby
Supported Services
Apple Push Notification Service
Google Cloud Messaging
Amazon Device Messaging
Windows Phone Push Notification Service
Feature Highlights
Use ActiveRecord, Redis or MongoDB for storage.
Plugins. You can write your own.
Seamless integration with your projects, including Rails.
Run as a daemon, inside a job queue, on the command-line or embedded in another process.
Feature Highlights
Scales vertically (threading) and horizontally (multiple processes).
Designed for uptime - new apps are loaded automatically, signal HUP to update running apps.
Hooks for fine-grained instrumentation and error handling (Reflection API).
Works with MRI, JRuby and Rubinius.
rpush init
Create an Appapp = Rpush::Apns::App.new
app.name = "ios_app"
app.certificate = File.read("/path/to/sandbox.pem")
app.password = "certificate password"
app.environment = "sandbox"
app.connections = 1
app.save!
app.auth_key = "..."
Send a Notificationn = Rpush::Apns::Notification.new
n.app = Rpush::Apns::App.find_by_name("ios_app")
n.device_token = "..." # 64-character hex string
n.alert = "hi mom!"
n.data = { foo: :bar }
n.save!
n.registration_ids = ["..."]
n.data = { message: "hi mom!" }
Questions?
Konstantin Reido
skype: konstantin.reido
Yulia Oletskaya
skype: tuwukee