Skip to content

Commit

Permalink
removed socketIOpacket from socketIO and added seperate class
Browse files Browse the repository at this point in the history
  • Loading branch information
pkyeck committed Dec 18, 2012
1 parent e4729ce commit 050b704
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 118 deletions.
31 changes: 1 addition & 30 deletions SocketIO.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SocketIO.h
// v0.2.5 ARC
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
Expand Down Expand Up @@ -100,33 +100,4 @@ typedef enum {
- (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function;
- (void) sendAcknowledgement:(NSString*)pId withArgs:(NSArray *)data;

@end


@interface SocketIOPacket : NSObject
{
NSString *type;
NSString *pId;
NSString *ack;
NSString *name;
NSString *data;
NSArray *args;
NSString *endpoint;
NSArray *_types;
}

@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) NSString *pId;
@property (nonatomic, copy) NSString *ack;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *data;
@property (nonatomic, copy) NSString *endpoint;
@property (nonatomic, copy) NSArray *args;

- (id) initWithType:(NSString *)packetType;
- (id) initWithTypeIndex:(int)index;
- (id) dataAsJSON;
- (NSNumber *) typeAsNumber;
- (NSString *) typeForIndex:(int)index;

@end
87 changes: 3 additions & 84 deletions SocketIO.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SocketIO.m
// v0.2.5 ARC
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
Expand All @@ -22,6 +22,7 @@
//

#import "SocketIO.h"
#import "SocketIOPacket.h"
#import "SocketIOJSONSerialization.h"

#import "SRWebSocket.h"
Expand Down Expand Up @@ -802,86 +803,4 @@ - (void) dealloc
}


@end


# pragma mark -
# pragma mark SocketIOPacket implementation

@implementation SocketIOPacket

@synthesize type, pId, name, ack, data, args, endpoint;

- (id) init
{
self = [super init];
if (self) {
_types = [NSArray arrayWithObjects: @"disconnect",
@"connect",
@"heartbeat",
@"message",
@"json",
@"event",
@"ack",
@"error",
@"noop",
nil];
}
return self;
}

- (id) initWithType:(NSString *)packetType
{
self = [self init];
if (self) {
self.type = packetType;
}
return self;
}

- (id) initWithTypeIndex:(int)index
{
self = [self init];
if (self) {
self.type = [self typeForIndex:index];
}
return self;
}

- (id) dataAsJSON
{
if (self.data) {
NSData *utf8Data = [self.data dataUsingEncoding:NSUTF8StringEncoding];
return [SocketIOJSONSerialization objectFromJSONData:utf8Data error:nil];
}
else {
return nil;
}
}

- (NSNumber *) typeAsNumber
{
NSUInteger index = [_types indexOfObject:self.type];
NSNumber *num = [NSNumber numberWithUnsignedInteger:index];
return num;
}

- (NSString *) typeForIndex:(int)index
{
return [_types objectAtIndex:index];
}

- (void) dealloc
{
_types = nil;

type = nil;
pId = nil;
name = nil;
ack = nil;
data = nil;
args = nil;
endpoint = nil;
}

@end
@end
5 changes: 3 additions & 2 deletions SocketIOJSONSerialization.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SocketIOJSONSerialization.h
// v0.22 ARC
// SocketIOJSONSerialization
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
Expand All @@ -18,6 +18,7 @@
// Updated by
// samlown https://github.com/samlown
// kayleg https://github.com/kayleg
// taiyangc https://github.com/taiyangc
//

#import <Foundation/Foundation.h>
Expand Down
5 changes: 3 additions & 2 deletions SocketIOJSONSerialization.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SocketIO.m
// v0.22 ARC
// SocketIOJSONSerialization
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
Expand All @@ -18,6 +18,7 @@
// Updated by
// samlown https://github.com/samlown
// kayleg https://github.com/kayleg
// taiyangc https://github.com/taiyangc
//

#import "SocketIOJSONSerialization.h"
Expand Down
52 changes: 52 additions & 0 deletions SocketIOPacket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SocketIOPacket.h
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
// https://github.com/stig/json-framework/
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// Updated by
// samlown https://github.com/samlown
// kayleg https://github.com/kayleg
// taiyangc https://github.com/taiyangc
//

#import <Foundation/Foundation.h>

@interface SocketIOPacket : NSObject
{
NSString *type;
NSString *pId;
NSString *ack;
NSString *name;
NSString *data;
NSArray *args;
NSString *endpoint;
NSArray *_types;
}

@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) NSString *pId;
@property (nonatomic, copy) NSString *ack;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *data;
@property (nonatomic, copy) NSString *endpoint;
@property (nonatomic, copy) NSArray *args;

- (id) initWithType:(NSString *)packetType;
- (id) initWithTypeIndex:(int)index;
- (id) dataAsJSON;
- (NSNumber *) typeAsNumber;
- (NSString *) typeForIndex:(int)index;

