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

[TM] Add spec for WebSocketModule #24893

Closed

Conversation

jeanregisser
Copy link
Contributor

Summary

Part of #24875

Changelog

[General] [Added] - Add TurboModule spec for WebSocketModule

Test Plan

Run yarn flow at the root level

@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label May 16, 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 May 16, 2019
@ericlewis ericlewis added the Flow label May 16, 2019
@RSNara RSNara self-requested a review May 16, 2019 22:19
Copy link
Contributor

@RSNara RSNara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested two approaches for solving the close issue. Thoughts?

+send: (message: string, socketID: number) => void;
+sendBinary: (base64String: string, socketID: number) => void;
+ping: (socketID: number) => void;
+close: typeof close;
Copy link
Contributor

@RSNara RSNara May 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky.

Approaches

  1. Create the specs/{ios,android} folders. Then, have a spec for ios and a spec for android. The only thing different between the two would be the close method. Then, you could create a NativeWebSocketModule.js file that returns the correct implementation based on Platform.OS.
  2. Refactor the API of close on Android to be close(socketID: number, code: number, reason: string): void;. Then type the second and third argument as optional. It seems like the only place where we use WebSocketModule is in WebSocket.js, so this wouldn't be difficult. Also, while we're working on WebSocketModule, it might be worthwhile to actually do some cleanup. Also, with approach number one, we have a lot of duplicate code.

I'm leaning more towards option 2. Even though it's probably the more difficult option, and even though it is a breaking change, I think it's probably the better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @RSNara

I was thinking about a 3rd approach, quite similar to approach 2:

  1. Refactoring the iOS API and allowing closing the socket with the reason and code like on Android. I checked the underlying implementation and it seems like a viable approach:
    - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;

This would actually make the iOS implementation more correct. Right now the JS interface for closing the WebSocket supports the reason and code but ignores it on iOS.

If we go this way, should the refactor be done in a different PR? I assume yes, but just checking.

Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also a good idea! But unfortunately, I just realized that our fb-internal infra doesn't allow refactoring NativeModule methods. So for the time being, I think we should just create two different spec files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure what you mean about the fb-internal infra refactoring limitation, but I've created 2 slightly different specs for now in 05d31c1

Note that I had to suppress the flow error when calling the close method. Let me know if there's a better way to avoid this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright since my small refactor for the iOS close method got merged, I'm gonna update the spec! There's no more a difference between the native iOS and Android implementations.

@ericlewis
Copy link
Contributor

ericlewis commented May 17, 2019 via email

WebSocketModule close method doesn't take the same arguments on iOS and
Android.
pull bot pushed a commit to Pandinosaurus/react-native that referenced this pull request May 20, 2019
…OS (facebook#24950)

Summary:
While working on facebook#24893 I noticed the `WebSocket` module implementation on iOS was ignoring the code and reason arguments for the `close` method.
The Android implementation already handled those arguments properly.
So this PR brings iOS implementation on par with Android for the `WebSocket` module.

## Changelog

[iOS] [Fixed] - Fixed `code` and `reason` arguments ignored on iOS when calling `WebSocket.close`
Pull Request resolved: facebook#24950

Differential Revision: D15411922

Pulled By: cpojer

fbshipit-source-id: f8a25598bd9c727313e24fea3801d5884d0723e4
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fkgozali has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @jeanregisser in 5705ea1.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label May 30, 2019
aleclarson pushed a commit to aleclarson/react-native-macos that referenced this pull request Jun 16, 2019
…OS (#24950)

Summary:
While working on facebook/react-native#24893 I noticed the `WebSocket` module implementation on iOS was ignoring the code and reason arguments for the `close` method.
The Android implementation already handled those arguments properly.
So this PR brings iOS implementation on par with Android for the `WebSocket` module.

[iOS] [Fixed] - Fixed `code` and `reason` arguments ignored on iOS when calling `WebSocket.close`
Pull Request resolved: facebook/react-native#24950

Differential Revision: D15411922

Pulled By: cpojer

fbshipit-source-id: f8a25598bd9c727313e24fea3801d5884d0723e4
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
…OS (facebook#24950)

Summary:
While working on facebook#24893 I noticed the `WebSocket` module implementation on iOS was ignoring the code and reason arguments for the `close` method.
The Android implementation already handled those arguments properly.
So this PR brings iOS implementation on par with Android for the `WebSocket` module.

## Changelog

[iOS] [Fixed] - Fixed `code` and `reason` arguments ignored on iOS when calling `WebSocket.close`
Pull Request resolved: facebook#24950

Differential Revision: D15411922

Pulled By: cpojer

fbshipit-source-id: f8a25598bd9c727313e24fea3801d5884d0723e4
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
Summary:
Part of facebook#24875

## Changelog

[General] [Added] - Add TurboModule spec for WebSocketModule
Pull Request resolved: facebook#24893

Reviewed By: RSNara

Differential Revision: D15551329

Pulled By: fkgozali

fbshipit-source-id: 59a921c50cc162528b2181fdd4cb1e41e3f1f6eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Flow Merged This PR has been merged. Native Module Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants