Permalink
Browse files

Use NSRunLoopCommonMondes as default run loop mode for ZTWebSocket, b…

…ut allow user to supply their own run loop modes
  • Loading branch information...
1 parent 000b556 commit 5284da5462ee50bbb8ab04651d576500c7c41b3e Esad Hajdarevic committed Feb 19, 2010
Showing with 8 additions and 11 deletions.
  1. +1 −4 samples/Chat/Classes/ChatViewController.m
  2. +4 −5 src/ZTWebSocket.m
  3. +3 −2 src/Zimt/ZTWebSocket.h
@@ -20,10 +20,7 @@ -(void)write:(NSString*)text {
-(void)viewDidLoad {
webSocket = [[ZTWebSocket alloc] initWithURLString:@"ws://localhost:10000/" delegate:self];
- [webSocket open];
- NSArray *runLoopModes = [NSArray arrayWithObjects:NSRunLoopCommonModes, nil];
- [webSocket setRunLoopModes:runLoopModes];
-
+ [webSocket open];
[textField becomeFirstResponder];
}
View
@@ -21,7 +21,7 @@
@implementation ZTWebSocket
-@synthesize delegate, url, origin, connected;
+@synthesize delegate, url, origin, connected, runLoopModes;
#pragma mark Initializers
@@ -37,6 +37,7 @@ -(id)initWithURLString:(NSString *)urlString delegate:(id<ZTWebSocketDelegate>)a
[NSException raise:ZTWebSocketException format:[NSString stringWithFormat:@"Unsupported protocol %@",url.scheme]];
}
socket = [[AsyncSocket alloc] initWithDelegate:self];
+ self.runLoopModes = [NSArray arrayWithObjects:NSRunLoopCommonModes, nil];
}
return self;
}
@@ -81,17 +82,14 @@ -(void)_readNextMessage {
#pragma mark Public interface
-- (BOOL)setRunLoopModes:(NSArray *)runLoopModes {
- return [socket setRunLoopModes:runLoopModes];
-}
-
-(void)close {
[socket disconnectAfterReadingAndWriting];
}
-(void)open {
if (!connected) {
[socket connectToHost:url.host onPort:[url.port intValue] withTimeout:5 error:nil];
+ if (runLoopModes) [socket setRunLoopModes:runLoopModes];
}
}
@@ -167,6 +165,7 @@ -(void)dealloc {
socket.delegate = nil;
[socket disconnect];
[socket release];
+ [runLoopModes release];
[url release];
[super dealloc];
}
View
@@ -26,18 +26,19 @@
AsyncSocket* socket;
BOOL connected;
NSString* origin;
+
+ NSArray* runLoopModes;
}
@property(nonatomic,assign) id<ZTWebSocketDelegate> delegate;
@property(nonatomic,readonly) NSURL* url;
@property(nonatomic,retain) NSString* origin;
@property(nonatomic,readonly) BOOL connected;
+@property(nonatomic,retain) NSArray* runLoopModes;
+ (id)webSocketWithURLString:(NSString*)urlString delegate:(id<ZTWebSocketDelegate>)delegate;
- (id)initWithURLString:(NSString*)urlString delegate:(id<ZTWebSocketDelegate>)delegate;
-- (BOOL)setRunLoopModes:(NSArray *)runLoopModes;
-
- (void)open;
- (void)close;
- (void)send:(NSString*)message;

0 comments on commit 5284da5

Please sign in to comment.