C
C
CanVeeD2016-05-01 13:40:19
Node.js
CanVeeD, 2016-05-01 13:40:19

Random chat script how?

Hello, I have a question. I wrote a chat with rooms, according to the principle of pogovorisomnoi.ru, a random chat without registration) How to write all this correctly? I wrote a script for connecting the first two users in a queue, but the code has not been finalized, because when the client sends messages to the server, the server does not know to whom it is sent and sends it to the last room. Here is the actual code:

socket.on('getIns', function(){
    
    if(queue.length == 0) queue.push(socket);
    else {
      
      room = "public-"+(room_id++);
      queue[0].join(room); 
      socket.join(room);
      io.sockets.to(room).emit('getIns', room);
      queue = queue.slice(1, queue.length);
    }
    
  });

The client sends the getIns key, the server connects it and warns that we have connected you, everything works, but the server does not know to whom to send messages, who is in which room. How can this be done correctly? Thanks in advance)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question