42
Web Push Notification Yulia Oletskaya / Konstantin Reido

Brug - Web push notification

  • Upload
    -

  • View
    897

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Brug  - Web push notification

Web Push NotificationYulia Oletskaya / Konstantin Reido

Page 2: Brug  - Web push notification

WebPush Notification?

Page 3: Brug  - Web push notification

Advantages

Timely and relevantEasy to accessGo straight to the

detailsFull control

● More visitors

Page 4: Brug  - Web push notification

Google Chrome

Page 5: Brug  - Web push notification

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)

Page 6: Brug  - Web push notification
Page 7: Brug  - Web push notification

Google Developers Console

Page 8: Brug  - Web push notification

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.

Page 9: Brug  - Web push notification

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.

Page 10: Brug  - Web push notification

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

Page 11: Brug  - Web push notification

Register a Service Worker

Page 12: Brug  - Web push notification

Service Worker Initial State

Page 13: Brug  - Web push notification

Subscribe a Service Worker

Page 14: Brug  - Web push notification

Unsubscribe a Service Worker

Page 15: Brug  - Web push notification

Send Out Push Notifications

Page 16: Brug  - Web push notification

Service Worker Example

Page 17: Brug  - Web push notification

Quick Flow Scheme

Page 18: Brug  - Web push notification

Safari

Page 19: Brug  - Web push notification

Local vs Web Push Notifications

Page 20: Brug  - Web push notification

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

Page 21: Brug  - Web push notification
Page 22: Brug  - Web push notification
Page 23: Brug  - Web push notification

Notification payload{ "aps": { "alert": { "title": "Flight A998 Now Boarding", "body": "Boarding has begun for Flight A998.", "action": "View" }, "url-args": ["boarding", "A998"] }}

Page 24: Brug  - Web push notification
Page 25: Brug  - Web push notification
Page 26: Brug  - Web push notification

● API● Push Package

Page 27: Brug  - Web push notification
Page 28: Brug  - Web push notification
Page 29: Brug  - Web push notification

{

"websiteName": "Bay Airlines",

"websitePushID": "web.com.domain",

"allowedDomains": ["http://domain.com"],

"urlFormatString": "http://domain.com/%@/?flight=%@",

"authenticationToken": "19f8d7a6e9fb8a7f6d9330dabe",

"webServiceURL": "https://domain.com/push"

}

Page 30: Brug  - Web push notification

{ "website.json": "96838c4...d7760fa4043a8", "icon.iconset/icon_16x16.png": "865f1...93796a6341", ...}

Page 31: Brug  - Web push notification
Page 32: Brug  - Web push notification
Page 33: Brug  - Web push notification
Page 34: Brug  - Web push notification

Best Practices

Page 35: Brug  - Web push notification

rpushThe push notification service for Ruby

Page 36: Brug  - Web push notification

Supported Services

Apple Push Notification Service

Google Cloud Messaging

Amazon Device Messaging

Windows Phone Push Notification Service

Page 37: Brug  - Web push notification

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.

Page 38: Brug  - Web push notification

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.

Page 39: Brug  - Web push notification

rpush init

Page 40: Brug  - Web push notification

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 = "..."

Page 41: Brug  - Web push notification

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!" }

Page 42: Brug  - Web push notification

Questions?

Konstantin Reido

[email protected]

skype: konstantin.reido

Yulia Oletskaya

[email protected]

skype: tuwukee