Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions SocketIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ typedef enum {
SocketIOUnauthorized = -8
} SocketIOErrorCodes;

@protocol SocketIOProtocol <NSObject>

- (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 <NSObject>
@optional
Expand All @@ -52,13 +71,29 @@ typedef enum {
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error;
@end

@protocol SocketIONamespaceDelegate <NSObject>

/// 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 <NSURLConnectionDelegate, SocketIOTransportDelegate>
@interface SocketIO : NSObject
<SocketIOProtocol, NSURLConnectionDelegate, SocketIOTransportDelegate>
{
NSString *_host;
NSInteger _port;
NSString *_sid;
NSString *_endpoint;
NSDictionary *_params;

__weak id<SocketIODelegate> _delegate;
Expand Down Expand Up @@ -100,11 +135,12 @@ typedef enum {
@property (nonatomic, weak) id<SocketIODelegate> delegate;
@property (nonatomic) BOOL returnAllDataFromAck;

/// For single delegate i.e. when using a socketIO without namespace
- (id) initWithDelegate:(id<SocketIODelegate>)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;
Expand Down
Loading