jmap.dev

Push in practice

The push guide explains the three ways a JMAP server tells an app something changed. This one is about building with them: the settings that matter, and what to do after a gap.

EventSource

The session's eventSourceUrl is a template with three blanks:

BlankWhat to put
typesWhich kinds of data to hear about, such as Email,Mailbox, or * for everything
closeafterno to stay connected, or state to close after the first change
pingSeconds between pings when nothing happens. 30 to 60 stops proxies closing a quiet connection

Browsers' built in EventSource can't send an Authorization header, so web apps often read the stream with fetch instead, as the push tester does.

Web Push

  1. Create a PushSubscription with PushSubscription/set, giving the push address, a device id and, ideally, encryption keys.
  2. The server sends a verification code to that address first. Send it back with another PushSubscription/set to switch the subscription on.
  3. Subscriptions expire. Keep track of expires and renew before then.

With encryption keys, the push service in the middle can't read the alerts. Servers listing urn:ietf:params:jmap:webpush-vapid also sign them, so the push service knows where they came from.

After a gap

Alerts can be missed: phones sleep, connections drop and apps get closed. So never trust that you saw every alert. Each time you reconnect, call /changes for each type from the states you saved. That catches anything you missed, and if nothing changed it costs one small request.

Less work for the same result

Words you don't know? See the glossary.

Try the push tester The push guide