From 09fe7add4d8b3c95e32292b36a19176417a5affe Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 27 Oct 2020 09:58:28 -0400 Subject: [PATCH] Make DevTools Websocket retry delay configurable --- packages/react-devtools-core/README.md | 1 + packages/react-devtools-core/src/backend.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-core/README.md b/packages/react-devtools-core/README.md index 9b0963de9310e..39a42bbfdad10 100644 --- a/packages/react-devtools-core/README.md +++ b/packages/react-devtools-core/README.md @@ -24,6 +24,7 @@ The `config` object may contain: * `useHttps: boolean` (defaults to `false`) - Websocked should use a secure protocol (wss). * `websocket: Websocket` - Custom websocket to use. Overrides `host` and `port` settings if provided. * `resolveRNStyle: (style: number) => ?Object` - Used by the React Native style plug-in. +* `retryConnectionDelay: number` (defaults to `2000`) - Milliseconds delay to wait between retrying a failed Websocket connection. * `isAppActive: () => boolean` - If provided, DevTools will poll this method and wait until it returns true before connecting to React. ## `react-devtools-core/standalone` diff --git a/packages/react-devtools-core/src/backend.js b/packages/react-devtools-core/src/backend.js index 6581101b5b977..b63cd13006e3d 100644 --- a/packages/react-devtools-core/src/backend.js +++ b/packages/react-devtools-core/src/backend.js @@ -26,6 +26,7 @@ type ConnectOptions = { port?: number, useHttps?: boolean, resolveRNStyle?: ResolveNativeStyle, + retryConnectionDelay?: number, isAppActive?: () => boolean, websocket?: ?WebSocket, ... @@ -60,6 +61,7 @@ export function connectToDevTools(options: ?ConnectOptions) { port = 8097, websocket, resolveRNStyle = null, + retryConnectionDelay = 2000, isAppActive = () => true, } = options || {}; @@ -69,7 +71,10 @@ export function connectToDevTools(options: ?ConnectOptions) { function scheduleRetry() { if (retryTimeoutID === null) { // Two seconds because RN had issues with quick retries. - retryTimeoutID = setTimeout(() => connectToDevTools(options), 2000); + retryTimeoutID = setTimeout( + () => connectToDevTools(options), + retryConnectionDelay, + ); } }