Skip to content

Commit 11d3f4d

Browse files
rubennortefacebook-github-bot
authored andcommitted
Allow custom factories for HTTP and WebSocket clients for DevTools
Differential Revision: D79806934
1 parent 57bc303 commit 11d3f4d

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

packages/react-native/ReactCxxPlatform/react/http/IHttpClient.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ namespace facebook::react {
1010
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
1111
extern const char HttpClientFactoryKey[] = "HttpClientFactory";
1212

13+
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
14+
extern const char DevToolsHttpClientFactoryKey[] = "DevToolsHttpClientFactory";
15+
1316
} // namespace facebook::react

packages/react-native/ReactCxxPlatform/react/http/IHttpClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ struct IHttpClient {
8282

8383
extern const char HttpClientFactoryKey[];
8484

85+
extern const char DevToolsHttpClientFactoryKey[];
86+
8587
using HttpClientFactory = std::function<std::unique_ptr<IHttpClient>()>;
8688

8789
HttpClientFactory getHttpClientFactory();

packages/react-native/ReactCxxPlatform/react/http/IWebSocketClient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ namespace facebook::react {
1010
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
1111
extern const char WebSocketClientFactoryKey[] = "WebSocketClientFactory";
1212

13+
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
14+
extern const char DevToolsWebSocketClientFactoryKey[] =
15+
"DevToolsWebSocketClientFactory";
16+
1317
} // namespace facebook::react

packages/react-native/ReactCxxPlatform/react/http/IWebSocketClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class IWebSocketClient {
3838

3939
extern const char WebSocketClientFactoryKey[];
4040

41+
extern const char DevToolsWebSocketClientFactoryKey[];
42+
4143
using WebSocketClientFactory =
4244
std::function<std::unique_ptr<IWebSocketClient>()>;
4345

packages/react-native/ReactCxxPlatform/react/runtime/ReactHost.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ void ReactHost::createReactInstance() {
136136
reactInstanceData_->contextContainer->at<WebSocketClientFactory>(
137137
WebSocketClientFactoryKey);
138138

139+
auto devToolsHttpClientFactory =
140+
reactInstanceData_->contextContainer
141+
->find<HttpClientFactory>(DevToolsHttpClientFactoryKey)
142+
.value_or(httpClientFactory);
143+
144+
auto devToolsWebSocketClientFactory =
145+
reactInstanceData_->contextContainer
146+
->find<WebSocketClientFactory>(DevToolsWebSocketClientFactoryKey)
147+
.value_or(webSocketClientFactory);
148+
139149
// Create devServerHelper
140150
if (!devServerHelper_ &&
141151
(reactInstanceConfig_.enableInspector ||
@@ -145,7 +155,7 @@ void ReactHost::createReactInstance() {
145155
reactInstanceConfig_.deviceName,
146156
reactInstanceConfig_.devServerHost,
147157
reactInstanceConfig_.devServerPort,
148-
httpClientFactory,
158+
devToolsHttpClientFactory,
149159
[this](
150160
const std::string& moduleName,
151161
const std::string& methodName,
@@ -159,8 +169,8 @@ void ReactHost::createReactInstance() {
159169
inspector_ = std::make_shared<Inspector>(
160170
reactInstanceConfig_.appId,
161171
reactInstanceConfig_.deviceName,
162-
webSocketClientFactory,
163-
httpClientFactory);
172+
devToolsWebSocketClientFactory,
173+
devToolsHttpClientFactory);
164174
inspector_->ensureHostTarget(
165175
[this]() { reloadReactInstance(); },
166176
[weakDevUIDelegate =
@@ -179,7 +189,7 @@ void ReactHost::createReactInstance() {
179189

180190
if (!packagerConnection_ && reactInstanceConfig_.enableDevMode) {
181191
packagerConnection_ = std::make_unique<PackagerConnection>(
182-
webSocketClientFactory,
192+
devToolsWebSocketClientFactory,
183193
devServerHelper_->getPackagerConnectionUrl(),
184194
[this]() { reloadReactInstance(); },
185195
[]() {});

0 commit comments

Comments
 (0)