@end
104 changes: 104 additions & 0 deletions SocketIOPacket.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// SocketIOPacket.h
// v0.3.0 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
// https://github.com/stig/json-framework/
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// Updated by
// samlown https://github.com/samlown
// kayleg https://github.com/kayleg
// taiyangc https://github.com/taiyangc
//

#import "SocketIOPacket.h"
#import "SocketIOJSONSerialization.h"

@implementation SocketIOPacket

@synthesize type, pId, name, ack, data, args, endpoint;

- (id) init
{
self = [super init];
if (self) {
_types = [NSArray arrayWithObjects: @"disconnect",
@"connect",
@"heartbeat",
@"message",
@"json",
@"event",
@"ack",
@"error",
@"noop",
nil];
}
return self;
}

- (id) initWithType:(NSString *)packetType
{
self = [self init];
if (self) {
self.type = packetType;
}
return self;
}

- (id) initWithTypeIndex:(int)index
{
self = [self init];
if (self) {
self.type = [self typeForIndex:index];
}
return self;
}

- (id) dataAsJSON
{
if (self.data) {
NSData *utf8Data = [self.data dataUsingEncoding:NSUTF8StringEncoding];
return [SocketIOJSONSerialization objectFromJSONData:utf8Data error:nil];
}
else {
return nil;
}
}

- (NSNumber *) typeAsNumber
{
NSUInteger index = [_types indexOfObject:self.type];
NSNumber *num = [NSNumber numberWithUnsignedInteger:index];
return num;
}

- (NSString *) typeForIndex:(int)index
{
return [_types objectAtIndex:index];
}

- (void) dealloc
{
_types = nil;

type = nil;
pId = nil;
name = nil;
ack = nil;
data = nil;
args = nil;
endpoint = nil;
}

@end

6 changes: 6 additions & 0 deletions SocketTesterARC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
4A4453811589EE9100B44ABB /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 4A44537A1589EE9100B44ABB /* base64.c */; };
4A4453821589EE9100B44ABB /* NSData+SRB64Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A44537D1589EE9100B44ABB /* NSData+SRB64Additions.m */; };
4A4453831589EE9100B44ABB /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4453801589EE9100B44ABB /* SRWebSocket.m */; };
4AD96DF41680853E00D9E42D /* SocketIOPacket.m in Sources */ = {isa = PBXBuildFile; fileRef = 4AD96DF31680853E00D9E42D /* SocketIOPacket.m */; };
4ADCCBA215790D760022990C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ADCCBA115790D760022990C /* UIKit.framework */; };
4ADCCBA415790D760022990C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ADCCBA315790D760022990C /* Foundation.framework */; };
4ADCCBA615790D760022990C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4ADCCBA515790D760022990C /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -74,6 +75,8 @@
4A44537E1589EE9100B44ABB /* SocketRocket-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SocketRocket-Prefix.pch"; path = "submodules/socket-rocket/SocketRocket/SocketRocket-Prefix.pch"; sourceTree = SOURCE_ROOT; };
4A44537F1589EE9100B44ABB /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SRWebSocket.h; path = "submodules/socket-rocket/SocketRocket/SRWebSocket.h"; sourceTree = SOURCE_ROOT; };
4A4453801589EE9100B44ABB /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SRWebSocket.m; path = "submodules/socket-rocket/SocketRocket/SRWebSocket.m"; sourceTree = SOURCE_ROOT; };
4AD96DF21680853E00D9E42D /* SocketIOPacket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SocketIOPacket.h; sourceTree = SOURCE_ROOT; };
4AD96DF31680853E00D9E42D /* SocketIOPacket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SocketIOPacket.m; sourceTree = SOURCE_ROOT; };
4ADCCB9D15790D760022990C /* SocketTesterARC.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SocketTesterARC.app; sourceTree = BUILT_PRODUCTS_DIR; };
4ADCCBA115790D760022990C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
4ADCCBA315790D760022990C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -206,6 +209,8 @@
4ADCCBB615790D760022990C /* ViewController.xib */,
4ADCCBC615790DEC0022990C /* SocketIO.h */,
4ADCCBC715790DEC0022990C /* SocketIO.m */,
4AD96DF21680853E00D9E42D /* SocketIOPacket.h */,
4AD96DF31680853E00D9E42D /* SocketIOPacket.m */,
C9E391A015E2A1B00004693A /* SocketIOJSONSerialization.h */,
C9E391A115E2A1B00004693A /* SocketIOJSONSerialization.m */,
4ADCCBA815790D760022990C /* Supporting Files */,
Expand Down Expand Up @@ -307,6 +312,7 @@
4A4453821589EE9100B44ABB /* NSData+SRB64Additions.m in Sources */,
4A4453831589EE9100B44ABB /* SRWebSocket.m in Sources */,
C9E391A215E2A1B00004693A /* SocketIOJSONSerialization.m in Sources */,
4AD96DF41680853E00D9E42D /* SocketIOPacket.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 050b704

Please sign in to comment.