react-native
react-native copied to clipboard
[reupload] - added: Websocket Module setCustomClientBuilder
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);
}
});
}
...
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!
| 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
FYI I've just signed the CLA, I'm guessing it'll update the PR shortly 😅
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!
Please note the deprecation of the old interface in the changelog entry, other than that, this seems good to me.
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!
Just did another commit to merge everything and pull recent changes from the main React Native repo up to commit 52698e758d1454afc74541e5507ac16dd6154386
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.
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@MO-Lewis could you rebase on top of the latest
mainas the CI should be green now
All done! CI is rerunning for you now.
@javache has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@javache merged this pull request in facebook/react-native@0cdb9e6a52f69ebee635d5bfaa34a52f6059dd47.