@@ -635,56 +635,57 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
635
635
636
636
// check each returned value (thanks for the input https://github.com/taiyangc)
637
637
BOOL connectionFailed = false ;
638
+ NSError * error;
638
639
639
640
_sid = [data objectAtIndex: 0 ];
640
641
if ([_sid length ] < 1 || [data count ] < 4 ) {
641
642
// did not receive valid data, possibly missing a useSecure?
642
643
connectionFailed = true ;
643
644
}
644
-
645
- // check SID
646
- DEBUGLOG (@" sid: %@ " , _sid);
647
- NSString *regex = @" [^0-9]" ;
648
- NSPredicate *regexTest = [NSPredicate predicateWithFormat: @" SELF MATCHES %@" , regex];
649
- if ([_sid rangeOfString: @" error" ].location != NSNotFound || [regexTest evaluateWithObject: _sid]) {
650
- [self connectToHost: _host onPort: _port withParams: _params withNamespace: _endpoint];
651
- return ;
652
- }
653
-
654
- // check heartbeat timeout
655
- _heartbeatTimeout = [[data objectAtIndex: 1 ] floatValue ];
656
- if (_heartbeatTimeout == 0.0 ) {
657
- // couldn't find float value -> fail
658
- connectionFailed = true ;
659
- }
660
- else {
661
- // add small buffer of 7sec (magic xD)
662
- _heartbeatTimeout += 7.0 ;
663
- }
664
- DEBUGLOG (@" heartbeatTimeout: %f " , _heartbeatTimeout);
665
-
666
- // index 2 => connection timeout
667
-
668
- // get transports
669
- NSString *t = [data objectAtIndex: 3 ];
670
- NSArray *transports = [t componentsSeparatedByString: @" ," ];
671
- DEBUGLOG (@" transports: %@ " , transports);
672
-
673
- NSError * error;
674
- if ([transports indexOfObject: @" websocket" ] != NSNotFound ) {
675
- DEBUGLOG (@" websocket supported -> using it now" );
676
- _transport = [[SocketIOTransportWebsocket alloc ] initWithDelegate: self ];
677
- }
678
- else if ([transports indexOfObject: @" xhr-polling" ] != NSNotFound ) {
679
- DEBUGLOG (@" xhr polling supported -> using it now" );
680
- _transport = [[SocketIOTransportXHR alloc ] initWithDelegate: self ];
681
- }
682
645
else {
683
- DEBUGLOG (@" no transport found that is supported :( -> fail" );
684
- connectionFailed = true ;
685
- error = [NSError errorWithDomain: SocketIOError
686
- code: SocketIOTransportsNotSupported
687
- userInfo: nil ];
646
+ // check SID
647
+ DEBUGLOG (@" sid: %@ " , _sid);
648
+ NSString *regex = @" [^0-9]" ;
649
+ NSPredicate *regexTest = [NSPredicate predicateWithFormat: @" SELF MATCHES %@" , regex];
650
+ if ([_sid rangeOfString: @" error" ].location != NSNotFound || [regexTest evaluateWithObject: _sid]) {
651
+ [self connectToHost: _host onPort: _port withParams: _params withNamespace: _endpoint];
652
+ return ;
653
+ }
654
+
655
+ // check heartbeat timeout
656
+ _heartbeatTimeout = [[data objectAtIndex: 1 ] floatValue ];
657
+ if (_heartbeatTimeout == 0.0 ) {
658
+ // couldn't find float value -> fail
659
+ connectionFailed = true ;
660
+ }
661
+ else {
662
+ // add small buffer of 7sec (magic xD)
663
+ _heartbeatTimeout += 7.0 ;
664
+ }
665
+ DEBUGLOG (@" heartbeatTimeout: %f " , _heartbeatTimeout);
666
+
667
+ // index 2 => connection timeout
668
+
669
+ // get transports
670
+ NSString *t = [data objectAtIndex: 3 ];
671
+ NSArray *transports = [t componentsSeparatedByString: @" ," ];
672
+ DEBUGLOG (@" transports: %@ " , transports);
673
+
674
+ if ([transports indexOfObject: @" websocket" ] != NSNotFound ) {
675
+ DEBUGLOG (@" websocket supported -> using it now" );
676
+ _transport = [[SocketIOTransportWebsocket alloc ] initWithDelegate: self ];
677
+ }
678
+ else if ([transports indexOfObject: @" xhr-polling" ] != NSNotFound ) {
679
+ DEBUGLOG (@" xhr polling supported -> using it now" );
680
+ _transport = [[SocketIOTransportXHR alloc ] initWithDelegate: self ];
681
+ }
682
+ else {
683
+ DEBUGLOG (@" no transport found that is supported :( -> fail" );
684
+ connectionFailed = true ;
685
+ error = [NSError errorWithDomain: SocketIOError
686
+ code: SocketIOTransportsNotSupported
687
+ userInfo: nil ];
688
+ }
688
689
}
689
690
690
691
// if connection didn't return the values we need -> fail
0 commit comments