Closed anemol closed 6 years ago
There is a test for the room feature (https://github.com/Lesterpig/sockpress/blob/master/test/scripts/http.js#L89). However, there may be a bug with the namespace system.
Can you try replacing app.io.route("/","ready", function( socket,version)
with app.io.route("ready", function( socket,version)
?
Alternatively, it may be a misuse of the ready
event. You can also try to change the event name.
If nothing work, I'll investigate.
I applied the modifications but no change.
Finally, i found the source of my problem. To authenticate users, i check the validity of a simple token (given by the authoritative webserver) and i initialize a variable socket.id=token I renamed to "myId" instead "id" and now, it works
Anyway, thanks for your answer. :)
I used this code to test:
function joinRoom(socket, room) {
socket.join(room);
socket.broadcast.to(room).emit('room joined', 1); //should not be sent
socket.emit('room joined', 2); //should be sent
app.io.to(room).emit('room joined', 3); //should be sent
}
I realised that if had a route in a namespace context the rooms wouldn't work.
app.io.route('/product', ioRoute);
only receives 2 from joinRoom test function.
When using:
app.io.route('/', ioRoute);
i receive 2 and 3 from joinRoom test function.
So my question is, are the rooms segmented by namespace?
Can someone help please thanks
Can you share the contents of ioRoute & where you are calling joinRoom from and what values are being passed for room (is it '/' & '/product')?
I'll look into the code now as it has been a few years.. I'd suggest quickly logging the room and socket values in the joinRoom function to make sure it is passing the same values when it's mounted on the two different routes. From a first glance I can't see why the route namespaces would affect your custom room joining.
Yup it seems so :/
"Rooms Within each namespace, you can also define arbitrary channels that sockets can join and leave."
https://socket.io/docs/rooms-and-namespaces/
my bad ;)
Have you resolved your issue? One thought is to check your client side connection, and that you're setting the correct namespace to connect to on the server.
I was able to get it to work by providing the namespace where there room is located.
app.io.of('/namespace').to('room').emit(....
But according to the socketio documentation (rooms are inside namespaces), so this is not a bug, i believe
I have 2 servers who use sockpress
I use Nginx as front proxy.
For the main website, i can use room without problem (join, broadcast to room)
For the game server, rooms don't work.
The main website provides the HTML/javacript and then, the javascript connects to the game server (socketio).
It works well since a while. But, recently, i wanted to use the room feature and i realized that it didn't work. There is no error.
The debug message is never received on the client side.
Any idea?