pkyeck / socket.IO-objc

socket.io v0.7.2 — 0.9.x for iOS and OS X
MIT License
1.97k stars 441 forks source link

Fix namespace to use the same socket connection with multiple namespaces. #198

Open jbaez opened 10 years ago

jbaez commented 10 years ago

The current namespace implementation was not ideal, it would create a new socket connection for each namespace. In this PR the namespace was removed from SocketIO class. To share the same socket connection with multiple namespaces the SocketIONamespace class can be used instead.

SocketIONamespace *socketNS  = [SocketIONamespace namespaceWithEndpoint:@"/endpoint" delegate:self];

Basically SocketIONamespace creates a SocketIO singleton which is reused by all SocketIONamespace instances. SocketIONamespace instances register themselves as a delegate of SocketIO. SocketIO will send events/messages only to the matching namespace SocketIONamespace instance.

pd: SocketIO has an array of weak pointers for the namespaces delegates implemented with a NSPointerArray, which is available on iOS 6 and later.