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

Commit b753a4a

Browse files
committed
v0.4.1
# By Menno Pruijssers (2) and others fix unix timecode bug in handshake url. close #118. Instantiate errorInfo NSMutableDictionary using mutableCopy as suggested by Elshad. close #125. introduce closed flag to XHR transport. fix #130. Removed nill-checks Changed delegates from unsafe_unretained to weak Fix improper use of NSLocalizedDescriptionKey.
2 parents 26748e0 + 2af028d commit b753a4a

11 files changed

+47
-28
lines changed

SocketIO.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIO.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -67,7 +67,7 @@ typedef enum {
6767
NSString *_endpoint;
6868
NSDictionary *_params;
6969

70-
__unsafe_unretained id<SocketIODelegate> _delegate;
70+
__weak id<SocketIODelegate> _delegate;
7171

7272
NSObject <SocketIOTransport> *_transport;
7373

@@ -100,7 +100,7 @@ typedef enum {
100100
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
101101
@property (nonatomic) BOOL useSecure;
102102
@property (nonatomic, readonly) BOOL isConnected, isConnecting;
103-
@property (nonatomic, unsafe_unretained) id<SocketIODelegate> delegate;
103+
@property (nonatomic, weak) id<SocketIODelegate> delegate;
104104
@property (nonatomic) BOOL returnAllDataFromAck;
105105

106106
- (id) initWithDelegate:(id<SocketIODelegate>)delegate;

SocketIO.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIO.m
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -38,7 +38,7 @@
3838
#endif
3939

4040
static NSString* kResourceName = @"socket.io";
41-
static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%d%@";
41+
static NSString* kHandshakeURL = @"%@://%@%@/%@/1/?t=%.0f%@";
4242
static NSString* kForceDisconnectURL = @"%@://%@%@/%@/1/xhr-polling/%@?disconnect";
4343

4444
float const defaultConnectionTimeout = 10.0f;
@@ -135,7 +135,8 @@ - (void) connectToHost:(NSString *)host
135135
// do handshake via HTTP request
136136
NSString *protocol = _useSecure ? @"https" : @"http";
137137
NSString *port = _port ? [NSString stringWithFormat:@":%d", _port] : @"";
138-
NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, rand(), query];
138+
NSTimeInterval time = [[NSDate date] timeIntervalSince1970] * 1000;
139+
NSString *handshakeUrl = [NSString stringWithFormat:kHandshakeURL, protocol, _host, port, kResourceName, time, query];
139140

140141
DEBUGLOG(@"Connecting to socket with URL: %@", handshakeUrl);
141142
query = nil;
@@ -676,7 +677,8 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
676677
_isConnecting = NO;
677678

678679
if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) {
679-
NSMutableDictionary *errorInfo = [NSDictionary dictionaryWithObject:error forKey:NSLocalizedDescriptionKey];
680+
NSMutableDictionary *errorInfo = [[NSDictionary dictionaryWithObject:error
681+
forKey:NSUnderlyingErrorKey] mutableCopy];
680682

681683
NSError *err = [NSError errorWithDomain:SocketIOError
682684
code:SocketIOHandshakeFailed

SocketIOJSONSerialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOJSONSerialization.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOJSONSerialization.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOJSONSerialization.m
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOPacket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOPacket.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOPacket.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOPacket.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOTransport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOTransport.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -45,6 +45,6 @@
4545
- (BOOL) isReady;
4646
- (void) send:(NSString *)request;
4747

48-
@property (nonatomic, unsafe_unretained) id <SocketIOTransportDelegate> delegate;
48+
@property (nonatomic, weak) id <SocketIOTransportDelegate> delegate;
4949

5050
@end

SocketIOTransportWebsocket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOTransportWebsocket.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -31,6 +31,6 @@
3131
SRWebSocket *_webSocket;
3232
}
3333

34-
@property (nonatomic, unsafe_unretained) id <SocketIOTransportDelegate> delegate;
34+
@property (nonatomic, weak) id <SocketIOTransportDelegate> delegate;
3535

3636
@end

SocketIOTransportWebsocket.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOTransportWebsocket.m
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -99,7 +99,9 @@ - (void) send:(NSString*)request
9999

100100
- (void) webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
101101
{
102-
[delegate onData:message];
102+
if([delegate respondsToSelector:@selector(onData:)]) {
103+
[delegate onData:message];
104+
}
103105
}
104106

105107
- (void) webSocketDidOpen:(SRWebSocket *)webSocket
@@ -111,7 +113,9 @@ - (void) webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error
111113
{
112114
DEBUGLOG(@"Socket failed with error ... %@", [error localizedDescription]);
113115
// Assuming this resulted in a disconnect
114-
[delegate onDisconnect:error];
116+
if([delegate respondsToSelector:@selector(onDisconnect:)]) {
117+
[delegate onDisconnect:error];
118+
}
115119
}
116120

117121
- (void) webSocket:(SRWebSocket *)webSocket
@@ -120,9 +124,11 @@ - (void) webSocket:(SRWebSocket *)webSocket
120124
wasClean:(BOOL)wasClean
121125
{
122126
DEBUGLOG(@"Socket closed. %@", reason);
123-
[delegate onDisconnect:[NSError errorWithDomain:SocketIOError
124-
code:SocketIOWebSocketClosed
125-
userInfo:nil]];
127+
if([delegate respondsToSelector:@selector(onDisconnect:)]) {
128+
[delegate onDisconnect:[NSError errorWithDomain:SocketIOError
129+
code:SocketIOWebSocketClosed
130+
userInfo:nil]];
131+
}
126132
}
127133

128134
@end

SocketIOTransportXHR.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOTransportXHR.h
3-
// v0.4.0.1 ARC
3+
// v0.4.1 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -30,8 +30,10 @@
3030
NSString *_url;
3131
NSMutableData *_data;
3232
NSMutableDictionary *_polls;
33+
BOOL _isClosed;
3334
}
3435

35-
@property (nonatomic, unsafe_unretained) id <SocketIOTransportDelegate> delegate;
36+
@property (nonatomic, weak) id <SocketIOTransportDelegate> delegate;
37+
@property (nonatomic) BOOL isClosed;
3638

3739
@end

0 commit comments

Comments
 (0)