IOS Streaming Browser 1.0
An IOS streaming browser to stream the display to others or to a projector

/Users/willrubel/IOS-Streaming-Browser/IOS-Streaming-Browser/WebSocket.h

Go to the documentation of this file.
00001 #import <Foundation/Foundation.h>
00002 
00003 @class HTTPMessage;
00004 @class GCDAsyncSocket;
00005 
00006 
00007 #define WebSocketDidDieNotification  @"WebSocketDidDie"
00008 
00009 @interface WebSocket : NSObject
00010 {
00011     
00012     /**
00013       websocket queue
00014     **/
00015         dispatch_queue_t websocketQueue; 
00016         
00017     /**
00018        the web socket request
00019     **/
00020         HTTPMessage *request; 
00021 
00022     /**
00023       the socket (i.e. file handle)
00024     **/
00025         GCDAsyncSocket *asyncSocket; 
00026         
00027     /**
00028      
00029     **/
00030         NSData *term;
00031         
00032     /**
00033       if web socket is started
00034     **/
00035         BOOL isStarted;  
00036     
00037     /**
00038       if web socket is open
00039     **/
00040         BOOL isOpen;  
00041     
00042     /**
00043       if version76
00044     **/
00045         BOOL isVersion76; 
00046 }
00047 
00048 /**
00049     Class method
00050     param HTTPMessage
00051     returns BOOL
00052 **/
00053 + (BOOL)isWebSocketRequest:(HTTPMessage *)request;
00054 
00055 /**
00056     Initialize with HTTPMessage request and a socket
00057     param HTTPMessage
00058     param GCDAsyncSocket
00059 **/
00060 - (id)initWithRequest:(HTTPMessage *)request socket:(GCDAsyncSocket *)socket;
00061 
00062 /**
00063  * Delegate option.
00064  * 
00065  * In most cases it will be easier to subclass WebSocket,
00066  * but some circumstances may lead one to prefer standard delegate callbacks instead.
00067 **/
00068 @property (/* atomic */ assign) id delegate;
00069 
00070 /**
00071  * The WebSocket class is thread-safe, generally via it's GCD queue.
00072  * All public API methods are thread-safe,
00073  * and the subclass API methods are thread-safe as they are all invoked on the same GCD queue.
00074 **/
00075 @property (nonatomic, readonly) dispatch_queue_t websocketQueue;
00076 
00077 /**
00078  * Public API
00079  * 
00080  * These methods are automatically called by the HTTPServer.
00081  * You may invoke the stop method yourself to close the WebSocket manually.
00082 **/
00083 
00084 /**
00085  * Starting point for the WebSocket after it has been fully initialized (including subclasses).
00086  * This method is called by the HTTPConnection it is spawned from.
00087  **/
00088 - (void)start;
00089 
00090 
00091 
00092 /**
00093  * This method is called by the HTTPServer if it is asked to stop.
00094  * The server, in turn, invokes stop on each WebSocket instance.
00095  **/
00096 - (void)stop;
00097 
00098 /**
00099  * Public API
00100  * 
00101  * Sends a message over the WebSocket.
00102  * This method is thread-safe.
00103 **/
00104 - (void)sendMessage:(NSString *)msg;
00105 
00106 /**
00107  * Subclass API
00108  * 
00109  * These methods are designed to be overriden by subclasses.
00110 **/
00111 
00112 /**
00113     If the web socket did open
00114 **/
00115 - (void)didOpen;
00116 
00117 /**
00118     If the web socket did receive an incoming message
00119 **/
00120 - (void)didReceiveMessage:(NSString *)msg;
00121 
00122 /**
00123     If the web socket did close
00124 **/
00125 - (void)didClose;
00126 
00127 @end
00128 
00129 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00130 #pragma mark -
00131 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00132 
00133 /**
00134  * There are two ways to create your own custom WebSocket:
00135  * 
00136  * - Subclass it and override the methods you're interested in.
00137  * - Use traditional delegate paradigm along with your own custom class.
00138  * 
00139  * They both exist to allow for maximum flexibility.
00140  * In most cases it will be easier to subclass WebSocket.
00141  * However some circumstances may lead one to prefer standard delegate callbacks instead.
00142  * One such example, you're already subclassing another class, so subclassing WebSocket isn't an option.
00143 **/
00144 
00145 @protocol WebSocketDelegate
00146 @optional
00147 
00148 /**
00149     The websocket did open
00150     param WebSocket
00151 **/
00152 - (void)webSocketDidOpen:(WebSocket *)ws;
00153 
00154 /**
00155     The websocket did receive an incoming message
00156     param WebSocket
00157     param NSString
00158 **/
00159 - (void)webSocket:(WebSocket *)ws didReceiveMessage:(NSString *)msg;
00160 
00161 /**
00162     The websocket did close
00163     param WebSocket
00164 **/
00165 - (void)webSocketDidClose:(WebSocket *)ws;
00166 
00167 @end
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines