Force the debugger to disconnect before a bundle reload
Reviewed By: bnham Differential Revision: D5594238 fbshipit-source-id: feff9f179534c8e617f8fa7c8a7b1bc525c07cae
This commit is contained in:
parent
f11f00197d
commit
41504103ce
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
- (instancetype)initWithURL:(NSURL *)url;
|
- (instancetype)initWithURL:(NSURL *)url;
|
||||||
@property (nonatomic, weak) id<RCTWebSocketProtocolDelegate> delegate;
|
@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)send:(id)data;
|
||||||
- (void)start;
|
- (void)start;
|
||||||
- (void)stop;
|
- (void)stop;
|
||||||
|
|
|
@ -70,7 +70,9 @@ static void my_nwlog_legacy_v(int level, char *format, va_list args) {
|
||||||
[self stop];
|
[self stop];
|
||||||
_socket = [[RCTSRWebSocket alloc] initWithURL:_url];
|
_socket = [[RCTSRWebSocket alloc] initWithURL:_url];
|
||||||
_socket.delegate = self;
|
_socket.delegate = self;
|
||||||
|
if (_delegateDispatchQueue) {
|
||||||
|
[_socket setDelegateDispatchQueue:_delegateDispatchQueue];
|
||||||
|
}
|
||||||
[_socket open];
|
[_socket open];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
@interface RCTWebSocketObserver : NSObject
|
@interface RCTWebSocketObserver : NSObject
|
||||||
|
|
||||||
- (instancetype)initWithURL:(NSURL *)url;
|
- (instancetype)initWithURL:(NSURL *)url;
|
||||||
|
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue;
|
||||||
|
|
||||||
@property (nonatomic, weak) id<RCTWebSocketObserverDelegate> delegate;
|
@property (nonatomic, weak) id<RCTWebSocketObserverDelegate> delegate;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue
|
||||||
|
{
|
||||||
|
[_socket setDelegateDispatchQueue:queue];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)start
|
- (void)start
|
||||||
{
|
{
|
||||||
_socket.delegate = self;
|
_socket.delegate = self;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#import "RCTConvert.h"
|
#import "RCTConvert.h"
|
||||||
#import "RCTEventDispatcher.h"
|
#import "RCTEventDispatcher.h"
|
||||||
|
#import "RCTInspectorDevServerHelper.h"
|
||||||
#import "RCTJSEnvironment.h"
|
#import "RCTJSEnvironment.h"
|
||||||
#import "RCTLog.h"
|
#import "RCTLog.h"
|
||||||
#import "RCTModuleData.h"
|
#import "RCTModuleData.h"
|
||||||
|
@ -252,6 +253,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||||
|
|
||||||
- (void)reload
|
- (void)reload
|
||||||
{
|
{
|
||||||
|
#if ENABLE_INSPECTOR
|
||||||
|
// Disable debugger to resume the JsVM & avoid thread locks while reloading
|
||||||
|
[RCTInspectorDevServerHelper disableDebugger];
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any thread
|
* Any thread
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
+ (void)connectForContext:(JSGlobalContextRef)context
|
+ (void)connectForContext:(JSGlobalContextRef)context
|
||||||
withBundleURL:(NSURL *)bundleURL;
|
withBundleURL:(NSURL *)bundleURL;
|
||||||
|
+ (void)disableDebugger;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
using namespace facebook::react;
|
using namespace facebook::react;
|
||||||
|
|
||||||
|
static NSString *const kDebuggerMsgDisable = @"{ \"id\":1,\"method\":\"Debugger.disable\" }";
|
||||||
|
|
||||||
static NSString *getDebugServerHost(NSURL *bundleURL)
|
static NSString *getDebugServerHost(NSURL *bundleURL)
|
||||||
{
|
{
|
||||||
NSString *host = [bundleURL host];
|
NSString *host = [bundleURL host];
|
||||||
|
@ -43,6 +45,20 @@ static NSURL *getInspectorDeviceUrl(NSURL *bundleURL)
|
||||||
|
|
||||||
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
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
|
+ (void)connectForContext:(JSGlobalContextRef)context
|
||||||
withBundleURL:(NSURL *)bundleURL
|
withBundleURL:(NSURL *)bundleURL
|
||||||
{
|
{
|
||||||
|
@ -55,7 +71,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||||
// Note, using a static dictionary isn't really the greatest design, but
|
// 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.
|
// 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
|
// This is a static map that holds different inspector clients per the inspectorURL
|
||||||
static NSMutableDictionary<NSString *, RCTInspectorPackagerConnection *> *socketConnections = nil;
|
|
||||||
if (socketConnections == nil) {
|
if (socketConnections == nil) {
|
||||||
socketConnections = [NSMutableDictionary new];
|
socketConnections = [NSMutableDictionary new];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
- (instancetype)initWithURL:(NSURL *)url;
|
- (instancetype)initWithURL:(NSURL *)url;
|
||||||
- (void)connect;
|
- (void)connect;
|
||||||
- (void)closeQuietly;
|
- (void)closeQuietly;
|
||||||
|
- (void)sendEventToAllConnections:(NSString *)event;
|
||||||
- (void)sendOpenEvent:(NSString *)pageId;
|
- (void)sendOpenEvent:(NSString *)pageId;
|
||||||
@end
|
@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
|
- (void)closeAllConnections
|
||||||
{
|
{
|
||||||
for (NSString *pageId in _inspectorConnections){
|
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 LONG_POLL_FAILURE_DELAY_MS = 5000;
|
||||||
private static final int HTTP_CONNECT_TIMEOUT_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 {
|
public interface OnServerContentChangeListener {
|
||||||
void onServerContentChanged();
|
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() {
|
public void closeInspectorConnection() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -679,6 +679,8 @@ public class DevSupportManagerImpl implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPackagerReloadCommand() {
|
public void onPackagerReloadCommand() {
|
||||||
|
// Disable debugger to resume the JsVM & avoid thread locks while reloading
|
||||||
|
mDevServerHelper.disableDebugger();
|
||||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
@ -47,6 +48,14 @@ public class InspectorPackagerConnection {
|
||||||
mConnection.close();
|
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) {
|
public void sendOpenEvent(String pageId) {
|
||||||
try {
|
try {
|
||||||
JSONObject payload = makePageIdPayload(pageId);
|
JSONObject payload = makePageIdPayload(pageId);
|
||||||
|
|
Loading…
Reference in New Issue