Y
Y
Yeldos Adetbekov2017-07-14 16:44:29
JavaScript
Yeldos Adetbekov, 2017-07-14 16:44:29

What is the best architecture for chat design?

Don't scold me for extra tags, please. Smart and experienced people listening to these tags were the reason))

Hello, this is another question about real-time chat between users. But this time the question is purely theoretical rather than practical. How to organize a messaging structure based on websockets+ajax? As I understand it, websockets is a fairly fast and nimble technology compared to long polling, since it does not need to overload the server with unnecessary pending requests. Correct me if my beliefs are not formed correctly))
I have a Messenger component on the client, it has two blocks:
1) Chat field (This is another Chat component with its own state and with keep-alive) When this component is initialized, a request is made to the REST API. Further, this component renders messages based on the received data. The state inside the component is saved, now there is no need to load them again. When the component is reactivated, the request to the server is not performed.
2) Field or list with the latest correspondence. This is also a separate block and it is also loaded separately via the REST API.
The problem arises when you start to think: "But how to update the data dynamically and concisely?".
I feel that listening to channels (Groups) of all connections with users is very stupid. Imagine that I have 1000 friends and I communicate with everyone, so if I'm not the only one. The django-channels microservice just crap one's pants, but what about django-channels, websocket won't pull this off)))
I came up with the idea to do everything as in the above method, but with a blot on websockets. Listen only to your channel, which is created when connecting to websockets. And when another user sends a message, he looks to see if this channel is open, if yes, then send an object with new data to this group, if not, then there is no point, if there is no listener on the other side, he can receive messages when retrieve data. But is it possible to find out if the channel is open or not?
This method has a problem with managing new messages. So I’m thinking, maybe it’s worth storing all the changed, that is, new objects in the store (vuex), and when switching to the chat, pull the new incoming data into the component, then delete them from the main state.
Can you suggest?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2017-07-14
@dosya97

I didn't understand much from your story. you can do everything quite simply:
The client opens a connection to the server and does the following:
1. sends his messages (if he wrote something) and actions
2. receives the messages that the server sent him. (Addressed to him in a personal, or to the channel / channels that are active with the client at the moment).
The server keeps connections with all active clients. Receiving messages from them - sends them to subscribers.
End.

A
Alexey, 2017-07-14
@Azperin

It seems like the node has become synonymous with chat for a long time. I don’t see communication problems there 1k people, web sockets will definitely pull, where I can’t even imagine the reverse infa.
In general, it's trite to read the documentation https://socket.io/

C
Coder321, 2017-07-14
@Coder321

I think at the start to get a list of all channels and create only one connection. At the same time, send the channel name/ID and message from the server, look at the name/ID on the front and push the message to the desired room. In principle, he said everything the same as Stalker_RED

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question