I make a news site. When news is added, all users are notified of the new news. I implemented the server part using Rachet and ZMQ, I don’t quite understand how to do it with the client part. So far, I have made notifications only through the console, everything works. But not through the console to notify users. The question is how to make an alert something like VC? What tools to use to support most browsers? thanks for answers

  • one
    Are you talking about the notification? There are a lot of google.com/ ... plugins, for example notifyjs.com or ned.im/noty/#/about and others .. you just need to search in the style of jquery notification - Aleksey Shimansky

3 answers 3

There are two types of push notifications: on one of the websites, they are turned, with other problems too.

The first type is if you have a tab with a site open, respectively, your js is quietly executed there.
The second type is real push notification. If you have a tab with the site is not selected or closed at all. But the browser is open at the same time.

For the implementation of the first type, you essentially need any ordinary message system from your server to your client. It can be at least web sockets, maybe long polling, maybe sse. Yes, even the signal fires on Googlemaps =)
Alexey Shimansky in his commentary meant exactly this type of messages.

With the second type all is more difficult. And you cannot implement them "just by screwing some kind of library or plugin on js". Because there is no this your client js when the tab is closed. Well, actually why the client should run your script if it is not on your site?

This can be done, but troubles await us on the way.

Let's start with the fact that there is a Notifications api specification. But of course it is not ready at all, browsers do not normally support it (which is to support something that will change ten times). It is not possible to use in a bloody enterprise. If you have a lot of enthusiasm and smoothies, you can try to fasten for some browsers.

And so it is solved now like this: large vendors of browsers provide their services through which you can accordingly work with the browsers of these vendors. GCM and APNS mentioned by misc in their answer are respectively such services for google and epl. There is a pack and from smaller companies.

This, of course, creates the following problem: in order for you to have everything wonderfully cross-browser and pink unicorns jump on the green lawn, you need to find as many of these services as possible and write a layer for everyone on your side, which will pull this service. And there is no universal format. And services are not so little. And each and every change sometimes, and will have to support somehow this zoo.

Accordingly, layers of varying degrees of reliability, functionality and chargeability appeared. Mentioned by mics on onesignal.com and clevertap.com refer to such layers.

And now to the bad. I did not find a ready-made working exclusively free solution (I was looking for about half a day, if someone prompts, I will be grateful.). There are paid solutions, there are services that provide a free trial and there are "free" ones.

Here onesignal.com is a free service. They will not take money from you for their decision, but as far as I understand from their agreement, they reserve the right to use and sell the data that you send through them to third parties. Suits you? Then try them.

  • thanks for the answer . I need to implement exactly the first type - Kolya Vantukh

As far as I understand, you use Web sockets to send Web Push (if they are, after all, it’s not entirely clear on your question). For this use, for example, pure GCM / APNS, or services that solve the nuances of connecting to GCM / APNS for you, for example:

  1. https://onesignal.com/
  2. https://clevertap.com/
  • I understand that GCM / APNS is used to send notifications to mobile phones, right? - Kolya Vantukh
  • @KolyaVantukh may be on phones, and maybe in the browser - misc
  • did not know, thank you. but what are web sockets bad for? - Kolya Vantukh
  • @KolyaVantukh they are good. But in the browser you do not send notification through them. - misc
  • but can you use some kind of libraries or plugins on js with the help of which you can actually do this? - Kolya Vantukh

Minishlink created https://github.com/web-push-libs/web-push-php package to easily implement push notifications on the PHP backend, he also created a demo based on this package, its javascript is easy to borrow into your project https: //github.com/Minishlink/web-push-php-example .