forked from pkyeck/socket.IO-objc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed socketIOpacket from socketIO and added seperate class
- Loading branch information
Showing
7 changed files
with
172 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters