Set host of development server for setupDevtools
Summary: Related to #15126, and this would be useful for use React DevTools on real device without modify `setupDevtools.js`. In Android emulator, the host of `SourceCode.scriptURL` is same with `PlatformConstants.ServerHost` so we can just replace it. * Tested on iOS device with [react-devtools](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) package. * Tested on Android emulator, the `getDevServer` module got the correctly hostname so that don't need `adb reverse`. [ENHANCEMENT] [setupDevtools] Set host of development server for setupDevtools Closes https://github.com/facebook/react-native/pull/15547 Differential Revision: D6544980 Pulled By: javache fbshipit-source-id: a286874bcef0501c5d2e0be2251d58c236a5534a
This commit is contained in:
parent
52f350a9cb
commit
fa574c6092
|
@ -28,11 +28,11 @@ let register = function () {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
const AppState = require('AppState');
|
const AppState = require('AppState');
|
||||||
const WebSocket = require('WebSocket');
|
const WebSocket = require('WebSocket');
|
||||||
const {PlatformConstants} = require('NativeModules');
|
|
||||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
|
||||||
* error found when Flow v0.54 was deployed. To see the error delete this
|
* error found when Flow v0.54 was deployed. To see the error delete this
|
||||||
* comment and run Flow. */
|
* comment and run Flow. */
|
||||||
const reactDevTools = require('react-devtools-core');
|
const reactDevTools = require('react-devtools-core');
|
||||||
|
const getDevServer = require('getDevServer');
|
||||||
|
|
||||||
// Initialize dev tools only if the native module for WebSocket is available
|
// Initialize dev tools only if the native module for WebSocket is available
|
||||||
if (WebSocket.isAvailable) {
|
if (WebSocket.isAvailable) {
|
||||||
|
@ -42,10 +42,11 @@ if (__DEV__) {
|
||||||
// or the code will throw for bundles that don't have it.
|
// or the code will throw for bundles that don't have it.
|
||||||
const isAppActive = () => AppState.currentState !== 'background';
|
const isAppActive = () => AppState.currentState !== 'background';
|
||||||
|
|
||||||
// Special case: Genymotion is running on a different host.
|
// Get hostname from development server (packager)
|
||||||
const host = PlatformConstants && PlatformConstants.ServerHost ?
|
const devServer = getDevServer();
|
||||||
PlatformConstants.ServerHost.split(':')[0] :
|
const host = devServer.bundleLoadedFromServer
|
||||||
'localhost';
|
? devServer.url.replace(/https?:\/\//, '').split(':')[0]
|
||||||
|
: 'localhost';
|
||||||
|
|
||||||
reactDevTools.connectToDevTools({
|
reactDevTools.connectToDevTools({
|
||||||
isAppActive,
|
isAppActive,
|
||||||
|
|
Loading…
Reference in New Issue