Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SocketRocket for web socket library #36347

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 10 additions & 10 deletions Libraries/WebSocket/RCTReconnectingWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>

#import <React/RCTSRWebSocket.h>
#import <SocketRocket/SRWebSocket.h>

#if RCT_DEV // Only supported in dev mode

@interface RCTReconnectingWebSocket () <RCTSRWebSocketDelegate>
@interface RCTReconnectingWebSocket () <SRWebSocketDelegate>
@end

@implementation RCTReconnectingWebSocket {
NSURL *_url;
RCTSRWebSocket *_socket;
SRWebSocket *_socket;
BOOL _stopped;
}

Expand All @@ -39,14 +39,14 @@ - (instancetype)initWithURL:(NSURL *)url

- (void)send:(id)data
{
[_socket send:data];
[_socket sendData:data error:nil];
}

- (void)start
{
[self stop];
_stopped = NO;
_socket = [[RCTSRWebSocket alloc] initWithURL:_url];
_socket = [[SRWebSocket alloc] initWithURL:_url];
_socket.delegate = self;
[_socket setDelegateDispatchQueue:_delegateDispatchQueue];
[_socket open];
Expand All @@ -60,7 +60,7 @@ - (void)stop
_socket = nil;
}

- (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
{
[_delegate reconnectingWebSocket:self didReceiveMessage:message];
}
Expand All @@ -71,7 +71,7 @@ - (void)reconnect
return;
}

__weak RCTSRWebSocket *socket = _socket;
__weak SRWebSocket *socket = _socket;
__weak __typeof(self) weakSelf = self;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
Expand All @@ -82,20 +82,20 @@ - (void)reconnect
});
}

- (void)webSocketDidOpen:(RCTSRWebSocket *)webSocket
- (void)webSocketDidOpen:(SRWebSocket *)webSocket
{
[_delegate reconnectingWebSocketDidOpen:self];
}

- (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error
{
[_delegate reconnectingWebSocketDidClose:self];
if ([error code] != ECONNREFUSED) {
[self reconnect];
}
}

- (void)webSocket:(RCTSRWebSocket *)webSocket
- (void)webSocket:(SRWebSocket *)webSocket
didCloseWithCode:(NSInteger)code
reason:(NSString *)reason
wasClean:(BOOL)wasClean
Expand Down
136 changes: 0 additions & 136 deletions Libraries/WebSocket/RCTSRWebSocket.h

This file was deleted.

Loading