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

Commit bf5781c

Browse files
committed
Merge commit '52940c272d08e7a9ad8c52ff7553a7722e813f86' into develop. close #134.
# By Menno Pruijssers # Via Menno Pruijssers * commit '52940c272d08e7a9ad8c52ff7553a7722e813f86': Make transports dynamic loadable (based on available classes) Conflicts: SocketIO.m
2 parents 9fa27e3 + 52940c2 commit bf5781c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

SocketIO.m

Lines changed: 14 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
#ifdef DEBUG
3229
#define DEBUG_LOGS 1
3330
#define DEBUG_CERTIFICATE 1
@@ -739,13 +736,23 @@ - (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+
if (webSocketTransportClass != nil && [transports indexOfObject:@"websocket"] != NSNotFound) {
743750
DEBUGLOG(@"websocket supported -> using it now");
744-
_transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
751+
_transport = [[webSocketTransportClass alloc] initWithDelegate:self];
745752
}
746-
else if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
753+
else if (xhrTransportClass != nil && [transports indexOfObject:@"xhr-polling"] != NSNotFound) {
747754
DEBUGLOG(@"xhr polling supported -> using it now");
748-
_transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
755+
_transport = [[xhrTransportClass alloc] initWithDelegate:self];
749756
}
750757
else {
751758
DEBUGLOG(@"no transport found that is supported :( -> fail");

0 commit comments

Comments
 (0)