GoogleChromeLabs / web-push-codelab

Other
556 stars 291 forks source link

Please describe how the connection between server and client are established #33

Closed jwillmer closed 7 years ago

jwillmer commented 7 years ago

After registration of the push event we get displayed a endpoint beginning with https://fcm.googleapis.com but there is no description how this endpoint was created and how to create an endpoint that points to your local(?) server.

sergioburdisso commented 7 years ago

That is the Message Server enpoint your serviceworker was subscribed to, that endpoint is the one your local(?) server has to send messages to (using the rest of information contained in the subscription object) in order for it to notify that serviceworker. Think of the Message Server as a proxy between your server and the client you want to notify. The "dialog" between your server and the Messe Server (in this case, fcm.googleapi.com) must be done in a very very precise way (partially defined here. That's why I ended up creating a Python package (solidwebpush) to carry out that work, the only thing you have to supply is the subscription JSON object and the message you want to send. Hope my answer helps you (even if it's just a little bit n.n).

jwillmer commented 7 years ago

Thx for the technical description of how the notification works. Do I understand you right that I can't use this solution offline? So if I am in a local network without internet connection I can't trigger a push notification on a phone in the same network (that does not have internet)? In other words: Is a connection to Google mandatory?

sergioburdisso commented 7 years ago

mmm I'm afraid you can't, each browser vendor subscribe the serviceWorkers to its own Message Server (Chrome: fcm.googleapi.com, Firefox: updates.push.services.mozilla.com, etc.), so it is something we don't have control over...

Although technically there's a solution, it would require you to sort of "hack" your network, namelly, it would require a Man In The Middle attack. You would have to code a program to redirect all your network traffic to that program (probably using raw sockets, and sending ARP packets), and then make that program listen for request to those Message Servers (those request will be over HTTPS - port 443), then your program has to send exactly the same response the real Message Server would send. It's is not an easy task.... but it is the only solution I cant think of.

Note: Your browser will block any serviceWorker registration that is not over a "secure connection", that means that your server MUST be serving request over HTTPS or you could install your web app locally on your users devices (so that they can be accessed by "localhost").

jwillmer commented 7 years ago

O.K. so bad news for me. The described scenario is the one I am facing. I created a Stackoverflow question about this. If you like you can post your answer there as well (and I accept it as answer) or I will reference it to this issue.

sergioburdisso commented 7 years ago

Ok!

gauntface commented 7 years ago

Thanks for discussing this and coming to a conclusion.