Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Framework added #160

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Products/SocketIO.framework/Headers
1 change: 1 addition & 0 deletions Products/SocketIO.framework/Resources
1 change: 1 addition & 0 deletions Products/SocketIO.framework/SocketIO
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Copyright 2012 Square Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>


@interface NSData (SRB64Additions)

- (NSString *)SR_stringByBase64Encoding;

@end
114 changes: 114 additions & 0 deletions Products/SocketIO.framework/Versions/A/Headers/SRWebSocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// Copyright 2012 Square Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>
#import <Security/SecCertificate.h>

typedef enum {
SR_CONNECTING = 0,
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;

@property (nonatomic, readonly) SRReadyState readyState;
@property (nonatomic, readonly, retain) NSURL *url;

// This returns the negotiated protocol.
// 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.
- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
- (id)initWithURLRequest:(NSURLRequest *)request;

// Some helper constructors.
- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
- (id)initWithURL:(NSURL *)url;

// 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.
- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;

// 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.
- (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.
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;

@optional

- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;

@end

#pragma mark - NSURLRequest (CertificateAdditions)

@interface NSURLRequest (CertificateAdditions)

@property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates;

@end

#pragma mark - NSMutableURLRequest (CertificateAdditions)

@interface NSMutableURLRequest (CertificateAdditions)

@property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates;

@end

#pragma mark - NSRunLoop (SRWebSocket)

@interface NSRunLoop (SRWebSocket)

+ (NSRunLoop *)SR_networkRunLoop;

@end
121 changes: 121 additions & 0 deletions Products/SocketIO.framework/Versions/A/Headers/SocketIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// SocketIO.h
// v0.5.1
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// With help from
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
//

#import <Foundation/Foundation.h>
#import "SocketIOTransport.h"

@class SocketIO;
@class SocketIOPacket;

typedef void(^SocketIOCallback)(id argsData);

extern NSString* const SocketIOError;

typedef enum {
SocketIOServerRespondedWithInvalidConnectionData = -1,
SocketIOServerRespondedWithDisconnect = -2,
SocketIOHeartbeatTimeout = -3,
SocketIOWebSocketClosed = -4,
SocketIOTransportsNotSupported = -5,
SocketIOHandshakeFailed = -6,
SocketIODataCouldNotBeSend = -7,
SocketIOUnauthorized = -8
} SocketIOErrorCodes;


@protocol SocketIODelegate <NSObject>
@optional
- (void) socketIODidConnect:(SocketIO *)socket;
- (void) socketIODidDisconnect:(SocketIO *)socket disconnectedWithError:(NSError *)error;
- (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) socketIO:(SocketIO *)socket onError:(NSError *)error;
@end


@interface SocketIO : NSObject <NSURLConnectionDelegate, SocketIOTransportDelegate>
{
NSString *_host;
NSInteger _port;
NSString *_sid;
NSString *_endpoint;
NSDictionary *_params;

__weak id<SocketIODelegate> _delegate;

NSObject <SocketIOTransport> *_transport;

BOOL _isConnected;
BOOL _isConnecting;
BOOL _useSecure;

NSArray *_cookies;

NSURLConnection *_handshake;

// heartbeat
NSTimeInterval _heartbeatTimeout;
dispatch_source_t _timeout;

NSMutableArray *_queue;

// acknowledge
NSMutableDictionary *_acks;
NSInteger _ackCount;

// http request
NSMutableData *_httpRequestData;

// get all arguments from ack? (https://github.com/pkyeck/socket.IO-objc/pull/85)
BOOL _returnAllDataFromAck;
}

@property (nonatomic, readonly) NSString *host;
@property (nonatomic, readonly) NSInteger port;
@property (nonatomic, readonly) NSString *sid;
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
@property (nonatomic) BOOL useSecure;
@property (nonatomic) NSArray *cookies;
@property (nonatomic, readonly) BOOL isConnected, isConnecting;
@property (nonatomic, weak) id<SocketIODelegate> delegate;
@property (nonatomic) BOOL returnAllDataFromAck;

- (id) initWithDelegate:(id<SocketIODelegate>)delegate;
- (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) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withConnectionTimeout: (NSTimeInterval) connectionTimeout;

- (void) disconnect;
- (void) disconnectForced;

- (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:(id)data;
- (void) sendEvent:(NSString *)eventName withData:(id)data andAcknowledge:(SocketIOCallback)function;
- (void) sendAcknowledgement:(NSString*)pId withArgs:(NSArray *)data;

- (void) setResourceName:(NSString *)name;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SocketIOJSONSerialization.h
// v0.5.1
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// With help from
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
//

#import <Foundation/Foundation.h>

@interface SocketIOJSONSerialization : NSObject

+ (id) objectFromJSONData:(NSData *)data error:(NSError **)error;
+ (NSString *) JSONStringFromObject:(id)object error:(NSError **)error;

@end
49 changes: 49 additions & 0 deletions Products/SocketIO.framework/Versions/A/Headers/SocketIOPacket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SocketIOPacket.h
// v0.5.1
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// With help from
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
//

#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
47 changes: 47 additions & 0 deletions Products/SocketIO.framework/Versions/A/Headers/SocketIOTransport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// SocketIOTransport.h
// v0.5.1
//
// based on
// socketio-cocoa https://github.com/fpotter/socketio-cocoa
// by Fred Potter <[email protected]>
//
// using
// https://github.com/square/SocketRocket
//
// reusing some parts of
// /socket.io/socket.io.js
//
// Created by Philipp Kyeck http://beta-interactive.de
//
// With help from
// https://github.com/pkyeck/socket.IO-objc/blob/master/CONTRIBUTORS.md
//

#import <Foundation/Foundation.h>

@protocol SocketIOTransportDelegate <NSObject>

- (void) onData:(id)message;
- (void) onDisconnect:(NSError*)error;
- (void) onError:(NSError*)error;

@property (nonatomic, readonly) NSString *host;
@property (nonatomic, readonly) NSInteger port;
@property (nonatomic, readonly) NSString *sid;
@property (nonatomic, readonly) NSTimeInterval heartbeatTimeout;
@property (nonatomic) BOOL useSecure;

@end

@protocol SocketIOTransport <NSObject>

- (id) initWithDelegate:(id <SocketIOTransportDelegate>)delegate;
- (void) open;
- (void) close;
- (BOOL) isReady;
- (void) send:(NSString *)request;

@property (nonatomic, weak) id <SocketIOTransportDelegate> delegate;

@end
Loading