@@ -34,7 +34,6 @@ if (__DEV__) {
3434 require ( '../../src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher' ) ;
3535 const {
3636 initialize,
37- connectToDevTools,
3837 connectWithCustomMessagingProtocol,
3938 } = require ( 'react-devtools-core' ) ;
4039
@@ -117,94 +116,6 @@ if (__DEV__) {
117116 } ) ;
118117 }
119118
120- let isWebSocketOpen = false ;
121- let ws = null ;
122- function connectToWSBasedReactDevToolsFrontend ( ) {
123- if ( ws !== null && isWebSocketOpen ) {
124- // If the DevTools backend is already connected, don't recreate the WebSocket.
125- // This would break the connection.
126- // If there isn't an active connection, a backend may be waiting to connect,
127- // in which case it's okay to make a new one.
128- return ;
129- }
130-
131- // not when debugging in chrome
132- // TODO(t12832058) This check is broken
133- if ( ! window . document ) {
134- const AppState = require ( '../AppState/AppState' ) . default ;
135- const getDevServer = require ( './Devtools/getDevServer' ) . default ;
136-
137- // Don't steal the DevTools from currently active app.
138- // Note: if you add any AppState subscriptions to this file,
139- // you will also need to guard against `AppState.isAvailable`,
140- // or the code will throw for bundles that don't have it.
141- const isAppActive = ( ) => AppState . currentState !== 'background' ;
142-
143- // Get hostname from development server (packager)
144- const devServer = getDevServer ( ) ;
145- const host = devServer . bundleLoadedFromServer
146- ? guessHostFromDevServerUrl ( devServer . url )
147- : 'localhost' ;
148-
149- // Derive scheme and port from the dev server URL when possible,
150- // falling back to ws://host:8097 for local development.
151- let wsScheme = 'ws' ;
152- let port = 8097 ;
153-
154- if (
155- // $FlowFixMe[prop-missing]
156- // $FlowFixMe[incompatible-use]
157- window . __REACT_DEVTOOLS_PORT__ != null
158- ) {
159- // $FlowFixMe[prop-missing]
160- port = window . __REACT_DEVTOOLS_PORT__ ;
161- } else if ( devServer . bundleLoadedFromServer ) {
162- try {
163- const devUrl = new URL ( devServer . url ) ;
164- if ( devUrl . protocol === 'https:' ) {
165- wsScheme = 'wss' ;
166- }
167- if ( devUrl . port ) {
168- port = parseInt ( devUrl . port , 10 ) ;
169- } else if ( devUrl . protocol === 'https:' ) {
170- port = 443 ;
171- }
172- } catch ( e ) { }
173- }
174-
175- const WebSocket = require ( '../WebSocket/WebSocket' ) . default ;
176- ws = new WebSocket ( wsScheme + '://' + host + ':' + port ) ;
177- ws . addEventListener ( 'close' , event => {
178- isWebSocketOpen = false ;
179- } ) ;
180- ws . addEventListener ( 'open' , event => {
181- isWebSocketOpen = true ;
182- } ) ;
183-
184- const {
185- isReloadAndProfileSupported,
186- isProfiling,
187- onReloadAndProfile,
188- onReloadAndProfileFlagsReset,
189- } = readReloadAndProfileConfig (
190- maybeReactDevToolsRuntimeSettingsModuleModule ,
191- ) ;
192- connectToDevTools ( {
193- isAppActive,
194- resolveRNStyle,
195- nativeStyleEditorValidAttributes : Object . keys (
196- ReactNativeStyleAttributes ,
197- ) ,
198- websocket : ws ,
199- onSettingsUpdated : handleReactDevToolsSettingsUpdate ,
200- isReloadAndProfileSupported,
201- isProfiling,
202- onReloadAndProfile,
203- onReloadAndProfileFlagsReset,
204- } ) ;
205- }
206- }
207-
208119 // 1. If React DevTools has already been opened and initialized in Fusebox, bindings survive reloads
209120 if ( global [ reactDevToolsFuseboxGlobalBindingName ] != null ) {
210121 disconnectBackendFromReactDevToolsInFuseboxIfNeeded ( ) ;
@@ -223,15 +134,6 @@ if (__DEV__) {
223134 }
224135 } ,
225136 ) ;
226-
227- // 3. Fallback to attempting to connect WS-based RDT frontend
228- const RCTNativeAppEventEmitter =
229- require ( '../EventEmitter/RCTNativeAppEventEmitter' ) . default ;
230- RCTNativeAppEventEmitter . addListener (
231- 'RCTDevMenuShown' ,
232- connectToWSBasedReactDevToolsFrontend ,
233- ) ;
234- connectToWSBasedReactDevToolsFrontend ( ) ; // Try connecting once on load
235137}
236138
237139function readReloadAndProfileConfig (
@@ -273,23 +175,3 @@ function readReloadAndProfileConfig(
273175 onReloadAndProfileFlagsReset,
274176 } ;
275177}
276-
277- /**
278- * This is a bad, no good, broken hack to get the host from a dev server URL for the purposes
279- * of connecting to the legacy React DevTools socket (for the standalone react-devtools package).
280- * It has too many bugs to list. Please don't use it in new code.
281- *
282- * The correct implementation would just be `return new URL(url).host`, but React Native does not
283- * ship with a spec-compliant `URL` class yet. Alternatively, this can be deleted when we delete
284- * `connectToWSBasedReactDevToolsFrontend`.
285- */
286- function guessHostFromDevServerUrl ( url : string ) : string {
287- const hopefullyHostAndPort = url
288- . replace ( / h t t p s ? : \/ \/ / , '' )
289- . replace ( / \/ $ / , '' ) ;
290- // IPv6 addresses contain colons, so the split(':') below will return garbage.
291- if ( hopefullyHostAndPort . includes ( ']' ) ) {
292- return hopefullyHostAndPort . split ( ']' ) [ 0 ] + ']' ;
293- }
294- return hopefullyHostAndPort . split ( ':' ) [ 0 ] ;
295- }
0 commit comments