How are web push messages delivered?

2019-07-30 05:07发布

问题:

I try to set up push messages for a web page. While I understand the front-end part (the Push API) and have a working localhost demo app, I just don't get how a server can push a message to the browser.

How are the packages from the push service routed to the client? The client has no domain name and usually no fixed IP address, so how is this possible?

I've read Google's guide to Web Push Libraries and parts of RFC 8030, but if they have the answer to this question, it eluded me.

回答1:

Your application server makes a POST request using the browser endpoint as the URL.

The browser endpoint is something like: https://updates.push.services.mozilla.com/A_VERY_LONG_TOKEN_123. That means that the POST request is sent to a web service owned by the browser manufacturer (e.g. Mozilla autopush for Firefox).

Then the browser push service is responsible for the delivery of the message to the browser. It's the client that creates a persistent connection with the browser push service. Also consider that once the TCP connection is established you get a full duplex / bidirectional channel (the server can send messages without a prior request from the client).

See also this introduction about web push.



标签: web-push