forked from pkyeck/socket.IO-objc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketIO.h
More file actions
executable file
·130 lines (106 loc) · 3.86 KB
/
Copy pathSocketIO.h
File metadata and controls
executable file
·130 lines (106 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// SocketIO.h
// v0.22 ARC
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <fpotter@pieceable.com>
//
// 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
//
#import <Foundation/Foundation.h>
@class SRWebSocket;
@class SocketIO;
@class SocketIOPacket;
typedef void(^SocketIOCallback)(id argsData);
extern NSString* const SocketIOError;
typedef enum {
SocketIOServerRespondedWithInvalidConnectionData = -1
} SocketIOErrorCodes;
@protocol SocketIODelegate <NSObject>
@optional
- (void) socketIODidConnect:(SocketIO *)socket;
- (void) socketIODidDisconnect:(SocketIO *)socket;
- (void) socketIO:(SocketIO *)socket didReceiveMessage:(SocketIOPacket *)packet;
- (void) socketIO:(SocketIO *)socket didReceiveJSON:(SocketIOPacket *)packet;
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet;
- (void) socketIO:(SocketIO *)socket didSendMessage:(SocketIOPacket *)packet;
- (void) socketIOHandshakeFailed:(SocketIO *)socket;
- (void) socketIO:(SocketIO *)socket failedToConnectWithError:(NSError *)error;
@end
@interface SocketIO : NSObject <NSURLConnectionDelegate>
{
NSString *_host;
NSInteger _port;
NSString *_sid;
NSString *_endpoint;
NSDictionary *_params;
__unsafe_unretained id<SocketIODelegate> _delegate;
SRWebSocket *_webSocket;
BOOL _isConnected;
BOOL _isConnecting;
BOOL _useSecure;
// heartbeat
NSTimeInterval _heartbeatTimeout;
NSTimer *_timeout;
NSMutableArray *_queue;
// acknowledge
NSMutableDictionary *_acks;
NSInteger _ackCount;
// http request
NSMutableData * _httpRequestData;
}
@property (nonatomic, readonly) BOOL isConnected, isConnecting;
@property (nonatomic) BOOL useSecure;
@property (nonatomic, unsafe_unretained) id<SocketIODelegate> delegate;
@property (nonatomic, copy) NSURLRequest *templateRequest;
- (id) initWithDelegate:(id<SocketIODelegate>)delegate;
// use request as a template. Request object may contain cookies and other header fields that may be required for load balancers.
- (void) connectWithRequest:(NSURLRequest *)request;
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port;
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params;
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint;
- (void) disconnect;
- (void) sendMessage:(NSString *)data;
- (void) sendMessage:(NSString *)data withAcknowledge:(SocketIOCallback)function;
- (void) sendJSON:(NSDictionary *)data;
- (void) sendJSON:(NSDictionary *)data withAcknowledge:(SocketIOCallback)function;
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)data;
- (void) sendEvent:(NSString *)eventName withData:(NSDictionary *)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