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

Commit f7d0e6b

Browse files
committed
v0.5
update SocketRocket submodule update readme to reflect the recent changes finally remove deprecated delegate methods Make transports dynamic loadable (based on available classes) Removed SBJson & JSONKit dependencies Debugging should only happen if it is build for debugging (DEBUG is defined if compiled by XCODE for debugging/not release)
2 parents d3fb9de + e639c7a commit f7d0e6b

16 files changed

+40
-204
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "submodules/json-framework"]
2-
path = submodules/json-framework
3-
url = https://github.com/stig/json-framework.git
41
[submodule "submodules/socket-rocket"]
52
path = submodules/socket-rocket
63
url = https://github.com/square/SocketRocket.git

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5 (2014-02-21)
2+
3+
- finally remove deprecated delegate methods
4+
- remove external JSON frameworks
5+
16
## 0.4.1 (2013-11-18)
27

38
- fix unix timecode bug in handshake url. close #118.

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
* [SocketRocket](https://github.com/square/SocketRocket)
88
Look [here](https://github.com/square/SocketRocket#installing-ios) for further instructions how to use/install SocketRocket.
99

10-
JSON serialization can be provided by SBJson (json-framework), JSONKit or by Foundation in OS X 10.7/iOS 5.0. These are selected at runtime and introduce no source-level dependencies.
11-
* [json-framework](https://github.com/stig/json-framework/) (optional)
12-
* [JSONKit](https://github.com/johnezang/JSONKit/) (optional)
1310

1411
## Requirements
1512

1613
As of version 0.4, this library requires at least OS X 10.7 or iOS 5.0.
14+
Because of this, we were able to remove the external JSON frameworks in v0.5 and only rely on iOS' own `NSJSONSerialization`.
15+
1716

1817
## Usage
1918

@@ -80,7 +79,6 @@ All delegate methods are optional - you could implement the following
8079
8180
``` objective-c
8281
- (void) socketIODidConnect:(SocketIO *)socket;
83-
- (void) socketIODidDisconnect:(SocketIO *)socket; // deprecated
8482
- (void) socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error;
8583
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet;
8684
- (void) socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet;
@@ -89,14 +87,6 @@ All delegate methods are optional - you could implement the following
8987
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error;
9088
```
9189

92-
These two callbacks are deprecated - please don't use them anymore - they will
93-
be removed in upcoming releases:
94-
95-
``` objective-c
96-
- (void) socketIOHandshakeFailed:(SocketIO *)socket;
97-
- (void) socketIO:(SocketIO *)socket failedToConnectWithError:(NSError *)error;
98-
```
99-
10090
To process an incoming `message` or `event` just
10191

10292
``` objective-c

SocketIO.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIO.h
3-
// v0.4.1 ARC
3+
// v0.5 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -52,10 +52,6 @@ typedef enum {
5252
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet;
5353
- (void) socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet;
5454
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error;
55-
56-
// TODO: deprecated -> to be removed
57-
- (void) socketIO:(SocketIO *)socket failedToConnectWithError:(NSError *)error __attribute__((deprecated));
58-
- (void) socketIOHandshakeFailed:(SocketIO *)socket __attribute__((deprecated));
5955
@end
6056

6157

SocketIO.m

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIO.m
3-
// v0.4.1 ARC
3+
// v0.5 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -25,11 +25,13 @@
2525
#import "SocketIOPacket.h"
2626
#import "SocketIOJSONSerialization.h"
2727

28-
#import "SocketIOTransportWebsocket.h"
29-
#import "SocketIOTransportXHR.h"
30-
28+
#ifdef DEBUG
3129
#define DEBUG_LOGS 1
3230
#define DEBUG_CERTIFICATE 1
31+
#else
32+
#define DEBUG_LOGS 0
33+
#define DEBUG_CERTIFICATE 0
34+
#endif
3335

3436
#if DEBUG_LOGS
3537
#define DEBUGLOG(...) NSLog(__VA_ARGS__)
@@ -686,13 +688,6 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
686688

687689
[_delegate socketIO:self onError:err];
688690
}
689-
// TODO: deprecated - to be removed
690-
else if ([_delegate respondsToSelector:@selector(socketIOHandshakeFailed:)]) {
691-
#pragma clang diagnostic push
692-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
693-
[_delegate socketIOHandshakeFailed:self];
694-
#pragma clang diagnostic pop
695-
}
696691
}
697692

698693
- (void) connectionDidFinishLoading:(NSURLConnection *)connection
@@ -741,13 +736,23 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
741736
NSArray *transports = [t componentsSeparatedByString:@","];
742737
DEBUGLOG(@"transports: %@", transports);
743738

744-
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) {
745750
DEBUGLOG(@"websocket supported -> using it now");
746-
_transport = [[SocketIOTransportWebsocket alloc] initWithDelegate:self];
751+
_transport = [[webSocketTransportClass alloc] initWithDelegate:self];
747752
}
748-
else if ([transports indexOfObject:@"xhr-polling"] != NSNotFound) {
753+
else if (xhrTransportClass != nil && [transports indexOfObject:@"xhr-polling"] != NSNotFound) {
749754
DEBUGLOG(@"xhr polling supported -> using it now");
750-
_transport = [[SocketIOTransportXHR alloc] initWithDelegate:self];
755+
_transport = [[xhrTransportClass alloc] initWithDelegate:self];
751756
}
752757
else {
753758
DEBUGLOG(@"no transport found that is supported :( -> fail");
@@ -770,13 +775,6 @@ - (void) connectionDidFinishLoading:(NSURLConnection *)connection
770775
if ([_delegate respondsToSelector:@selector(socketIO:onError:)]) {
771776
[_delegate socketIO:self onError:error];
772777
}
773-
// TODO: deprecated - to be removed
774-
else if ([_delegate respondsToSelector:@selector(socketIO:failedToConnectWithError:)]) {
775-
#pragma clang diagnostic push
776-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
777-
[_delegate socketIO:self failedToConnectWithError:error];
778-
#pragma clang diagnostic pop
779-
}
780778

781779
// make sure to do call all cleanup code
782780
[self onDisconnect:error];

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.1 ARC
3+
// v0.5 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOJSONSerialization.m

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// SocketIOJSONSerialization.m
3-
// v0.4.1 ARC
3+
// v0.5 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
@@ -23,93 +23,15 @@
2323

2424
#import "SocketIOJSONSerialization.h"
2525

26-
extern NSString * const SocketIOException;
27-
28-
// covers the methods in SBJson and JSONKit
29-
@interface NSObject (SocketIOJSONSerialization)
30-
31-
// used by both JSONKit and SBJson
32-
- (id) objectWithData:(NSData *)data;
33-
34-
// Use by JSONKit serialization
35-
- (NSString *) JSONString;
36-
- (id) decoder;
37-
38-
// Used by SBJsonWriter
39-
- (NSString *) stringWithObject:(id)object;
40-
41-
@end
42-
4326
@implementation SocketIOJSONSerialization
4427

4528
+ (id) objectFromJSONData:(NSData *)data error:(NSError **)error {
46-
Class serializer;
47-
48-
// try SBJson first
49-
serializer = NSClassFromString(@"SBJsonParser");
50-
if (serializer) {
51-
id parser;
52-
id object;
53-
54-
parser = [[serializer alloc] init];
55-
object = [parser objectWithData:data];
56-
57-
return object;
58-
}
59-
60-
// try Foundation's JSON coder, available in OS X 10.7/iOS 5.0
61-
serializer = NSClassFromString(@"NSJSONSerialization");
62-
if (serializer) {
63-
return [serializer JSONObjectWithData:data options:0 error:error];
64-
}
65-
66-
// lastly, try JSONKit
67-
serializer = NSClassFromString(@"JSONDecoder");
68-
if (serializer) {
69-
return [[serializer decoder] objectWithData:data];
70-
}
71-
72-
// unable to find a suitable JSON deseralizer
73-
[NSException raise:SocketIOException format:@"socket.IO-objc requires SBJson, JSONKit or an OS that has NSJSONSerialization."];
74-
75-
return nil;
29+
return [NSJSONSerialization JSONObjectWithData:data options:0 error:error];
7630
}
7731

7832
+ (NSString *) JSONStringFromObject:(id)object error:(NSError **)error {
79-
Class serializer;
80-
NSString *jsonString;
81-
82-
jsonString = nil;
83-
serializer = NSClassFromString(@"SBJsonWriter");
84-
if (serializer) {
85-
id writer;
86-
87-
writer = [[serializer alloc] init];
88-
jsonString = [writer stringWithObject:object];
89-
90-
return jsonString;
91-
}
92-
93-
serializer = NSClassFromString(@"NSJSONSerialization");
94-
if (serializer) {
95-
NSData *data;
96-
97-
data = [serializer dataWithJSONObject:object options:0 error:error];
98-
99-
jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
100-
101-
return jsonString;
102-
}
103-
104-
// lastly, try JSONKit
105-
if ([object respondsToSelector:@selector(JSONString)]) {
106-
return [object JSONString];
107-
}
108-
109-
// unable to find a suitable JSON seralizer
110-
[NSException raise:SocketIOException format:@"socket.IO-objc requires SBJson, JSONKit or an OS that has NSJSONSerialization."];
111-
112-
return nil;
33+
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:0 error:error];
34+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
11335
}
11436

11537
@end

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.1 ARC
3+
// v0.5 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.1 ARC
3+
// v0.5 ARC
44
//
55
// based on
66
// socketio-cocoa https://github.com/fpotter/socketio-cocoa

SocketIOTransport.h

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

0 commit comments

Comments
 (0)