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

[reupload] - added: Websocket Module setCustomClientBuilder #37798

Closed
wants to merge 10 commits into from

Conversation

MO-Lewis
Copy link
Contributor

@MO-Lewis MO-Lewis commented Jun 9, 2023

Summary:

Added code previously added in the following PR: #28659.

The above PR was accidentally scrapped due to the renaming of the master branch on the React Native repo. As advised in this comment: #37770 (comment), I'm opening a new PR with the same code to get this merged into master / main.

Currently, we need to run a local fork of React Native and manually apply these changes ourselves. This then causes additional issues, as it's currently impossible to build React Native from source when running on a Windows machine, as evidenced in #37770 and the other linked issues nested inside of this issue.

Original summary is as follows:
With NetworkModule.setCustomClientBuilder we can customize our OkHttpClient to all requests made by react-native, it's very useful when you do SSL Pinning or change some OkHttpClient configuration at all. I've added a similar function to websocket, it allow us do some configurations on Websocket OkHttpClient.

Changelog:

[Android] [Added] - Websocket Module setCustomClientBuilder

Test Plan:

From the original PR:

You can just set a custom CustomClientBuilder on MainActivity onCreate:

import okhttp3.OkHttpClient;
import java.util.concurrent.TimeUnit;
import com.facebook.react.modules.network.CustomClientBuilder;
import com.facebook.react.modules.websocket.WebsocketModule;

public class MainActivity extends ReactFragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);

        WebsocketModule.setCustomClientBuilder(new CustomClientBuilder() {
            @Override
            public void apply(OkHttpClient.Builder builder) {
              builder.connectTimeout(0, TimeUnit.MILLISECONDS);
            }
          });
    }

   ...

@facebook-github-bot
Copy link
Contributor

Hi @MO-Lewis!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign 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 to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@analysis-bot
Copy link

analysis-bot commented Jun 9, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,836,393 +144
android hermes armeabi-v7a 8,146,280 +140
android hermes x86 9,341,760 +135
android hermes x86_64 9,184,507 +144
android jsc arm64-v8a 9,448,196 +89
android jsc armeabi-v7a 8,629,957 +93
android jsc x86 9,530,877 +95
android jsc x86_64 9,774,080 +92

Base commit: 04ad34d
Branch: main

@MO-Lewis
Copy link
Contributor Author

FYI I've just signed the CLA, I'm guessing it'll update the PR shortly 😅

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Jun 20, 2023
Comment on lines -170 to -172
public static interface CustomClientBuilder {
public void apply(OkHttpClient.Builder builder);
}
Copy link
Member

Choose a reason for hiding this comment

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

For backwards compatibility, can you keep the old interface name here, but mark it as deprecated. We can then remove it in a future release

public static interface CustomClientBuilder extends com.facebook.react.modules.network.CustomClientBuilder {}

@javache
Copy link
Member

javache commented Jul 7, 2023

Please note the deprecation of the old interface in the changelog entry, other than that, this seems good to me.

@MO-Lewis
Copy link
Contributor Author

Hi @javache! I've just made that change for you, I believe this is what you wanted. If there's something not right about the change I've made, or have any additional feedback, please let me know. 😄

Thanks!

…up to commit `52698e758d1454afc74541e5507ac16dd6154386`

Merge remote-tracking branch 'upstream/main'
@MO-Lewis
Copy link
Contributor Author

Just did another commit to merge everything and pull recent changes from the main React Native repo up to commit 52698e758d1454afc74541e5507ac16dd6154386

