# How Browser and Mobile Pushes Work
---
### Browser aka Web Pushes
* [RFC 8030](https://www.rfc-editor.org/rfc/rfc8030)
* [W3C Push API standard](https://w3c.github.io/push-api/)
* [Google's tutorial on web pushes](https://developers.google.com/web/fundamentals/push-notifications/web-push-protocol)
---
### Browser aka Web Pushes
```plantuml
participant "User Agent" as UA
participant "Push Service" as PS
participant "Application Server" as AS
== Subscribing ==
UA -> PS : Subscribe
UA -> AS : Distribute subscription
== Receiving pushes ==
UA <-> PS : Monitor pushes
AS -> PS : Push message
PS -> UA : Push message
== Unsubscribing ==
UA -> PS : Unsubscribe
```
----
### Browser aka Web Pushes

----
```
// User Agent starts receiving pushes
HEADERS [stream 7] +END_STREAM +END_HEADERS
:method = GET
:path = /subscription/LBhhw0OohO-Wl4Oi971UG
:authority = push.example.net
// Push Service sends a push
PUSH_PROMISE [stream 7; promised stream 4] +END_HEADERS
:method = GET
:path = /message/qDIYHNcfAIPP_5ITvURr-d6BGt
:authority = push.example.net
// (cont'd vvvv)
```
----
```
// (cont'd ^^^^)
// Push Service sends a push
HEADERS [stream 4] +END_HEADERS
:status = 200
date = Thu, 11 Dec 2014 23:56:56 GMT
last-modified = Thu, 11 Dec 2014 23:56:55 GMT
cache-control = private
link = </push/JzLQ3raZJfFBR0aqvOMsLrt54w4rJUsV>;
rel="urn:ietf:params:push"
content-type = text/plain;charset=utf8
content-length = 36
// (cont'd vvvv)
```
----
```
// (cont'd ^^^^)
// Push Service sends a push
DATA [stream 4] +END_STREAM
iChYuI3jMzt3ir20P8r_jgRR-dSuN182x7iB
// User Agent stops receiving pushes
<<<HEADERS [stream 7] +END_STREAM +END_HEADERS
:status = 200
```
---
### Mobile Pushes
* [Google Firebase Cloud Messaging docs](https://firebase.google.com/docs/cloud-messaging/server)
* [Apple Push Notifications docs](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html)
* [Google GCM vs Apple APNS](https://citrusbits.com/google-gcm-vs-apple-apns/)
---
### Mobile Pushes
* Same idea as in web pushes
* Focus on battery saving
* Allow XMPP two-way messaging
---

{"metaMigratedAt":"2023-06-16T19:31:39.622Z","metaMigratedFrom":"YAML","title":"How Browser and Mobile Pushes Work","breaks":true,"slideOptions":"{\"theme\":\"solarized\"}","contributors":"[{\"id\":\"e03327bd-87b7-4ac5-9cc2-2a66b2df58cf\",\"add\":3466,\"del\":3262}]"}