Answer the question
In order to leave comments, you need to log in
Dynamic namespaces in socket.io
I'm trying to implement dynamic spaces in socket.io, but I'm running into various bugs. There are many questions on the Internet on this issue, but few normal answers. Here is my implementation:
app.get '/:namespace', (req, res) ->
namespace = '/' + req.params.namespace
# Is already created namespace?
namespaceExist = io.sockets.manager.namespaces[namespace]?
# Send responce
res.json yes
return if namespaceExist
# Socket.io
io.of(namespace).on 'connection', (socket) ->
# do something
$.getJSON server, {}, (yes) =>
socket = io.connect server
# do something
Answer the question
In order to leave comments, you need to log in
1) What prevents you from using the rooms ?
2) You can do this:
io.sockets.on('connection', function(socket){
var namespace = '/' + socket.handshake.namespace.toLowerCase();
if (!io.namespaces[namespace]){
io.of(namespace).on('connection', function(socket){
});
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question