Skip to content

Commit

Permalink
Disallow sending messages before a socket is open
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjpayne committed May 12, 2016
1 parent 11fa5fe commit aaff48e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PocketSocket/PSWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ - (void)open {
- (void)send:(id)message {
NSParameterAssert(message);
[self executeWork:^{
if(!_opened || _readyState == PSWebSocketReadyStateConnecting) {
[NSException raise:@"Invalid State" format:@"You cannot send a PSWebSocket messages before it is finished opening."];
return;
}

if([message isKindOfClass:[NSString class]]) {
[_driver sendText:message];
} else if([message isKindOfClass:[NSData class]]) {
Expand Down

0 comments on commit aaff48e

Please sign in to comment.