I
I
ikerya2018-10-21 13:18:26
JavaScript
ikerya, 2018-10-21 13:18:26

How to determine the currently viewed posts by the user and send them over WebSocket?

0
downvotes
favorites
There is a site with a list of posts -- regular divs. Let's say there are 1000 posts in the site database, 10 posts are shown on the page, you can load another 10, then another .. and so on until the last post.
I want to make a system of likes, and so that when they like, an event is sent to all users who are viewing this post at the moment.
(but I can’t send information about all posts (1000) to all online visitors (200-500). 200-500 packages will be sent for 1 like. If each user likes at least 5 times? 200 * 1000 * 5 = 1000000 packages for a few seconds? for two hundred visitors? Not the case(
The like event directly interacts with the socket server, and it turns out that when a user likes a post, the socket server is already ready to send an event, but I don’t understand how to determine who should send this event - how to determine the viewed users of that post who was just liked to update their counter???
In general, thoughts are needed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2018-10-21
@inoise

When you open the page, you create a ws connection, and after that you collect post identifiers and send several messages via ws: subscribe: post_id
And on the server, you collect a list of connections that are subscribed to one post. Here is the mailing list for you.
When disconnecting, remove all connection subscriptions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question