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

added: Websocket Module setCustomClientBuilder #28659

Closed
wants to merge 4 commits into from
Closed

added: Websocket Module setCustomClientBuilder #28659

wants to merge 4 commits into from

Conversation

djorkaeffalexandre
Copy link

@djorkaeffalexandre djorkaeffalexandre commented Apr 16, 2020

Summary

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

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 @djorkaeffalexandre!

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

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

@react-native-bot react-native-bot added the Platform: Android Android applications. label Apr 16, 2020
@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 Apr 16, 2020
@facebook-github-bot
Copy link
Contributor

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

@analysis-bot
Copy link

analysis-bot commented Apr 16, 2020

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,367,890 12
android hermes armeabi-v7a 6,994,970 8
android hermes x86 7,808,394 20
android hermes x86_64 7,699,940 12
android jsc arm64-v8a 9,512,943 20
android jsc armeabi-v7a 9,132,159 4
android jsc x86 9,379,019 8
android jsc x86_64 9,959,945 12

Base commit: c907202

@analysis-bot
Copy link

analysis-bot commented Apr 16, 2020

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: c907202

@djorkaeffalexandre djorkaeffalexandre changed the title changed: use OkHttpClientProvider on websocket added: Websocket Module setCustomClientBuilder Apr 17, 2020
@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label Apr 17, 2020
@djorkaeffalexandre
Copy link
Author

@shergin do you know if someone can take a look here?
This is an important change for us on https://github.com/RocketChat/Rocket.Chat.ReactNative, since we need to allow users to pin a SSL Client certificate before connect to a server and it should be pinned at all the network layer.
If we get this merged, we don't need to create a fork of React Native.
Is there any chance of merge this?
Thanks a lot.

@ChristophGr
Copy link

Any chance to get this in next release?
This is also important for WSS-Endpoints that require Client Certificates.

@bigfootjon bigfootjon closed this Jul 16, 2021
@bigfootjon bigfootjon deleted the branch facebook:master July 16, 2021 21:12
@yungsters
Copy link
Contributor

Sorry, we are working through some remaining issues with renaming the master branch to main and this PR was accidentally closed. We're working on fixing the affected PRs.

MO-Lewis added a commit to MO-Lewis/react-native-custom-ws-factory that referenced this pull request Jun 9, 2023
facebook-github-bot pushed a commit that referenced this pull request Jul 18, 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

<!-- 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: #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
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. Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants