mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 03:50:11 +08:00
Introducing Responder and JSONObject to JSPackagerClient
Reviewed By: cwdick Differential Revision: D4537115 fbshipit-source-id: 61ee03d3e700bbee8b1cdb02bbf31a8491ca7891
This commit is contained in:
committed by
Facebook Github Bot
parent
47616d84d8
commit
e28a12c613
@@ -31,7 +31,6 @@ import com.facebook.react.common.network.OkHttpCallUtil;
|
||||
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
||||
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
|
||||
import com.facebook.react.packagerconnection.JSPackagerClient;
|
||||
import com.facebook.react.packagerconnection.ReconnectingWebSocket;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
@@ -89,7 +88,7 @@ public class DevServerHelper {
|
||||
public interface PackagerCommandListener {
|
||||
void onPackagerReloadCommand();
|
||||
void onCaptureHeapCommand();
|
||||
void onPokeSamplingProfilerCommand(@Nullable final ReconnectingWebSocket.WebSocketSender webSocket);
|
||||
void onPokeSamplingProfilerCommand(@Nullable final JSPackagerClient.Responder responder);
|
||||
}
|
||||
|
||||
private final DevInternalSettings mSettings;
|
||||
@@ -121,28 +120,25 @@ public class DevServerHelper {
|
||||
}
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
protected Void doInBackground(Void... backgroundParams) {
|
||||
Map<String, JSPackagerClient.RequestHandler> handlers =
|
||||
new HashMap<String, JSPackagerClient.RequestHandler>();
|
||||
handlers.put("reload", new JSPackagerClient.RequestHandler() {
|
||||
handlers.put("reload", new JSPackagerClient.NotificationOnlyHandler() {
|
||||
@Override
|
||||
public void onNotification(
|
||||
@Nullable ReconnectingWebSocket.WebSocketSender webSocket) {
|
||||
public void onNotification(@Nullable Object params) {
|
||||
commandListener.onPackagerReloadCommand();
|
||||
}
|
||||
});
|
||||
handlers.put("captureHeap", new JSPackagerClient.RequestHandler() {
|
||||
handlers.put("captureHeap", new JSPackagerClient.NotificationOnlyHandler() {
|
||||
@Override
|
||||
public void onNotification(
|
||||
@Nullable ReconnectingWebSocket.WebSocketSender webSocket) {
|
||||
public void onNotification(@Nullable Object params) {
|
||||
commandListener.onCaptureHeapCommand();
|
||||
}
|
||||
});
|
||||
handlers.put("pokeSamplingProfiler", new JSPackagerClient.RequestHandler() {
|
||||
handlers.put("pokeSamplingProfiler", new JSPackagerClient.RequestOnlyHandler() {
|
||||
@Override
|
||||
public void onNotification(
|
||||
@Nullable ReconnectingWebSocket.WebSocketSender webSocket) {
|
||||
commandListener.onPokeSamplingProfilerCommand(webSocket);
|
||||
public void onRequest(@Nullable Object params, JSPackagerClient.Responder responder) {
|
||||
commandListener.onPokeSamplingProfilerCommand(responder);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -56,13 +56,12 @@ import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
||||
import com.facebook.react.devsupport.interfaces.StackFrame;
|
||||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
||||
import com.facebook.react.packagerconnection.ReconnectingWebSocket;
|
||||
import com.facebook.react.packagerconnection.JSPackagerClient;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ws.WebSocket;
|
||||
|
||||
/**
|
||||
* Interface for accessing and interacting with development features. Following features
|
||||
@@ -693,12 +692,11 @@ public class DevSupportManagerImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPokeSamplingProfilerCommand(
|
||||
@Nullable final ReconnectingWebSocket.WebSocketSender webSocket) {
|
||||
public void onPokeSamplingProfilerCommand(@Nullable final JSPackagerClient.Responder responder) {
|
||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handlePokeSamplingProfiler(webSocket);
|
||||
handlePokeSamplingProfiler(responder);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -709,8 +707,7 @@ public class DevSupportManagerImpl implements
|
||||
JSCHeapUpload.captureCallback(mDevServerHelper.getHeapCaptureUploadUrl()));
|
||||
}
|
||||
|
||||
private void handlePokeSamplingProfiler(
|
||||
@Nullable ReconnectingWebSocket.WebSocketSender webSocket) {
|
||||
private void handlePokeSamplingProfiler(@Nullable final JSPackagerClient.Responder responder) {
|
||||
try {
|
||||
List<String> pokeResults = JSCSamplingProfiler.poke(60000);
|
||||
for (String result : pokeResults) {
|
||||
@@ -720,14 +717,11 @@ public class DevSupportManagerImpl implements
|
||||
? "Started JSC Sampling Profiler"
|
||||
: "Stopped JSC Sampling Profiler",
|
||||
Toast.LENGTH_LONG).show();
|
||||
if (webSocket != null) {
|
||||
// WebSocket is provided, so there is a client waiting our response
|
||||
webSocket.sendMessage(
|
||||
RequestBody.create(
|
||||
WebSocket.TEXT,
|
||||
result == null
|
||||
? "{\"target\":\"profiler\", \"action\":\"started\"}"
|
||||
: result));
|
||||
if (responder != null) {
|
||||
// Responder is provided, so there is a client waiting our response
|
||||
responder.respond(result == null
|
||||
? "{\"target\":\"profiler\", \"action\":\"started\"}"
|
||||
: result);
|
||||
} else if (result != null) {
|
||||
// The profile was not initiated by external client, so process the
|
||||
// profile if there is one in the result
|
||||
@@ -738,8 +732,6 @@ public class DevSupportManagerImpl implements
|
||||
}
|
||||
} catch (JSCSamplingProfiler.ProfilerException e) {
|
||||
showNewJavaError(e.getMessage(), e);
|
||||
} catch (IOException e) {
|
||||
showNewJavaError(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user