16
16
import com .facebook .react .common .ReactConstants ;
17
17
import com .facebook .react .devsupport .interfaces .DevBundleDownloadListener ;
18
18
import com .facebook .react .devsupport .interfaces .PackagerStatusCallback ;
19
+ import com .facebook .react .modules .debug .interfaces .DeveloperSettings ;
19
20
import com .facebook .react .modules .systeminfo .AndroidInfoHelpers ;
20
21
import com .facebook .react .packagerconnection .FileIoHandler ;
21
22
import com .facebook .react .packagerconnection .JSPackagerClient ;
22
23
import com .facebook .react .packagerconnection .NotificationOnlyHandler ;
24
+ import com .facebook .react .packagerconnection .PackagerConnectionSettings ;
23
25
import com .facebook .react .packagerconnection .ReconnectingWebSocket .ConnectionCallback ;
24
26
import com .facebook .react .packagerconnection .RequestHandler ;
25
27
import com .facebook .react .packagerconnection .RequestOnlyHandler ;
@@ -99,7 +101,10 @@ public String typeID() {
99
101
}
100
102
}
101
103
102
- private final DevInternalSettings mSettings ;
104
+ private final DeveloperSettings mSettings ;
105
+
106
+ private final PackagerConnectionSettings mPackagerConnectionSettings ;
107
+
103
108
private final OkHttpClient mClient ;
104
109
private final BundleDownloader mBundleDownloader ;
105
110
private final PackagerStatusCheck mPackagerStatusCheck ;
@@ -110,10 +115,12 @@ public String typeID() {
110
115
private InspectorPackagerConnection .BundleStatusProvider mBundlerStatusProvider ;
111
116
112
117
public DevServerHelper (
113
- DevInternalSettings settings ,
118
+ DeveloperSettings developerSettings ,
114
119
String packageName ,
115
- InspectorPackagerConnection .BundleStatusProvider bundleStatusProvider ) {
116
- mSettings = settings ;
120
+ InspectorPackagerConnection .BundleStatusProvider bundleStatusProvider ,
121
+ PackagerConnectionSettings packagerConnectionSettings ) {
122
+ mSettings = developerSettings ;
123
+ mPackagerConnectionSettings = packagerConnectionSettings ;
117
124
mBundlerStatusProvider = bundleStatusProvider ;
118
125
mClient =
119
126
new OkHttpClient .Builder ()
@@ -181,10 +188,7 @@ public void onDisconnected() {
181
188
182
189
mPackagerClient =
183
190
new JSPackagerClient (
184
- clientId ,
185
- mSettings .getPackagerConnectionSettings (),
186
- handlers ,
187
- onPackagerConnectedCallback );
191
+ clientId , mPackagerConnectionSettings , handlers , onPackagerConnectedCallback );
188
192
mPackagerClient .init ();
189
193
190
194
return null ;
@@ -277,14 +281,14 @@ public String getWebsocketProxyURL() {
277
281
return String .format (
278
282
Locale .US ,
279
283
"ws://%s/debugger-proxy?role=client" ,
280
- mSettings . getPackagerConnectionSettings () .getDebugServerHost ());
284
+ mPackagerConnectionSettings .getDebugServerHost ());
281
285
}
282
286
283
287
private String getInspectorDeviceUrl () {
284
288
return String .format (
285
289
Locale .US ,
286
290
"http://%s/inspector/device?name=%s&app=%s" ,
287
- mSettings . getPackagerConnectionSettings () .getInspectorServerHost (),
291
+ mPackagerConnectionSettings .getInspectorServerHost (),
288
292
AndroidInfoHelpers .getFriendlyDeviceName (),
289
293
mPackageName );
290
294
}
@@ -315,8 +319,7 @@ public void downloadBundleFromURL(
315
319
/** @return the host to use when connecting to the bundle server from the host itself. */
316
320
private String getHostForJSProxy () {
317
321
// Use custom port if configured. Note that host stays "localhost".
318
- String host =
319
- Assertions .assertNotNull (mSettings .getPackagerConnectionSettings ().getDebugServerHost ());
322
+ String host = Assertions .assertNotNull (mPackagerConnectionSettings .getDebugServerHost ());
320
323
int portOffset = host .lastIndexOf (':' );
321
324
if (portOffset > -1 ) {
322
325
return "localhost" + host .substring (portOffset );
@@ -362,8 +365,7 @@ private String createBundleURL(
362
365
}
363
366
364
367
private String createBundleURL (String mainModuleID , BundleType type ) {
365
- return createBundleURL (
366
- mainModuleID , type , mSettings .getPackagerConnectionSettings ().getDebugServerHost ());
368
+ return createBundleURL (mainModuleID , type , mPackagerConnectionSettings .getDebugServerHost ());
367
369
}
368
370
369
371
private static String createResourceURL (String host , String resourcePath ) {
@@ -372,18 +374,15 @@ private static String createResourceURL(String host, String resourcePath) {
372
374
373
375
public String getDevServerBundleURL (final String jsModulePath ) {
374
376
return createBundleURL (
375
- jsModulePath ,
376
- BundleType .BUNDLE ,
377
- mSettings .getPackagerConnectionSettings ().getDebugServerHost ());
377
+ jsModulePath , BundleType .BUNDLE , mPackagerConnectionSettings .getDebugServerHost ());
378
378
}
379
379
380
380
public String getDevServerSplitBundleURL (String jsModulePath ) {
381
- return createSplitBundleURL (
382
- jsModulePath , mSettings .getPackagerConnectionSettings ().getDebugServerHost ());
381
+ return createSplitBundleURL (jsModulePath , mPackagerConnectionSettings .getDebugServerHost ());
383
382
}
384
383
385
384
public void isPackagerRunning (final PackagerStatusCallback callback ) {
386
- String host = mSettings . getPackagerConnectionSettings () .getDebugServerHost ();
385
+ String host = mPackagerConnectionSettings .getDebugServerHost ();
387
386
if (host == null ) {
388
387
FLog .w (ReactConstants .TAG , "No packager host configured." );
389
388
callback .onPackagerStatusFetched (false );
@@ -396,7 +395,7 @@ private String createLaunchJSDevtoolsCommandUrl() {
396
395
return String .format (
397
396
Locale .US ,
398
397
"http://%s/launch-js-devtools" ,
399
- mSettings . getPackagerConnectionSettings () .getDebugServerHost ());
398
+ mPackagerConnectionSettings .getDebugServerHost ());
400
399
}
401
400
402
401
public void launchJSDevtools () {
@@ -443,8 +442,7 @@ public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
443
442
public @ Nullable File downloadBundleResourceFromUrlSync (
444
443
final String resourcePath , final File outputFile ) {
445
444
final String resourceURL =
446
- createResourceURL (
447
- mSettings .getPackagerConnectionSettings ().getDebugServerHost (), resourcePath );
445
+ createResourceURL (mPackagerConnectionSettings .getDebugServerHost (), resourcePath );
448
446
final Request request = new Request .Builder ().url (resourceURL ).build ();
449
447
450
448
try (Response response = mClient .newCall (request ).execute ()) {
0 commit comments