forked from fpotter/socketio-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocketIoClient.h
105 lines (79 loc) · 3.14 KB
/
SocketIoClient.h
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
//
// SocketIoClient.h
// SocketIoCocoa
//
// Created by Fred Potter on 11/11/10.
// Copyright 2010 Fred Potter. All rights reserved.
//
#import <Foundation/Foundation.h>
@class WebSocket;
@protocol SocketIoClientDelegate;
@interface SocketIoClient : NSObject {
NSString *_host;
NSString *_resourcePath;
NSInteger _port;
BOOL _isSecure;
WebSocket *_webSocket;
NSTimeInterval _connectTimeout;
BOOL _tryAgainOnConnectTimeout;
BOOL _tryAgainOnHeartbeatTimeout;
NSTimeInterval _heartbeatTimeout;
NSTimer *_timeout;
BOOL _isConnected;
BOOL _isConnecting;
NSString *_sessionId;
id<SocketIoClientDelegate> _delegate;
// Selectors
SEL _didStartSelector;
SEL _didDisconnectSelector;
SEL _didReceiveMessageSelector;
SEL _didSendMessageSelector;
SEL _didFailSelector;
NSMutableArray *_queue;
}
@property (nonatomic, readonly) BOOL isSecure;
@property (nonatomic, retain) NSString *sessionId;
@property (nonatomic, readonly) BOOL isConnected;
@property (nonatomic, readonly) BOOL isConnecting;
@property (nonatomic, assign) id<SocketIoClientDelegate> delegate;
@property (nonatomic, assign) NSTimeInterval connectTimeout;
@property (nonatomic, assign) BOOL tryAgainOnConnectTimeout;
@property (nonatomic, assign) BOOL tryAgainOnHeartbeatTimeout;
@property (nonatomic, assign) NSTimeInterval heartbeatTimeout;
// Selectors
@property (assign) SEL didConnectSelector;
@property (assign) SEL didDisconnectSelector;
@property (assign) SEL didReceiveMessageSelector;
@property (assign) SEL didSendMessageSelector;
@property (assign) SEL didFailSelector;
- (id)initWithHost:(NSString *)host resource:(NSString *)resourcePath port:(int)port;
- (id)initWithSecureHost:(NSString *)host resource:(NSString *)resourcePath port:(int)port;
- (void)connect;
- (void)disconnect;
/**
* Rather than coupling this with any specific JSON library, you always
* pass in a string (either _the_ string, or the the JSON-encoded version
* of your object), and indicate whether or not you're passing a JSON object.
*/
- (void)send:(NSString *)data isJSON:(BOOL)isJSON;
/**
* Adds the NSDictionary representation of a message to the offline queue.
* This allows subclass implementations to have more granular control over what
* is happening to their writes that happen without a connection instead of
* only keeping an in memory copy that gets erased on connection. This also allows
* messages to be queued directly into an offline data structure.
*/
- (void)queueOfflineMessage:(NSDictionary *)message;
@end
@protocol SocketIoClientDelegate <NSObject>
/**
* Message is always returned as a string, even when the message was meant to come
* in as a JSON object. Decoding the JSON is left as an exercise for the receiver.
*/
- (void)socketIoClient:(SocketIoClient *)client didReceiveMessage:(NSString *)message isJSON:(BOOL)isJSON;
- (void)socketIoClientDidConnect:(SocketIoClient *)client;
- (void)socketIoClientDidDisconnect:(SocketIoClient *)client;
@optional
- (void)socketIoClient:(SocketIoClient *)client didSendMessage:(NSString *)message isJSON:(BOOL)isJSON;
- (void)socketIoClient:(SocketIoClient *)client didFailWithError:(NSError *)error;
@end