Skip to content

[iOS] [Fixed] - Fixed code and reason arguments ignored on iOS when listening to WebSocket.onclose#26052

Closed
diegolmello wants to merge 1 commit intofacebook:mainfrom
diegolmello:fix.did-close-with-code
Closed

[iOS] [Fixed] - Fixed code and reason arguments ignored on iOS when listening to WebSocket.onclose#26052
diegolmello wants to merge 1 commit intofacebook:mainfrom
diegolmello:fix.did-close-with-code

Conversation

@diegolmello
Copy link
Copy Markdown

Summary

Websocket ignores code and reason from onclose listener.
Some work was done in #24950 to send them to close, but onclose always returns 1001 and Stream end encountered:
https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTSRWebSocket.m#L1391

This PR calls didCloseWithCode at the end of closeWithCode and Websocket.onclose now works.

Changelog

[iOS] [Fixed] - Fixed code and reason arguments ignored on iOS when listening to WebSocket.onclose

Test Plan

Run integration tests.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@react-native-bot react-native-bot added Platform: iOS iOS applications. Bug labels Aug 13, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 13, 2019
@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@roadmanfong
Copy link
Copy Markdown

I tried patching the code from @diegolmello to my project, but it return with code: 1000 and null reason

So I wrote more lines and it works, but I'm not good at objective-c.

Can someone check if I'm doing right?

diff --git a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
index 8ce6edc..01a5948 100644
--- a/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
+++ b/node_modules/react-native/Libraries/WebSocket/RCTSRWebSocket.m
@@ -594,6 +594,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason
       }
     }

+    [self.delegate webSocket:self didCloseWithCode:code reason:reason wasClean:YES];
     [self _sendFrameWithOpcode:RCTSROpCodeConnectionClose data:payload];
   });
 }
@@ -764,7 +765,9 @@ - (void)handleCloseWithData:(NSData *)data

   [self assertOnWorkQueue];

-  if (self.readyState == RCTSR_OPEN) {
+  if (_closeCode) {
+    [self closeWithCode:_closeCode reason:_closeReason];
+  } else if (self.readyState == RCTSR_OPEN) {
     [self closeWithCode:1000 reason:nil];
   }
   dispatch_async(_workQueue, ^{

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 14, 2023
@github-actions
Copy link
Copy Markdown

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants