@@ -73,7 +73,6 @@ public class DevServerHelper {
7373 private static final String ONCHANGE_ENDPOINT_URL_FORMAT =
7474 "http://%s/onchange" ;
7575 private static final String WEBSOCKET_PROXY_URL_FORMAT = "ws://%s/debugger-proxy?role=client" ;
76- private static final String PACKAGER_CONNECTION_URL_FORMAT = "ws://%s/message?role=android-rn-devserverhelper" ;
7776 private static final String PACKAGER_STATUS_URL_FORMAT = "http://%s/status" ;
7877 private static final String HEAP_CAPTURE_UPLOAD_URL_FORMAT = "http://%s/jscheapcaptureupload" ;
7978 private static final String INSPECTOR_DEVICE_URL_FORMAT = "http://%s/inspector/device?name=%s" ;
@@ -152,7 +151,7 @@ public void onRequest(@Nullable Object params, JSPackagerClient.Responder respon
152151 });
153152 handlers .putAll (new FileIoHandler ().handlers ());
154153
155- mPackagerClient = new JSPackagerClient (getPackagerConnectionURL (), handlers );
154+ mPackagerClient = new JSPackagerClient ("devserverhelper" , mSettings . getPackagerConnectionSettings (), handlers );
156155 mPackagerClient .init ();
157156
158157 return null ;
@@ -213,22 +212,18 @@ public static String getReloadAppAction(Context context) {
213212 }
214213
215214 public String getWebsocketProxyURL () {
216- return String .format (Locale .US , WEBSOCKET_PROXY_URL_FORMAT , getDebugServerHost ());
217- }
218-
219- private String getPackagerConnectionURL () {
220- return String .format (Locale .US , PACKAGER_CONNECTION_URL_FORMAT , getDebugServerHost ());
215+ return String .format (Locale .US , WEBSOCKET_PROXY_URL_FORMAT , mSettings .getPackagerConnectionSettings ().getDebugServerHost ());
221216 }
222217
223218 public String getHeapCaptureUploadUrl () {
224- return String .format (Locale .US , HEAP_CAPTURE_UPLOAD_URL_FORMAT , getDebugServerHost ());
219+ return String .format (Locale .US , HEAP_CAPTURE_UPLOAD_URL_FORMAT , mSettings . getPackagerConnectionSettings (). getDebugServerHost ());
225220 }
226221
227222 public String getInspectorDeviceUrl () {
228223 return String .format (
229224 Locale .US ,
230225 INSPECTOR_DEVICE_URL_FORMAT ,
231- getDebugServerHost (),
226+ mSettings . getPackagerConnectionSettings (). getDebugServerHost (),
232227 AndroidInfoHelpers .getFriendlyDeviceName ());
233228 }
234229
@@ -260,30 +255,6 @@ private boolean getHMR() {
260255 return mSettings .isHotModuleReplacementEnabled ();
261256 }
262257
263- /**
264- * @return the host to use when connecting to the bundle server.
265- */
266- private String getDebugServerHost () {
267- // Check debug server host setting first. If empty try to detect emulator type and use default
268- // hostname for those
269- String hostFromSettings = mSettings .getDebugServerHost ();
270-
271- if (!TextUtils .isEmpty (hostFromSettings )) {
272- return Assertions .assertNotNull (hostFromSettings );
273- }
274-
275- String host = AndroidInfoHelpers .getServerHost ();
276-
277- if (host .equals (AndroidInfoHelpers .DEVICE_LOCALHOST )) {
278- FLog .w (
279- ReactConstants .TAG ,
280- "You seem to be running on device. Run 'adb reverse tcp:8081 tcp:8081' " +
281- "to forward the debug server's port to the device." );
282- }
283-
284- return host ;
285- }
286-
287258 private static String createBundleURL (String host , String jsModulePath , boolean devMode , boolean hmr , boolean jsMinify ) {
288259 return String .format (Locale .US , BUNDLE_URL_FORMAT , host , jsModulePath , devMode , hmr , jsMinify );
289260 }
@@ -294,7 +265,7 @@ private static String createResourceURL(String host, String resourcePath) {
294265
295266 public String getDevServerBundleURL (final String jsModulePath ) {
296267 return createBundleURL (
297- getDebugServerHost (),
268+ mSettings . getPackagerConnectionSettings (). getDebugServerHost (),
298269 jsModulePath ,
299270 getDevMode (),
300271 getHMR (),
@@ -438,7 +409,7 @@ public void cancelDownloadBundleFromURL() {
438409 }
439410
440411 public void isPackagerRunning (final PackagerStatusCallback callback ) {
441- String statusURL = createPackagerStatusURL (getDebugServerHost ());
412+ String statusURL = createPackagerStatusURL (mSettings . getPackagerConnectionSettings (). getDebugServerHost ());
442413 Request request = new Request .Builder ()
443414 .url (statusURL )
444415 .build ();
@@ -558,11 +529,11 @@ public void onResponse(Call call, Response response) throws IOException {
558529 }
559530
560531 private String createOnChangeEndpointUrl () {
561- return String .format (Locale .US , ONCHANGE_ENDPOINT_URL_FORMAT , getDebugServerHost ());
532+ return String .format (Locale .US , ONCHANGE_ENDPOINT_URL_FORMAT , mSettings . getPackagerConnectionSettings (). getDebugServerHost ());
562533 }
563534
564535 private String createLaunchJSDevtoolsCommandUrl () {
565- return String .format (Locale .US , LAUNCH_JS_DEVTOOLS_COMMAND_URL_FORMAT , getDebugServerHost ());
536+ return String .format (Locale .US , LAUNCH_JS_DEVTOOLS_COMMAND_URL_FORMAT , mSettings . getPackagerConnectionSettings (). getDebugServerHost ());
566537 }
567538
568539 public void launchJSDevtools () {
@@ -584,11 +555,11 @@ public void onResponse(Call call, Response response) throws IOException {
584555 }
585556
586557 public String getSourceMapUrl (String mainModuleName ) {
587- return String .format (Locale .US , SOURCE_MAP_URL_FORMAT , getDebugServerHost (), mainModuleName , getDevMode (), getHMR (), getJSMinifyMode ());
558+ return String .format (Locale .US , SOURCE_MAP_URL_FORMAT , mSettings . getPackagerConnectionSettings (). getDebugServerHost (), mainModuleName , getDevMode (), getHMR (), getJSMinifyMode ());
588559 }
589560
590561 public String getSourceUrl (String mainModuleName ) {
591- return String .format (Locale .US , BUNDLE_URL_FORMAT , getDebugServerHost (), mainModuleName , getDevMode (), getHMR (), getJSMinifyMode ());
562+ return String .format (Locale .US , BUNDLE_URL_FORMAT , mSettings . getPackagerConnectionSettings (). getDebugServerHost (), mainModuleName , getDevMode (), getHMR (), getJSMinifyMode ());
592563 }
593564
594565 public String getJSBundleURLForRemoteDebugging (String mainModuleName ) {
@@ -607,7 +578,7 @@ public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
607578 public @ Nullable File downloadBundleResourceFromUrlSync (
608579 final String resourcePath ,
609580 final File outputFile ) {
610- final String resourceURL = createResourceURL (getDebugServerHost (), resourcePath );
581+ final String resourceURL = createResourceURL (mSettings . getPackagerConnectionSettings (). getDebugServerHost (), resourcePath );
611582 final Request request = new Request .Builder ()
612583 .url (resourceURL )
613584 .build ();
0 commit comments