Skip to content

Commit

Permalink
Reconnect to debugger after reload
Browse files Browse the repository at this point in the history
Summary:
This diff allows re-connecting to the debugger websocket after reloading so that if, for example, metro has restarted, we'll reconnect to allow for debugging. Previously you would need to kill the app and re-open it to re-register the debugger websocket.

Changelog: [iOS] [Fixed] Reconnect to debugger websocket after metro is restarted.

Reviewed By: motiz88

Differential Revision: D18820399

fbshipit-source-id: ddbfa4476e70a6313c877a050ef2d77c04d1657e
  • Loading branch information
rickhanlonii authored and facebook-github-bot committed Dec 6, 2019
1 parent d9deee2 commit 13992f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion React/DevSupport/RCTInspectorDevServerHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions React/Inspector/RCTInspectorPackagerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions React/Inspector/RCTInspectorPackagerConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ - (void)webSocket:(__unused RCTSRWebSocket *)webSocket didCloseWithCode:(__unuse
}
}

- (bool)isConnected
{
return _webSocket != nil;
}

- (void)connect
{
if (_closed) {
Expand Down

0 comments on commit 13992f9

Please sign in to comment.