react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[reupload] - added: Websocket Module setCustomClientBuilder

Open MO-Lewis opened this issue 2 years ago • 5 comments

Summary:

Added code previously added in the following PR: https://github.com/facebook/react-native/pull/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: https://github.com/facebook/react-native/issues/37770#issuecomment-1582476332, 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 https://github.com/facebook/react-native/issues/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);
            }
          });
    }

   ...

MO-Lewis avatar Jun 09 '23 12:06 MO-Lewis

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 [email protected]. Thanks!

facebook-github-bot avatar Jun 09 '23 12:06 facebook-github-bot

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: 04ad34d6ad64c702d6619aa5a358ddd376f8be8e Branch: main

analysis-bot avatar Jun 09 '23 13:06 analysis-bot

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

MO-Lewis avatar Jun 20 '23 14:06 MO-Lewis

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 avatar Jun 20 '23 15:06 facebook-github-bot

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

javache avatar Jul 07 '23 08:07 javache

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!

MO-Lewis avatar Jul 11 '23 10:07 MO-Lewis

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

MO-Lewis avatar Jul 11 '23 10:07 MO-Lewis

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 avatar Jul 14 '23 09:07 MO-Lewis

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

facebook-github-bot avatar Jul 14 '23 11:07 facebook-github-bot

@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.

MO-Lewis avatar Jul 18 '23 09:07 MO-Lewis

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

facebook-github-bot avatar Jul 18 '23 13:07 facebook-github-bot

@javache merged this pull request in facebook/react-native@0cdb9e6a52f69ebee635d5bfaa34a52f6059dd47.

facebook-github-bot avatar Jul 18 '23 21:07 facebook-github-bot