Permalink
Browse files

Force the debugger to disconnect before a bundle reload

Reviewed By: bnham

Differential Revision: D5594238

fbshipit-source-id: feff9f179534c8e617f8fa7c8a7b1bc525c07cae
  • Loading branch information...
pakoito authored and facebook-github-bot committed Aug 14, 2017
1 parent f11f001 commit 41504103ceecbaa2d6659c42bb99a07960472fcb
@@ -25,6 +25,8 @@
- (instancetype)initWithURL:(NSURL *)url;
@property (nonatomic, weak) id<RCTWebSocketProtocolDelegate> delegate;
/** @brief Must be set before -start to have effect */
@property (nonatomic, strong) dispatch_queue_t delegateDispatchQueue;
- (void)send:(id)data;
- (void)start;
- (void)stop;
@@ -70,7 +70,9 @@ - (void)start
[self stop];
_socket = [[RCTSRWebSocket alloc] initWithURL:_url];
_socket.delegate = self;
if (_delegateDispatchQueue) {
[_socket setDelegateDispatchQueue:_delegateDispatchQueue];
}
[_socket open];
}
@@ -20,6 +20,7 @@
@interface RCTWebSocketObserver : NSObject
- (instancetype)initWithURL:(NSURL *)url;
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue;
@property (nonatomic, weak) id<RCTWebSocketObserverDelegate> delegate;
@@ -36,6 +36,11 @@ - (instancetype)initWithURL:(NSURL *)url
return self;
}
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue
{
[_socket setDelegateDispatchQueue:queue];
}
- (void)start
{
_socket.delegate = self;
View
@@ -14,6 +14,7 @@
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "RCTInspectorDevServerHelper.h"
#import "RCTJSEnvironment.h"
#import "RCTLog.h"
#import "RCTModuleData.h"
@@ -252,6 +253,11 @@ - (void)whitelistedModulesDidChange
- (void)reload
{
#if ENABLE_INSPECTOR
// Disable debugger to resume the JsVM & avoid thread locks while reloading
[RCTInspectorDevServerHelper disableDebugger];
#endif
/**
* Any thread
*/
@@ -10,6 +10,7 @@
+ (void)connectForContext:(JSGlobalContextRef)context
withBundleURL:(NSURL *)bundleURL;
+ (void)disableDebugger;
@end
#endif
@@ -10,6 +10,8 @@
using namespace facebook::react;
static NSString *const kDebuggerMsgDisable = @"{ \"id\":1,\"method\":\"Debugger.disable\" }";
static NSString *getDebugServerHost(NSURL *bundleURL)
{
NSString *host = [bundleURL host];
@@ -43,6 +45,20 @@ @implementation RCTInspectorDevServerHelper
RCT_NOT_IMPLEMENTED(- (instancetype)init)
static NSMutableDictionary<NSString *, RCTInspectorPackagerConnection *> *socketConnections = nil;
static void sendEventToAllConnections(NSString *event)
{
for (NSString *socketId in socketConnections) {
[socketConnections[socketId] sendEventToAllConnections:event];
}
}
+ (void)disableDebugger
{
sendEventToAllConnections(kDebuggerMsgDisable);
}
+ (void)connectForContext:(JSGlobalContextRef)context
withBundleURL:(NSURL *)bundleURL
{
@@ -55,7 +71,6 @@ + (void)connectForContext:(JSGlobalContextRef)context
// Note, using a static dictionary isn't really the greatest design, but
// the packager connection does the same thing, so it's at least consistent.
// This is a static map that holds different inspector clients per the inspectorURL
static NSMutableDictionary<NSString *, RCTInspectorPackagerConnection *> *socketConnections = nil;
if (socketConnections == nil) {
socketConnections = [NSMutableDictionary new];
}
@@ -10,6 +10,7 @@
- (instancetype)initWithURL:(NSURL *)url;
- (void)connect;
- (void)closeQuietly;
- (void)sendEventToAllConnections:(NSString *)event;
- (void)sendOpenEvent:(NSString *)pageId;
@end
@@ -74,6 +74,13 @@ - (void)handleProxyMessage:(NSDictionary<NSString *, id> *)message
}
}
- (void)sendEventToAllConnections:(NSString *)event
{
for (NSString *pageId in _inspectorConnections) {
[_inspectorConnections[pageId] sendMessage:event];
}
}
- (void)closeAllConnections
{
for (NSString *pageId in _inspectorConnections){
@@ -90,6 +90,8 @@
private static final int LONG_POLL_FAILURE_DELAY_MS = 5000;
private static final int HTTP_CONNECT_TIMEOUT_MS = 5000;
private static final String DEBUGGER_MSG_DISABLE = "{ \"id\":1,\"method\":\"Debugger.disable\" }";
public interface OnServerContentChangeListener {
void onServerContentChanged();
}
@@ -211,6 +213,18 @@ public void openInspector(String id) {
}
}
public void sendEventToAllConnections(String event) {
if (mInspectorPackagerConnection != null) {
mInspectorPackagerConnection.sendEventToAllConnections(event);
}
}
public void disableDebugger() {
if (mInspectorPackagerConnection != null) {
mInspectorPackagerConnection.sendEventToAllConnections(DEBUGGER_MSG_DISABLE);
}
}
public void closeInspectorConnection() {
new AsyncTask<Void, Void, Void>() {
@Override
@@ -679,6 +679,8 @@ public void isPackagerRunning(PackagerStatusCallback callback) {
@Override
public void onPackagerReloadCommand() {
// Disable debugger to resume the JsVM & avoid thread locks while reloading
mDevServerHelper.disableDebugger();
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import android.os.AsyncTask;
@@ -47,6 +48,14 @@ public void closeQuietly() {
mConnection.close();
}
public void sendEventToAllConnections(String event) {
for (Map.Entry<String, Inspector.LocalConnection> inspectorConnectionEntry :
mInspectorConnections.entrySet()) {
Inspector.LocalConnection inspectorConnection = inspectorConnectionEntry.getValue();
inspectorConnection.sendMessage(event);
}
}
public void sendOpenEvent(String pageId) {
try {
JSONObject payload = makePageIdPayload(pageId);

0 comments on commit 4150410

Please sign in to comment.