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

Commit 79655e7

Browse files
committed
v0.5.1
Added method to pass cookies on conenct adjust cookie implementation add cookie example distinguish between handshake failed and unauthorized handshake add extra contributors file add examples for different event data types. ref #158 clean up
2 parents f7d0e6b + 952082d commit 79655e7

13 files changed

+105
-72
lines changed

CONTRIBUTORS.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Contributors
2+
3+
Many thanks to the following people for helping me with this:
4+
5+
- mennopruijssers
6+
- samlown
7+
- DanLite
8+
- bnadim
9+
- kayleg
10+
- psineur
11+
- dgthistle
12+
- paiv
13+
- antonholmquist
14+
- spesholized
15+
- insanehunter
16+
- RevCBH
17+
- elwerene
18+
- MichaelScaria
19+
- beepscore
20+
- progeddog
21+
- bridger
22+
- YannickL
23+
- taiyangc

SocketIO.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIO.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import <Foundation/Foundation.h>
@@ -39,7 +36,8 @@ typedef enum {
3936
SocketIOWebSocketClosed = -4,
4037
SocketIOTransportsNotSupported = -5,
4138
SocketIOHandshakeFailed = -6,
42-
SocketIODataCouldNotBeSend = -7
39+
SocketIODataCouldNotBeSend = -7,
40+
SocketIOUnauthorized = -8
4341
} SocketIOErrorCodes;
4442

4543

@@ -71,6 +69,8 @@ typedef enum {
7169
BOOL _isConnecting;
7270
BOOL _useSecure;
7371

72+
NSArray *_cookies;
73+
7474
NSURLConnection *_handshake;
7575

7676
// heartbeat
@@ -95,6 +95,7 @@ typedef enum {
9595
@property (nonatomic, readonly) NSString *sid;
9696
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
9797
@property (nonatomic) BOOL useSecure;
98+
@property (nonatomic) NSArray *cookies;
9899
@property (nonatomic, readonly) BOOL isConnected, isConnecting;
99100
@property (nonatomic, weak) id<SocketIODelegate> delegate;
100101
@property (nonatomic) BOOL returnAllDataFromAck;

SocketIO.m

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIO.m
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import "SocketIO.h"
@@ -78,7 +75,8 @@ @implementation SocketIO
7875

7976
@synthesize isConnected = _isConnected,
8077
isConnecting = _isConnecting,
81-
useSecure = _useSecure,
78+
useSecure = _useSecure,
79+
cookies = _cookies,
8280
delegate = _delegate,
8381
heartbeatTimeout = _heartbeatTimeout,
8482
returnAllDataFromAck = _returnAllDataFromAck;
@@ -144,10 +142,18 @@ - (void) connectToHost:(NSString *)host
144142
query = nil;
145143

146144
// make a request
147-
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:handshakeUrl]
145+
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:handshakeUrl]
148146
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
149147
timeoutInterval:connectionTimeout];
150148

149+
if (_cookies != nil) {
150+
DEBUGLOG(@"Adding cookie(s): %@", [_cookies description]);
151+
NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:_cookies];
152+
[request setAllHTTPHeaderFields:headers];
153+
}
154+
155+
[request setHTTPShouldHandleCookies:YES];
156+
151157
_handshake = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
152158
[_handshake scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
153159
[_handshake start];
@@ -675,6 +681,8 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
675681
{
676682
NSLog(@"ERROR: handshake failed ... %@", [error localizedDescription]);
677683

684+
int errorCode = [error code] == 403 ? SocketIOUnauthorized : SocketIOHandshakeFailed;
685+
678686
_isConnected = NO;
679687
_isConnecting = NO;
680688

@@ -683,7 +691,7 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
683691
forKey:NSUnderlyingErrorKey] mutableCopy];
684692

685693
NSError *err = [NSError errorWithDomain:SocketIOError
686-
code:SocketIOHandshakeFailed
694+
code:errorCode
687695
userInfo:errorInfo];
688696

689697
[_delegate socketIO:self onError:err];

SocketIOJSONSerialization.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOJSONSerialization.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import <Foundation/Foundation.h>

SocketIOJSONSerialization.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOJSONSerialization.m
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import "SocketIOJSONSerialization.h"

SocketIOPacket.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOPacket.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import <Foundation/Foundation.h>

SocketIOPacket.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOPacket.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import "SocketIOPacket.h"

SocketIOTransport.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOTransport.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import <Foundation/Foundation.h>

SocketIOTransportWebsocket.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOTransportWebsocket.h
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import <Foundation/Foundation.h>

SocketIOTransportWebsocket.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
//
22
// SocketIOTransportWebsocket.m
3-
// v0.5 ARC
3+
// v0.5.1
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
77
// by Fred Potter <[email protected]>
88
//
99
// using
1010
// https://github.com/square/SocketRocket
11-
// https://github.com/stig/json-framework/
1211
//
1312
// reusing some parts of
1413
// /socket.io/socket.io.js
1514
//
1615
// Created by Philipp Kyeck http://beta-interactive.de
1716
//
18-
// Updated by
19-
// samlown https://github.com/samlown
20-
// kayleg https://github.com/kayleg
21-
// taiyangc https://github.com/taiyangc
17+
// With help from
18+
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
2219
//
2320

2421
#import "SocketIOTransportWebsocket.h"

0 commit comments

Comments
 (0)