Sunday 28 July 2019

How would you join two specific sockets to a chatroom using socket.io

I am using nodejs, in the backend with socket.io. I want to take in multiple sockets and then sort them by username and join the first one in the sort to the last one. An example would be connecting the socket with username that starts with A to Z, B to C and so on.The way I'm doing it now is I am attaching a username to each socket and putting it in an array and then sorting them. However, I cannot get the sockets to join each other when I do a socket.join('room 237') on both sockets. My guess is that when I join the sockets, I am joining the copy of the sockets in the array and not connecting the actual sockets, and I am not sure of what else to do.I even thought of hacky solutions to do it but I couldn't come up with any that were decent. I think there has to be a better way to do this and make it work.Any help is appreciated, thank you!

Submitted July 28, 2019 at 09:21PM by IRULETHISREDDIT

No comments:

Post a Comment