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

Commit 52940c2

Browse files
Make transports dynamic loadable (based on available classes)
1 parent 26748e0 commit 52940c2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

SocketIO.m

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
#import "SocketIOPacket.h"
2626
#import "SocketIOJSONSerialization.h"
2727

28-
#import "SocketIOTransportWebsocket.h"
29-
#import "SocketIOTransportXHR.h"
30-
3128
#define DEBUG_LOGS 1
3229
#define DEBUG_CERTIFICATE 1
3330

@@ -739,13 +736,25 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
739736
NSArray *transports = [t componentsSeparatedByString:@","];
740737
DEBUGLOG(@"transports: %@", transports);
741738

742-
if ([transports indexOfObject:@"websocket"] != NSNotFound) {
739+
static Class webSocketTransportClass;
740+
static Class xhrTransportClass;
741+
742+
if(webSocketTransportClass == nil) {
743+
webSocketTransportClass = NSClassFromString(@"SocketIOTransportWebsocket");
744+
}
745+
if(xhrTransportClass == nil) {
746+
xhrTransportClass = NSClassFromString(@"SocketIOTransportXHR");
747+
}
748+
749+
750+
751+
if (webSocketTransportClass != nil && [transports indexOfObject:@"websocket"] != NSNotFound) {
743752
DEBUGLOG(@"websocket supported -> using it now");
744-
_transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
753+
_transport = [[webSocketTransportClass alloc] initWithDelegate:self];
745754
}
746-
else if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
755+
else if (xhrTransportClass != nil && [transports indexOfObject:@"xhr-polling"] != NSNotFound) {
747756
DEBUGLOG(@"xhr polling supported -> using it now");
748-
_transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
757+
_transport = [[xhrTransportClass alloc] initWithDelegate:self];
749758
}
750759
else {
751760
DEBUGLOG(@"no transport found that is supported :( -> fail");

0 commit comments

Comments
 (0)