R
R
Rostislav Ignatenko2017-05-10 19:48:50
JavaScript
Rostislav Ignatenko, 2017-05-10 19:48:50

What is the correct way to pass the chat room number?

Hello. Again a question, on a theoretical example.
There is a chat. Authorized users enter it. Each of them can create their own chat room. The list of rooms is displayed as Nickname-How many_persons-Enter.
As I understand it, when creating a room, in the button ID, assign the nickname of the person who created the room, and then send the ID via JS via sockets, check if there is one in the list of rooms on the server, and then connect the user to the selected room. And the question is, is this approach rational? Or is there some easier way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RaulDuke, 2017-05-10
@RaulDuke

If I understand correctly, this is more a question of the back data structure. And for all the seeming simplicity, the task of chatting with rooms for some backends turns out to be not so simple (for example, for Firebase this is a non-trivial task).
Offhand, I would make a structure like this:

db: {
  users: {
    id: 111,
    name: 'Rostislav',
    room: 8888,
  },
  rooms: {
    id: 8888,
    messages: [...],
    owner: 111,
    public: true
  }
}

When you press the enter button, we give the room id to the server, if it exists, it checks everything that you need to check and gives the owner of the room with messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question