Open shawn-simon opened 9 years ago
Hi Shawn. It's a straightforward thing. You can create separate factories for each namespace, and initialize respective connections inside of it. Here's an example.
suppose you have two namespaces. /feed and /chat
for /feed namespace
app.factory('feedSocket',feedSocket);
function feedSocket(socketFactory){
var myIoSocket = io.connect('server-base-url' +/feed);
var mySocket = socketFactory({ ioSocket : myIoSocket });
return mySocket;
}
for /chat namespace
app.factory('chatSocket','chatSocket');
function chatSocket(socketFactory){
var myIoSocket = io.connect('server-base-url' + '/chat');
var mySocket = socketFactory({ ioSocket : myIoSocket });
return mySocket;
}
then inside your controllers you can simple inject the required socket factory. Hope it's clear for you.
Thanks, this is really helpful. I did it a different way but will probably switch it to this
Does this make two separate connections? If so, why?
@dolftax Yes it does because it is called from different factories with different namespaces
Is there a way of achieving this with 1 connection?
Couldn't find an example. Thanks!