UNPKG

1.71 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 * @flow
9 */
10
11'use strict';
12
13let register = function() {
14 // noop
15};
16
17if (__DEV__) {
18 const AppState = require('AppState');
19 const WebSocket = require('WebSocket');
20 /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
21 * error found when Flow v0.54 was deployed. To see the error delete this
22 * comment and run Flow. */
23 const reactDevTools = require('react-devtools-core');
24 const getDevServer = require('getDevServer');
25
26 // Initialize dev tools only if the native module for WebSocket is available
27 if (WebSocket.isAvailable) {
28 // Don't steal the DevTools from currently active app.
29 // Note: if you add any AppState subscriptions to this file,
30 // you will also need to guard against `AppState.isAvailable`,
31 // or the code will throw for bundles that don't have it.
32 const isAppActive = () => AppState.currentState !== 'background';
33
34 // Get hostname from development server (packager)
35 const devServer = getDevServer();
36 const host = devServer.bundleLoadedFromServer
37 ? devServer.url.replace(/https?:\/\//, '').split(':')[0]
38 : 'localhost';
39
40 reactDevTools.connectToDevTools({
41 isAppActive,
42 host,
43 // Read the optional global variable for backward compatibility.
44 // It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
45 port: window.__REACT_DEVTOOLS_PORT__,
46 resolveRNStyle: require('flattenStyle'),
47 });
48 }
49}
50
51module.exports = {
52 register,
53};