Skip to content
Closed
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
17 changes: 15 additions & 2 deletions packages/react-native/React/CoreModules/RCTWebSocketModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
NSString *type;

NSNumber *socketID = [webSocket reactTag];
if (!socketID) {
return;
}
id contentHandler = _contentHandlers[socketID];
if (contentHandler) {
message = [contentHandler processWebsocketMessage:message forSocketID:socketID withType:&type];
Expand All @@ -152,18 +155,25 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message
}
}

[self sendEventWithName:@"websocketMessage" body:@{@"data" : message, @"type" : type, @"id" : webSocket.reactTag}];
[self sendEventWithName:@"websocketMessage" body:@{@"data" : message, @"type" : type, @"id" : socketID}];
}

- (void)webSocketDidOpen:(SRWebSocket *)webSocket
{
NSNumber *socketID = [webSocket reactTag];
if (!socketID) {
return;
}
[self sendEventWithName:@"websocketOpen"
body:@{@"id" : webSocket.reactTag, @"protocol" : webSocket.protocol ? webSocket.protocol : @""}];
body:@{@"id" : socketID, @"protocol" : webSocket.protocol ? webSocket.protocol : @""}];
}

- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error
{
NSNumber *socketID = [webSocket reactTag];
if (!socketID) {
return;
}
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
NSDictionary *body =
Expand All @@ -177,6 +187,9 @@ - (void)webSocket:(SRWebSocket *)webSocket
wasClean:(BOOL)wasClean
{
NSNumber *socketID = [webSocket reactTag];
if (!socketID) {
return;
}
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketClosed"
Expand Down
Loading