Force the debugger to disconnect before a bundle reload

Reviewed By: bnham

Differential Revision: D5594238

fbshipit-source-id: feff9f179534c8e617f8fa7c8a7b1bc525c07cae
This commit is contained in:
Paco Estevez Garcia 2017-08-14 08:07:13 -07:00 коммит произвёл Facebook Github Bot
Родитель f11f00197d
Коммит 41504103ce
12 изменённых файлов: 67 добавлений и 2 удалений

Просмотреть файл

@ -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 @@ static void my_nwlog_legacy_v(int level, char *format, va_list args) {
[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 @@
return self;
}
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue
{
[_socket setDelegateDispatchQueue:queue];
}
- (void)start
{
_socket.delegate = self;

Просмотреть файл

@ -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 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (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 @@ static NSURL *getInspectorDeviceUrl(NSURL *bundleURL)
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 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
// 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 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
}
}
- (void)sendEventToAllConnections:(NSString *)event
{
for (NSString *pageId in _inspectorConnections) {
[_inspectorConnections[pageId] sendMessage:event];
}
}
- (void)closeAllConnections
{
for (NSString *pageId in _inspectorConnections){

Просмотреть файл

@ -90,6 +90,8 @@ public class DevServerHelper {
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 class DevServerHelper {
}
}
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 class DevSupportManagerImpl implements
@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.io.IOException;
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 class InspectorPackagerConnection {
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);