2015-07-23 23:56:23 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-07-23 23:56:23 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-07-23 23:56:23 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-07-23 23:56:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-08-10 22:34:14 +00:00
|
|
|
type DevToolsPluginConnection = {
|
|
|
|
isAppActive: () => boolean,
|
|
|
|
host: string,
|
|
|
|
port: number,
|
|
|
|
};
|
|
|
|
|
|
|
|
type DevToolsPlugin = {
|
|
|
|
connectToDevTools: (connection: DevToolsPluginConnection) => void,
|
|
|
|
};
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
let register = function() {
|
2017-08-10 22:34:14 +00:00
|
|
|
// noop
|
|
|
|
};
|
|
|
|
|
2017-02-14 21:53:21 +00:00
|
|
|
if (__DEV__) {
|
2017-02-22 22:54:11 +00:00
|
|
|
const AppState = require('AppState');
|
2017-06-01 15:20:57 +00:00
|
|
|
const WebSocket = require('WebSocket');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $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
|
|
|
|
* comment and run Flow. */
|
2017-08-10 22:34:14 +00:00
|
|
|
const reactDevTools = require('react-devtools-core');
|
2017-12-29 15:44:42 +00:00
|
|
|
const getDevServer = require('getDevServer');
|
2017-08-10 22:34:14 +00:00
|
|
|
|
2017-09-26 02:23:42 +00:00
|
|
|
// Initialize dev tools only if the native module for WebSocket is available
|
|
|
|
if (WebSocket.isAvailable) {
|
|
|
|
// Don't steal the DevTools from currently active app.
|
|
|
|
// Note: if you add any AppState subscriptions to this file,
|
|
|
|
// you will also need to guard against `AppState.isAvailable`,
|
|
|
|
// or the code will throw for bundles that don't have it.
|
|
|
|
const isAppActive = () => AppState.currentState !== 'background';
|
|
|
|
|
2017-12-29 15:44:42 +00:00
|
|
|
// Get hostname from development server (packager)
|
|
|
|
const devServer = getDevServer();
|
|
|
|
const host = devServer.bundleLoadedFromServer
|
|
|
|
? devServer.url.replace(/https?:\/\//, '').split(':')[0]
|
|
|
|
: 'localhost';
|
2017-09-26 02:23:42 +00:00
|
|
|
|
|
|
|
reactDevTools.connectToDevTools({
|
|
|
|
isAppActive,
|
|
|
|
host,
|
|
|
|
// Read the optional global variable for backward compatibility.
|
|
|
|
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
|
|
|
|
port: window.__REACT_DEVTOOLS_PORT__,
|
|
|
|
resolveRNStyle: require('flattenStyle'),
|
|
|
|
});
|
|
|
|
}
|
2015-07-23 23:56:23 +00:00
|
|
|
}
|
2017-08-10 22:34:14 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
register,
|
|
|
|
};
|