diff --git a/React/DevSupport/RCTInspectorDevServerHelper.mm b/React/DevSupport/RCTInspectorDevServerHelper.mm index 4ba004d51bb3d3..13098d16a59513 100644 --- a/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -128,7 +128,7 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL NSString *key = [inspectorURL absoluteString]; RCTInspectorPackagerConnection *connection = socketConnections[key]; - if (!connection) { + if (!connection || !connection.isConnected) { connection = [[RCTInspectorPackagerConnection alloc] initWithURL:inspectorURL]; socketConnections[key] = connection; [connection connect]; diff --git a/React/Inspector/RCTInspectorPackagerConnection.h b/React/Inspector/RCTInspectorPackagerConnection.h index 1dfba9d369f0b4..6fe57a441d2992 100644 --- a/React/Inspector/RCTInspectorPackagerConnection.h +++ b/React/Inspector/RCTInspectorPackagerConnection.h @@ -20,6 +20,7 @@ typedef RCTBundleStatus *(^RCTBundleStatusProvider)(void); @interface RCTInspectorPackagerConnection : NSObject - (instancetype)initWithURL:(NSURL *)url; +- (bool)isConnected; - (void)connect; - (void)closeQuietly; - (void)sendEventToAllConnections:(NSString *)event; diff --git a/React/Inspector/RCTInspectorPackagerConnection.m b/React/Inspector/RCTInspectorPackagerConnection.m index 36dfdae2638770..5da2e858f102d0 100644 --- a/React/Inspector/RCTInspectorPackagerConnection.m +++ b/React/Inspector/RCTInspectorPackagerConnection.m @@ -241,6 +241,11 @@ - (void)webSocket:(__unused RCTSRWebSocket *)webSocket didCloseWithCode:(__unuse } } +- (bool)isConnected +{ + return _webSocket != nil; +} + - (void)connect { if (_closed) {