Answer the question
In order to leave comments, you need to log in
How to implement notifications and messages like in VK?
Hello!
I decided to make real-time notifications on the site and update messages in the dialog.
The site itself is in php, the nodejs server is also running.
In node: express, socket.io, redis, etc.
How was it for me?
Let's say how notifications were implemented?
It's just stupid ajax requests n number of times per minute, because of the large online and users there could be a bunch of tabs, plus they go through the tabs, in general, the database almost constantly received too many connections.
I decided to remake everything on a node with a websocket connection.
I identify the user, create a unique room for him based on his id, and I also put all the user connections in a separate array.
If the broker received some kind of notification, I send all these notifications to the room, for a specific user, if there are a bunch of tabs, then there will be a notification for all open tabs, I want to do it like in VK, if let's say the dialog is open and the window is active, no notifications, we just show a new message, if the dialog is open, but the window is not active, then the notification sound, if the dialog is open, but another page of the same VK is active, then the notification will be on the active tab, how to achieve this?
The problem is that the notification goes to all open tabs and you need to understand if the dialog is open, which tab the person is currently on, etc.
How to implement it?
Answer the question
In order to leave comments, you need to log in
To understand if the user is in a tab: https://stackoverflow.com/a/20922020/7415288
There is a feature in browsers so that the tabs of the same site speak to each other: https://developer.mozilla.org/en-US/ docs/Web/API/B...
almost constantly the database received too many connections
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question