diff --git a/SocketIO.h b/SocketIO.h index 2fbb12e..f48b973 100755 --- a/SocketIO.h +++ b/SocketIO.h @@ -40,6 +40,25 @@ typedef enum { SocketIOUnauthorized = -8 } SocketIOErrorCodes; +@protocol SocketIOProtocol + +- (void) connectToHost:(NSString *)host onPort:(NSInteger)port; +- (void) connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params; +- (void) connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params + withConnectionTimeout: (NSTimeInterval) connectionTimeout; + +- (void) sendMessage:(NSString *)data; +- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function; +- (void) sendJSON:(NSDictionary *)data; +- (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function; +- (void) sendEvent:(NSString *)eventName withData:(id)data; +- (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function; + +@end @protocol SocketIODelegate @optional @@ -52,13 +71,29 @@ typedef enum { - (void) socketIO:(SocketIO *)socket onError:(NSError *)error; @end +@protocol SocketIONamespaceDelegate + +/// returns endpoint for namespace +- (NSString *)endpoint; + +// Methods from SocketIODelegate protocol but mandatory +- (void) socketIODidConnect:(SocketIO *)socket; +- (void) socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error; +- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet; +- (void) socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet; +- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet; +- (void) socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet; +- (void) socketIO:(SocketIO *)socket onError:(NSError *)error; + +@end + -@interface SocketIO : NSObject +@interface SocketIO : NSObject + { NSString *_host; NSInteger _port; NSString *_sid; - NSString *_endpoint; NSDictionary *_params; __weak id _delegate; @@ -100,11 +135,12 @@ typedef enum { @property (nonatomic, weak) id delegate; @property (nonatomic) BOOL returnAllDataFromAck; +/// For single delegate i.e. when using a socketIO without namespace - (id) initWithDelegate:(id)delegate; + - (void) connectToHost:(NSString *)host onPort:(NSInteger)port; - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params; -- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint; -- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withConnectionTimeout: (NSTimeInterval) connectionTimeout; +- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withConnectionTimeout: (NSTimeInterval) connectionTimeout; - (void) disconnect; - (void) disconnectForced; diff --git a/SocketIO.m b/SocketIO.m index 61ff67a..f8f465b 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -18,7 +18,7 @@ // https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md // -#import "SocketIO.h" +#import "SocketIO_NSInterface.h" #import "SocketIOPacket.h" #import "SocketIOJSONSerialization.h" @@ -48,6 +48,12 @@ # pragma mark - # pragma mark SocketIO's private interface +@interface SocketIO() + +@property (nonatomic, strong) NSPointerArray *namespaceDelegates; + +@end + @interface SocketIO (Private) - (NSArray*) arrayOfCaptureComponentsMatchedByRegex:(NSString*)regex; @@ -81,41 +87,46 @@ @implementation SocketIO heartbeatTimeout = _heartbeatTimeout, returnAllDataFromAck = _returnAllDataFromAck; -- (id) initWithDelegate:(id)delegate +- (id) init { self = [super init]; if (self) { - _delegate = delegate; _queue = [[NSMutableArray alloc] init]; _ackCount = 0; _acks = [[NSMutableDictionary alloc] init]; _returnAllDataFromAck = NO; + _namespaceDelegates = [NSPointerArray weakObjectsPointerArray]; } return self; } -- (void) connectToHost:(NSString *)host onPort:(NSInteger)port +- (id) initWithDelegate:(id)delegate +{ + self = [self init]; + if (self) { + _delegate = delegate; + } + return self; +} + +- (void) addNamespaceDelegate:(id)delegate { - [self connectToHost:host onPort:port withParams:nil withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout]; + [self.namespaceDelegates addPointer:(__bridge void *)(delegate)]; } -- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params +- (void) connectToHost:(NSString *)host onPort:(NSInteger)port { - [self connectToHost:host onPort:port withParams:params withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout]; + [self connectToHost:host onPort:port withParams:nil withConnectionTimeout:defaultConnectionTimeout]; } -- (void) connectToHost:(NSString *)host - onPort:(NSInteger)port - withParams:(NSDictionary *)params - withNamespace:(NSString *)endpoint +- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params { - [self connectToHost:host onPort:port withParams:params withNamespace:endpoint withConnectionTimeout:defaultConnectionTimeout]; + [self connectToHost:host onPort:port withParams:params withConnectionTimeout:defaultConnectionTimeout]; } - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params - withNamespace:(NSString *)endpoint withConnectionTimeout:(NSTimeInterval)connectionTimeout { if (!_isConnected && !_isConnecting) { @@ -124,8 +135,7 @@ - (void) connectToHost:(NSString *)host _host = host; _port = port; _params = params; - _endpoint = [endpoint copy]; - + // create a query parameters string NSMutableString *query = [[NSMutableString alloc] initWithString:@""]; [params enumerateKeysAndObjectsUsingBlock: ^(id key, id value, BOOL *stop) { @@ -206,10 +216,23 @@ - (void) sendMessage:(NSString *)data } - (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function +{ + [self sendMessage:data forNamespace:@"" withAcknowledge:function]; +} + +- (void) sendMessage:(NSString *)data forNamespace:(NSString *)endpoint +{ + [self sendMessage:data forNamespace:endpoint withAcknowledge:nil]; +} + +- (void) sendMessage:(NSString *)data + forNamespace:(NSString *)endpoint + withAcknowledge:(SocketIOCallback)function { SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"message"]; packet.data = data; packet.pId = [self addAcknowledge:function]; + packet.endpoint = endpoint; [self send:packet]; } @@ -219,10 +242,23 @@ - (void) sendJSON:(NSDictionary *)data } - (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function +{ + [self sendJSON:data forNamespace:@"" withAcknowledge:function]; +} + +- (void) sendJSON:(NSDictionary *)data forNamespace:(NSString *)endpoint +{ + [self sendJSON:data forNamespace:endpoint withAcknowledge:nil]; +} + +- (void) sendJSON:(NSDictionary *)data + forNamespace:(NSString *)endpoint + withAcknowledge:(SocketIOCallback)function { SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"json"]; packet.data = [SocketIOJSONSerialization JSONStringFromObject:data error:nil]; packet.pId = [self addAcknowledge:function]; + packet.endpoint = endpoint; [self send:packet]; } @@ -232,6 +268,18 @@ - (void) sendEvent:(NSString *)eventName withData:(id)data } - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function +{ + [self sendEvent:eventName forNamespace:@"" withData:data andAcknowledge:function]; +} + +- (void) sendEvent:(NSString *)eventName forNamespace:(NSString *)endpoint withData:(id)data +{ + [self sendEvent:eventName forNamespace:endpoint withData:data andAcknowledge:nil]; +} + +- (void)sendEvent:(NSString *)eventName + forNamespace:(NSString *)endpoint + withData:(id)data andAcknowledge:(SocketIOCallback)function { NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:eventName forKey:@"name"]; @@ -239,10 +287,12 @@ - (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(Socke if (data != nil) { [dict setObject:[NSArray arrayWithObject:data] forKey:@"args"]; } - + SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"event"]; packet.data = [SocketIOJSONSerialization JSONStringFromObject:dict error:nil]; packet.pId = [self addAcknowledge:function]; + packet.endpoint = endpoint; + if (function) { packet.ack = @"data"; } @@ -274,9 +324,10 @@ - (void) sendDisconnect [self onDisconnect:nil]; } -- (void) sendConnect +- (void) sendConnectForNamespace:(NSString *)endpoint { SocketIOPacket *packet = [[SocketIOPacket alloc] initWithType:@"connect"]; + packet.endpoint = endpoint; [self send:packet]; } @@ -293,6 +344,7 @@ - (void) send:(SocketIOPacket *)packet return; } DEBUGLOG(@"send()"); + NSNumber *type = [packet typeAsNumber]; NSMutableArray *encoded = [NSMutableArray arrayWithObject:type]; @@ -309,7 +361,7 @@ - (void) send:(SocketIOPacket *)packet // Add the end point for the namespace to be used, as long as it is not // an ACK, heartbeat, or disconnect packet if ([type intValue] != 6 && [type intValue] != 2 && [type intValue] != 0) { - [encoded addObject:_endpoint]; + [encoded addObject:packet.endpoint]; } else { [encoded addObject:@""]; @@ -336,6 +388,10 @@ - (void) send:(SocketIOPacket *)packet if ([_delegate respondsToSelector:@selector(socketIO:didSendMessage:)]) { [_delegate socketIO:self didSendMessage:packet]; } + + for (id delegate in _namespaceDelegates) { + [delegate socketIO:self didSendMessage:packet]; + } } } @@ -357,23 +413,28 @@ - (void) onConnect:(SocketIOPacket *)packet _isConnected = YES; - // Send the connected packet so the server knows what it's dealing with. - // Only required when endpoint/namespace is present - if ([_endpoint length] > 0) { - // Make sure the packet we received has an endpoint, otherwise send it again - if (![packet.endpoint isEqualToString:_endpoint]) { - DEBUGLOG(@"onConnect() >> End points do not match, resending connect packet"); - [self sendConnect]; - return; + if ([self.namespaceDelegates count] > 0 && [packet.endpoint length] == 0) { + // Send the connected packet for namespaces + // so the server knows what it's dealing with. + for (id delegate in _namespaceDelegates) { + [self sendConnectForNamespace:[delegate endpoint]]; + } + return; + } else { + // Socket without namespaces + if ([_delegate respondsToSelector:@selector(socketIODidConnect:)]) { + [_delegate socketIODidConnect:self]; } } - + _isConnecting = NO; - - if ([_delegate respondsToSelector:@selector(socketIODidConnect:)]) { - [_delegate socketIODidConnect:self]; + + for (id delegate in _namespaceDelegates) { + if ([packet.endpoint isEqualToString:[delegate endpoint]]) { + [delegate socketIODidConnect:self]; + } } - + // send any queued packets [self doQueue]; @@ -529,6 +590,12 @@ - (void) onData:(NSString *)data if ([_delegate respondsToSelector:@selector(socketIO:didReceiveMessage:)]) { [_delegate socketIO:self didReceiveMessage:packet]; } + for (id delegate in _namespaceDelegates) { + if (![packet.endpoint isEqualToString:[delegate endpoint]]) { + continue; + } + [delegate socketIO:self didReceiveMessage:packet]; + } } break; } @@ -538,6 +605,12 @@ - (void) onData:(NSString *)data if ([_delegate respondsToSelector:@selector(socketIO:didReceiveJSON:)]) { [_delegate socketIO:self didReceiveJSON:packet]; } + for (id delegate in _namespaceDelegates) { + if (![packet.endpoint isEqualToString:[delegate endpoint]]) { + continue; + } + [delegate socketIO:self didReceiveJSON:packet]; + } } break; } @@ -550,6 +623,12 @@ - (void) onData:(NSString *)data if ([_delegate respondsToSelector:@selector(socketIO:didReceiveEvent:)]) { [_delegate socketIO:self didReceiveEvent:packet]; } + for (id delegate in _namespaceDelegates) { + if (![packet.endpoint isEqualToString:[delegate endpoint]]) { + continue; + } + [delegate socketIO:self didReceiveEvent:packet]; + } } break; } @@ -635,6 +714,9 @@ - (void) onDisconnect:(NSError *)error if ([_delegate respondsToSelector:@selector(socketIODidDisconnect:disconnectedWithError:)]) { [_delegate socketIODidDisconnect:self disconnectedWithError:error]; } + for (id delegate in _namespaceDelegates) { + [delegate socketIODidDisconnect:self disconnectedWithError:error]; + } } } @@ -643,6 +725,9 @@ - (void) onError:(NSError *)error if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) { [_delegate socketIO:self onError:error]; } + for (id delegate in _namespaceDelegates) { + [delegate socketIO:self onError:error]; + } } @@ -685,17 +770,21 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er _isConnected = NO; _isConnecting = NO; - + + NSMutableDictionary *errorInfo = [[NSDictionary dictionaryWithObject:error + forKey:NSUnderlyingErrorKey] mutableCopy]; + + NSError *err = [NSError errorWithDomain:SocketIOError + code:errorCode + userInfo:errorInfo]; + if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) { - NSMutableDictionary *errorInfo = [[NSDictionary dictionaryWithObject:error - forKey:NSUnderlyingErrorKey] mutableCopy]; - - NSError *err = [NSError errorWithDomain:SocketIOError - code:errorCode - userInfo:errorInfo]; - [_delegate socketIO:self onError:err]; } + + for (id delegate in _namespaceDelegates) { + [delegate socketIO:self onError:err]; + } } - (void) connectionDidFinishLoading:(NSURLConnection *)connection @@ -721,7 +810,7 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection NSString *regex = @"[^0-9]"; NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; if ([_sid rangeOfString:@"error"].location != NSNotFound || [regexTest evaluateWithObject:_sid]) { - [self connectToHost:_host onPort:_port withParams:_params withNamespace:_endpoint]; + [self connectToHost:_host onPort:_port withParams:_params]; return; } @@ -783,6 +872,10 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) { [_delegate socketIO:self onError:error]; } + + for (id delegate in _namespaceDelegates) { + [delegate socketIO:self onError:error]; + } // make sure to do call all cleanup code [self onDisconnect:error]; @@ -819,7 +912,6 @@ - (void) connection:(NSURLConnection *)connection } #endif - # pragma mark - - (void) dealloc @@ -829,8 +921,7 @@ - (void) dealloc _host = nil; _sid = nil; - _endpoint = nil; - + _transport.delegate = nil; _transport = nil; diff --git a/SocketIONamespace.h b/SocketIONamespace.h new file mode 100644 index 0000000..8163af0 --- /dev/null +++ b/SocketIONamespace.h @@ -0,0 +1,55 @@ +// +// SocketIONamespace.h +// +// Created by jbaez https://github.com/jbaez on 04/07/2014. +// +// + +#import +#import "SocketIO_NSInterface.h" + +@interface SocketIONamespace : NSObject +{ + __weak id _delegate; +} + +/// The namespace enpoint +@property (nonatomic, strong, readonly) NSString *endpoint; + +/// SocketIO delegate for this namespace +@property (nonatomic, weak) id delegate; + +/// Shared socket instance +@property (nonatomic, strong, readonly) SocketIO *socket; + +/// Namespace connection instance ++ (instancetype)namespaceWithEndpoint:(NSString *)endpoint + delegate:(id)delegate; + +/// Namespace connection instance ++ (instancetype)namespaceWithEndpoint:(NSString *)endpoint; + +/// Shared socket used for namespace connections ++ (SocketIO *)sharedSocket; + +#pragma mark - SocketIOProtocol + +- (void)connectToHost:(NSString *)host onPort:(NSInteger)port; +- (void)connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params; +- (void)connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params +withConnectionTimeout:(NSTimeInterval)connectionTimeout; + +- (void)sendMessage:(NSString *)data; +- (void)sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function; +- (void)sendJSON:(NSDictionary *)data; +- (void)sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function; +- (void)sendEvent:(NSString *)eventName withData:(id)data; +- (void)sendEvent:(NSString *)eventName + withData:(id)data + andAcknowledge:(SocketIOCallback)function; + +@end diff --git a/SocketIONamespace.m b/SocketIONamespace.m new file mode 100644 index 0000000..8277e24 --- /dev/null +++ b/SocketIONamespace.m @@ -0,0 +1,214 @@ +// +// SocketIONamespace.m +// +// Created by jbaez https://github.com/jbaez on 04/07/2014. +// +// + +#import "SocketIONamespace.h" +#import "SocketIOPacket.h" + +@interface SocketIONamespace() + +@property (nonatomic, strong) SocketIO *socket; +@property (nonatomic, strong) NSString *endpoint; + +@end + +@implementation SocketIONamespace + +#pragma mark - initializers + ++ (SocketIO *)sharedSocket +{ + static SocketIO *socket; + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + socket = [[SocketIO alloc] init]; + }); + + return socket; +} + ++ (instancetype)namespaceWithEndpoint:(NSString *)endpoint + delegate:(id)delegate +{ + SocketIO *socket = [SocketIONamespace sharedSocket]; + + SocketIONamespace *namespace = [[SocketIONamespace alloc] initWithSocket:socket + namespace:endpoint + delegate:delegate]; + + return namespace; +} + ++ (instancetype)namespaceWithEndpoint:(NSString *)endpoint +{ + SocketIO *socket = [SocketIONamespace sharedSocket]; + + SocketIONamespace *namespace = [[SocketIONamespace alloc] initWithSocket:socket + namespace:endpoint + delegate:nil]; + + return namespace; +} + +/// Private initializer +- (instancetype)initWithSocket:(SocketIO *)socket + namespace:(NSString *)endpoint + delegate:(id)delegate +{ + self = [super init]; + if (self) { + _socket = socket; + _endpoint = endpoint; + _delegate = delegate; + + [_socket addNamespaceDelegate:self]; + } + return self; +} + +#pragma mark - private methods + +- (void)sendConnectPackage +{ + if([self.socket isConnected] && ![self.socket isConnecting]) { + // socket already connected. Send connect package for new namespace + [self.socket sendConnectForNamespace:self.endpoint]; + } +} + +#pragma mark - SocketIOProtocol + +- (void)connectToHost:(NSString *)host onPort:(NSInteger)port +{ + if (![self.socket isConnected] && ![self.socket isConnecting]) { + [self.socket connectToHost:host + onPort:port]; + } else { + // socket already connected. Send connect package for new namespace + [self sendConnectPackage]; + } +} + +- (void)connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params +{ + if (![self.socket isConnected] && ![self.socket isConnecting]) { + [self.socket connectToHost:host + onPort:port + withParams:params]; + } else { + // socket already connected. Send connect package for new namespace + [self sendConnectPackage]; + } +} + +- (void)connectToHost:(NSString *)host + onPort:(NSInteger)port + withParams:(NSDictionary *)params +withConnectionTimeout:(NSTimeInterval)connectionTimeout +{ + if (![self.socket isConnected] && ![self.socket isConnecting]) { + [self.socket connectToHost:host + onPort:port + withParams:params + withConnectionTimeout:connectionTimeout]; + } else { + // socket already connected. Send connect package for new namespace + [self sendConnectPackage]; + } +} + +- (void)sendMessage:(NSString *)data +{ + [self.socket sendMessage:data forNamespace:self.endpoint]; +} + +- (void)sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function +{ + [self.socket sendMessage:data forNamespace:self.endpoint withAcknowledge:function]; +} + +- (void)sendJSON:(NSDictionary *)data +{ + [self.socket sendJSON:data forNamespace:self.endpoint]; +} + +- (void)sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function +{ + [self.socket sendJSON:data forNamespace:self.endpoint withAcknowledge:function]; +} + +- (void)sendEvent:(NSString *)eventName withData:(id)data +{ + [self.socket sendEvent:eventName forNamespace:self.endpoint withData:data]; +} + +- (void)sendEvent:(NSString *)eventName + withData:(id)data + andAcknowledge:(SocketIOCallback)function +{ + [self.socket sendEvent:eventName + forNamespace:self.endpoint + withData:data + andAcknowledge:function]; +} + +#pragma mark - socketIONamespace delegate protocol + +- (void)socketIODidConnect:(SocketIO *)socket +{ + if ([_delegate respondsToSelector:@selector(socketIODidConnect:)]) { + [_delegate socketIODidConnect:socket]; + } +} + +- (void)socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error +{ + if ([_delegate respondsToSelector:@selector(socketIODidDisconnect: + disconnectedWithError:)]) { + [_delegate socketIODidDisconnect:socket + disconnectedWithError:error]; + } +} + +- (void)socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet +{ + if ([_delegate respondsToSelector:@selector(socketIO:didReceiveMessage:)]) { + [_delegate socketIO:socket didReceiveMessage:packet]; + } +} + +- (void)socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet +{ + if ([_delegate respondsToSelector:@selector(socketIO:didReceiveJSON:)]) { + [_delegate socketIO:socket didReceiveJSON:packet]; + } +} + +- (void)socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet +{ + if ([_delegate respondsToSelector:@selector(socketIO:didReceiveEvent:)]) { + [_delegate socketIO:socket didReceiveEvent:packet]; + } +} + +- (void)socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet +{ + if ([_delegate respondsToSelector:@selector(socketIO:didSendMessage:)]) { + [_delegate socketIO:socket didSendMessage:packet]; + } +} + +- (void)socketIO:(SocketIO *)socket onError:(NSError *)error +{ + if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) { + [_delegate socketIO:socket onError:error]; + } +} + +@end diff --git a/SocketIOPacket.m b/SocketIOPacket.m index d5c422b..0e14b80 100644 --- a/SocketIOPacket.m +++ b/SocketIOPacket.m @@ -39,6 +39,8 @@ - (id) init @"error", @"noop", nil]; + + self.endpoint = @""; } return self; } diff --git a/SocketIO_NSInterface.h b/SocketIO_NSInterface.h new file mode 100644 index 0000000..7e0b929 --- /dev/null +++ b/SocketIO_NSInterface.h @@ -0,0 +1,40 @@ +// +// SocketIO_NSInterface.h +// Pods +// +// Created by jbaez on 04/07/2014. +// +// SocketIO Interface used by SocketIONamespace +// + +#import "SocketIO.h" + +@interface SocketIO () + +/// For reusing socket connection with multiple namespaces +- (void)addNamespaceDelegate:(id) delegate; + +- (void)sendMessage:(NSString *)data forNamespace:(NSString *)endpoint; + +- (void)sendMessage:(NSString *)data + forNamespace:(NSString *)endpoint + withAcknowledge:(SocketIOCallback)function; + +- (void)sendJSON:(NSDictionary *)data forNamespace:(NSString *)endpoint; + +- (void)sendJSON:(NSDictionary *)data + forNamespace:(NSString *)endpoint + withAcknowledge:(SocketIOCallback)function; + +- (void)sendEvent:(NSString *)eventName + forNamespace:(NSString *)endpoint + withData:(id)data; + +- (void)sendEvent:(NSString *)eventName + forNamespace:(NSString *)endpoint + withData:(id)data + andAcknowledge:(SocketIOCallback)function; + +- (void)sendConnectForNamespace:(NSString *)endpoint; + +@end