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

Socket transport fallback #186

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
4 changes: 3 additions & 1 deletion SocketIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ typedef enum {

// get all arguments from ack? (https://github.com/pkyeck/socket.IO-objc/pull/85)
BOOL _returnAllDataFromAck;

BOOL _useSocket;
}

@property (nonatomic, readonly) NSString *host;
Expand Down Expand Up @@ -119,4 +121,4 @@ typedef enum {

- (void) setResourceName:(NSString *)name;

@end
@end
7 changes: 5 additions & 2 deletions SocketIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ - (id) initWithDelegate:(id<SocketIODelegate>)delegate
_ackCount = 0;
_acks = [[NSMutableDictionary alloc] init];
_returnAllDataFromAck = NO;
_useSocket = YES;
}
return self;
}
Expand Down Expand Up @@ -630,7 +631,8 @@ - (void) onDisconnect:(NSError *)error
_transport.delegate = nil;
[_transport close];
}

if ([_transport isKindOfClass:NSClassFromString(@"SocketIOTransportWebsocket")] && wasConnecting && !wasConnected)
_useSocket = NO;
if ((wasConnected || wasConnecting)) {
if ([_delegate respondsToSelector:@selector(socketIODidDisconnect:disconnectedWithError:)]) {
[_delegate socketIODidDisconnect:self disconnectedWithError:error];
Expand Down Expand Up @@ -754,13 +756,14 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
xhrTransportClass = NSClassFromString(@"SocketIOTransportXHR");
}

if (webSocketTransportClass != nil && [transports indexOfObject:@"websocket"] != NSNotFound) {
if (webSocketTransportClass != nil && [transports indexOfObject:@"websocket"] != NSNotFound && _useSocket) {
DEBUGLOG(@"websocket supported -> using it now");
_transport = [[webSocketTransportClass alloc] initWithDelegate:self];
}
else if (xhrTransportClass != nil && [transports indexOfObject:@"xhr-polling"] != NSNotFound) {
DEBUGLOG(@"xhr polling supported -> using it now");
_transport = [[xhrTransportClass alloc] initWithDelegate:self];
_useSocket = YES;
}
else {
DEBUGLOG(@"no transport found that is supported :( -> fail");
Expand Down