/**
* @deprecated To be removed in a future release. See https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914
*/
public static interface CustomClientBuilder extends com.facebook.react.modules.network.CustomClientBuilder {
public void apply(OkHttpClient.Builder builder);
Copy link
Member

Choose a reason for hiding this comment

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

This can just be an empty interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented in latest commit; resolve if sufficient.


public interface CustomClientBuilder {
public void apply(OkHttpClient.Builder builder);
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: empty new line at end of file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amended in latest commit; resolve if sufficient.

Copy link
Member

@javache javache left a comment

Choose a reason for hiding this comment

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

Looking good, few more changes.

/**
* @deprecated To be removed in a future release. See https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914
*/
public static interface CustomClientBuilder extends com.facebook.react.modules.network.CustomClientBuilder {
Copy link
Member

Choose a reason for hiding this comment

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

Make sure the API's in this class reference com.facebook.react.modules.network.CustomClientBuilder, not this CustomClientBuilder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies, I'm not too sure what you mean by this. Does this mean you'd like com.facebook.react.modules.network.CustomClientBuilder explicitly imported at the top of this file?

Copy link
Member

Choose a reason for hiding this comment

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

Anywhere in this Java file where it references CustomClientBuilder it will use the old deprecated interface, you could point at the shared interface instead, and will prevent people from upgrading their code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @javache, I believe I've implemented what you'd like. I've changed:

public static void setCustomClientBuilder(CustomClientBuilder ccb) {
to
public static void setCustomClientBuilder(com.facebook.react.modules.network.CustomClientBuilder ccb) {

Does this cover what you've requested? Anything else, just let me know 🙂

@@ -0,0 +1,75 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

This file has been incorrectly merged back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies! Removed in latest commit; resolve if sufficient.

Changelog:
- Added empty new line at end of file on `CustomClientBuilder.java`
- Removed accidentally-added `ReactNativeFlipper.java` file.
- Made deprecated `CustomClientBuilder` interface empty.
@MO-Lewis MO-Lewis requested a review from javache July 12, 2023 16:06
@@ -167,9 +167,10 @@ public static void setCustomClientBuilder(CustomClientBuilder ccb) {
customClientBuilder = ccb;
Copy link
Member

Choose a reason for hiding this comment

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

Silly github doesn't allow you to comment on unchanged lines, but line 168 here needs to be com.facebook.react.modules.network.CustomClientBuilder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Javache, I've implemented and replied to this here

Changelog:
- Implemented feedback to point all `CustomClientBuilder` references in `NetworkingModule,java` to `com.facebook.react.modules.network.CustomClientBuilder`
@MO-Lewis MO-Lewis requested a review from javache July 13, 2023 16:09
Copy link
Member

@javache javache left a comment

Choose a reason for hiding this comment

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

The type of customClientBuilder in NetworkingModule also needs to become com.facebook.react.modules.network.CustomClientBuilder

Changelog:
- Changed `private static @nullable CustomClientBuilder` to `private static @nullable com.facebook.react.modules.network.CustomClientBuilder`
@MO-Lewis
Copy link
Contributor Author

The type of customClientBuilder in NetworkingModule also needs to become com.facebook.react.modules.network.CustomClientBuilder

Thanks for the heads up! I've just made that change now.

@MO-Lewis MO-Lewis requested a review from javache July 14, 2023 09:46
@facebook-github-bot
Copy link
Contributor

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

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

@MO-Lewis could you rebase on top of the latest main as the CI should be green now

@MO-Lewis
Copy link
Contributor Author

@MO-Lewis could you rebase on top of the latest main as the CI should be green now

All done! CI is rerunning for you now.

Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

One nit @MO-Lewis and we should be able to merge it

/**
* @deprecated To be removed in a future release. See https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914
*/
public static interface CustomClientBuilder extends com.facebook.react.modules.network.CustomClientBuilder {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also @Deprecate this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Just added that, CICD re-running now.

MO-Lewis added 3 commits July 18, 2023 12:12
Changelog:
- Added `@Deprecated` to `CustomClientBuilder` in `NetworkingModule.java
Changelog:
- Added `@Deprecated` to `CustomClientBuilder` in `NetworkingModule.java`
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 18, 2023
@facebook-github-bot
Copy link
Contributor

@javache merged this pull request in 0cdb9e6.

juniorklawa pushed a commit to juniorklawa/react-native that referenced this pull request Jul 20, 2023
Summary:
Added code previously added in the following PR: facebook#28659.

The above PR was accidentally scrapped due to the renaming of the master branch on the React Native repo. As advised in this comment: facebook#37770 (comment), I'm opening a new PR with the same code to get this merged into master / main.

Currently, we need to run a local fork of React Native and manually apply these changes ourselves. This then causes additional issues, as it's currently _**impossible**_ to build React Native from source when running on a Windows machine, as evidenced in facebook#37770 and the other linked issues nested inside of this issue.

**Original summary is as follows:**
With `NetworkModule.setCustomClientBuilder` we can customize our OkHttpClient to all requests made by react-native, it's very useful when you do `SSL Pinning` or change some OkHttpClient configuration at all. I've added a similar function to websocket, it allow us do some configurations on Websocket OkHttpClient.

## Changelog:
[Android] [Added] - Websocket Module setCustomClientBuilder

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: facebook#37798

Test Plan:
**From the original PR:**

You can just set a custom `CustomClientBuilder` on `MainActivity` `onCreate`:

```
import okhttp3.OkHttpClient;
import java.util.concurrent.TimeUnit;
import com.facebook.react.modules.network.CustomClientBuilder;
import com.facebook.react.modules.websocket.WebsocketModule;

public class MainActivity extends ReactFragmentActivity {

    Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);

        WebsocketModule.setCustomClientBuilder(new CustomClientBuilder() {
            Override
            public void apply(OkHttpClient.Builder builder) {
              builder.connectTimeout(0, TimeUnit.MILLISECONDS);
            }
          });
    }

   ...
```

Reviewed By: cortinico

Differential Revision: D47468613

Pulled By: javache

fbshipit-source-id: ad97fb18ba5784d8abe157f5ccd29201b8b0fe84
DDRBoxman pushed a commit to discord/react-native that referenced this pull request Feb 15, 2024
Summary:
Added code previously added in the following PR: facebook#28659.

The above PR was accidentally scrapped due to the renaming of the master branch on the React Native repo. As advised in this comment: facebook#37770 (comment), I'm opening a new PR with the same code to get this merged into master / main.

Currently, we need to run a local fork of React Native and manually apply these changes ourselves. This then causes additional issues, as it's currently _**impossible**_ to build React Native from source when running on a Windows machine, as evidenced in facebook#37770 and the other linked issues nested inside of this issue.

**Original summary is as follows:**
With `NetworkModule.setCustomClientBuilder` we can customize our OkHttpClient to all requests made by react-native, it's very useful when you do `SSL Pinning` or change some OkHttpClient configuration at all. I've added a similar function to websocket, it allow us do some configurations on Websocket OkHttpClient.

[Android] [Added] - Websocket Module setCustomClientBuilder

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: facebook#37798

Test Plan:
**From the original PR:**

You can just set a custom `CustomClientBuilder` on `MainActivity` `onCreate`:

```
import okhttp3.OkHttpClient;
import java.util.concurrent.TimeUnit;
import com.facebook.react.modules.network.CustomClientBuilder;
import com.facebook.react.modules.websocket.WebsocketModule;

public class MainActivity extends ReactFragmentActivity {

    Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);

        WebsocketModule.setCustomClientBuilder(new CustomClientBuilder() {
            Override
            public void apply(OkHttpClient.Builder builder) {
              builder.connectTimeout(0, TimeUnit.MILLISECONDS);
            }
          });
    }

   ...
```

Reviewed By: cortinico

Differential Revision: D47468613

Pulled By: javache

fbshipit-source-id: ad97fb18ba5784d8abe157f5ccd29201b8b0fe84
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. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants