}); }); asyncOne() .then(asyncTwo) .then(asyncThree) .catch(function(error) { // handle error }); traditional callbacks using promises Service Workers make extensive use of promises
called endpoint, which might look like this: https://android.googleapis. com/gcm/send/APA91bHPffi8zclbIBDcToXN_LEpT6iA87pgR-J-MuuVVycM0SmptG- rXdCPKTM5pvKiHk2Ts-ukL1KV8exGOnurOAKdbvH9jcvg8h2gSi- zZJyToiiydjAJW6Fa9mE3_7vsNIgzF28KGspVmLUpMgYLBd1rxaVh- L4NDzD7HyTkhFOfwWiyVdKh__rEt15W9n2o6cZ8nxrP
called endpoint, which might look like this: https://android.googleapis. com/gcm/send/APA91bHPffi8zclbIBDcToXN_LEpT6iA87pgR-J-MuuVVycM0SmptG- rXdCPKTM5pvKiHk2Ts-ukL1KV8exGOnurOAKdbvH9jcvg8h2gSi- zZJyToiiydjAJW6Fa9mE3_7vsNIgzF28KGspVmLUpMgYLBd1rxaVh- L4NDzD7HyTkhFOfwWiyVdKh__rEt15W9n2o6cZ8nxrP
{ // Unsubscribe successful! }); } else { // We are not yet subscribed for push notifications. } }) Chrome: need to pass { userVisibleOnly: true } to subscribe() method.
messages between servers and client applications or vice versa. Handles all aspects of the message transfer, from queueing of the messages up to their delivery to and from the client applications. Google Cloud Messaging
https://android.googleapis.com/gcm/send method: POST headers: Authorization: key=GCM_SERVER_KEY Content-Type: application/json Data: <GOOGLE_CLOUD_MESSAGING_OPTIONS> Sending notification from server to GCM
a list of subscription tokens for multiple recipients collapse_key Identifies a group of messages that can be collapsed, meaning that only the latest message with this key will be delivered to the client time_to_live Specifies how long (in seconds) the message should be kept in GCM storage while the client is still offline notification Specifies a predefined notifications object Google Cloud Messaging options
Can’t get list of visible notifications for programmatic closing - Notifications can only be userVisibleOnly - On mobile, predefined notification data only appears when Chrome is closed - On desktop, when Chrome is closed, push notifications won’t be received Push Notifications - The ಠ╭╮ಠ Parts
network requests '/static/service-worker.js' ⇒ scope: '/static' - Fires 'fetch' events only for requests with paths that start with '/static' - Won’t fire 'fetch' event for e.g. '/images/sample.png' ServiceWorker Scope
cache resources from other origins - Can also dynamically cache requested resources - Due to the ability to intercept network requests, Service Workers need to be served over HTTPS for security purposes Offline Mode - Other Stuff
background sync! // Next, save the message to a persistent storage. }); The 'send-message' string passed to the register() method is a tag, which can be checked in the service worker to determine how it should send the data to the server.
function(event) { if (event.tag === 'send-message') { // Retrieve from persistent storage those objects that are tagged // as 'send-message'. } }); One 'sync' event for each unique registered tag.