diff --git a/README.md b/README.md index ef65765..20b9785 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -**The current version of this library does not yet support socket.io v1.0. -So if you want to use socket.io-objc, please fall back to v0.9.x.** +**This fork supports some socket.io v1.0 features, (no binary support yet). Many thanks to francoisTemasys who did most of the heavy lifting; this is a fork of a fork. v0.9.x compatibility is generally maintained. + --- diff --git a/SocketIO.h b/SocketIO.h index 2fbb12e..67ceb23 100755 --- a/SocketIO.h +++ b/SocketIO.h @@ -21,6 +21,7 @@ #import #import "SocketIOTransport.h" +#import "SocketIOPacket.h" @class SocketIO; @class SocketIOPacket; @@ -41,6 +42,7 @@ typedef enum { } SocketIOErrorCodes; + @protocol SocketIODelegate @optional - (void) socketIODidConnect:(SocketIO *)socket; @@ -61,6 +63,8 @@ typedef enum { NSString *_endpoint; NSDictionary *_params; + SocketIOVersion _version; + __weak id _delegate; NSObject *_transport; @@ -75,7 +79,9 @@ typedef enum { // heartbeat NSTimeInterval _heartbeatTimeout; + NSTimeInterval _connectionTimeout; dispatch_source_t _timeout; + dispatch_source_t _heartbeat; NSMutableArray *_queue; diff --git a/SocketIO.m b/SocketIO.m index 61ff67a..6cfc636 100755 --- a/SocketIO.m +++ b/SocketIO.m @@ -37,7 +37,9 @@ #endif static NSString* kResourceName = @"socket.io"; -static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%.0f%@"; +static NSString* kTransportPolling = @"polling"; +static NSString* kTransportWebsocket = @"websocket"; +static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?EIO=2&transport=%@&t=%.0f%@"; static NSString* kForceDisconnectURL = @"%@://%@%@/%@/1/xhr-polling/%@?disconnect"; float const defaultConnectionTimeout = 10.0f; @@ -55,11 +57,10 @@ - (NSArray*) arrayOfCaptureComponentsMatchedByRegex:(NSString*)regex; - (void) setTimeout; - (void) onTimeout; +- (void) sendHeartbeat; - (void) onConnect:(SocketIOPacket *)packet; - (void) onDisconnect:(NSError *)error; - - (void) sendDisconnect; -- (void) sendHearbeat; - (void) send:(SocketIOPacket *)packet; - (NSString *) addAcknowledge:(SocketIOCallback)function; @@ -136,7 +137,9 @@ - (void) connectToHost:(NSString *)host NSString *protocol = _useSecure ? @"https" : @"http"; NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @""; NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000; - NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, time, query]; + NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName,kTransportPolling, time, query]; + //@"%@://%@%@/%@/1/?t=%.0f%@"; + //http:///socket.io/1/?t=