|
@@ -22,15 +22,18 @@ typedef enum {
|
|
|
SR_OPEN = 1,
|
|
|
SR_CLOSING = 2,
|
|
|
SR_CLOSED = 3,
|
|
|
-
|
|
|
} SRReadyState;
|
|
|
|
|
|
@class SRWebSocket;
|
|
|
|
|
|
extern NSString *const SRWebSocketErrorDomain;
|
|
|
|
|
|
+#pragma mark - SRWebSocketDelegate
|
|
|
+
|
|
|
@protocol SRWebSocketDelegate;
|
|
|
|
|
|
+#pragma mark - SRWebSocket
|
|
|
+
|
|
|
@interface SRWebSocket : NSObject <NSStreamDelegate>
|
|
|
|
|
|
@property (nonatomic, assign) id <SRWebSocketDelegate> delegate;
|
|
@@ -39,41 +42,43 @@ extern NSString *const SRWebSocketErrorDomain;
|
|
|
@property (nonatomic, readonly, retain) NSURL *url;
|
|
|
|
|
|
// This returns the negotiated protocol.
|
|
|
-// It will be niluntil after the handshake completes.
|
|
|
+// It will be nil until after the handshake completes.
|
|
|
@property (nonatomic, readonly, copy) NSString *protocol;
|
|
|
|
|
|
-// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol
|
|
|
+// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
|
|
|
- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
|
|
|
- (id)initWithURLRequest:(NSURLRequest *)request;
|
|
|
|
|
|
-// Some helper constructors
|
|
|
+// Some helper constructors.
|
|
|
- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
|
|
|
- (id)initWithURL:(NSURL *)url;
|
|
|
|
|
|
-// Delegage queue will be dispatch_main_queue by default
|
|
|
-// Only can set OperationQeuue or dispatch_queue
|
|
|
+// Delegate queue will be dispatch_main_queue by default.
|
|
|
+// You cannot set both OperationQueue and dispatch_queue.
|
|
|
- (void)setDelegateOperationQueue:(NSOperationQueue*) queue;
|
|
|
- (void)setDelegateDispatchQueue:(dispatch_queue_t) queue;
|
|
|
|
|
|
-// By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes
|
|
|
+// By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes.
|
|
|
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
|
|
|
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
|
|
|
|
|
|
-// SRWebSockets are intended one-time-use only. Open should be called once and only once
|
|
|
+// SRWebSockets are intended for one-time-use only. Open should be called once and only once.
|
|
|
- (void)open;
|
|
|
|
|
|
- (void)close;
|
|
|
- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
|
|
|
|
|
|
-// Send a UTF8 String or Data
|
|
|
+// Send a UTF8 String or Data.
|
|
|
- (void)send:(id)data;
|
|
|
|
|
|
@end
|
|
|
|
|
|
+#pragma mark - SRWebSocketDelegate
|
|
|
+
|
|
|
@protocol SRWebSocketDelegate <NSObject>
|
|
|
|
|
|
-// message will either be an NSString if the server is using text
|
|
|
-// or NSData if the server is using binary
|
|
|
+// message will either be an NSString if the server is using text
|
|
|
+// or NSData if the server is using binary.
|
|
|
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
|
|
|
|
|
|
@optional
|
|
@@ -84,6 +89,7 @@ extern NSString *const SRWebSocketErrorDomain;
|
|
|
|
|
|
@end
|
|
|
|
|
|
+#pragma mark - NSURLRequest (CertificateAdditions)
|
|
|
|
|
|
@interface NSURLRequest (CertificateAdditions)
|
|
|
|
|
@@ -91,6 +97,7 @@ extern NSString *const SRWebSocketErrorDomain;
|
|
|
|
|
|
@end
|
|
|
|
|
|
+#pragma mark - NSMutableURLRequest (CertificateAdditions)
|
|
|
|
|
|
@interface NSMutableURLRequest (CertificateAdditions)
|
|
|
|
|
@@ -98,6 +105,8 @@ extern NSString *const SRWebSocketErrorDomain;
|
|
|
|
|
|
@end
|
|
|
|
|
|
+#pragma mark - NSRunLoop (SRWebSocket)
|
|
|
+
|
|
|
@interface NSRunLoop (SRWebSocket)
|
|
|
|
|
|
+ (NSRunLoop *)SR_networkRunLoop;
|