Refactor the packager server for further protocol changes

Reviewed By: cwdick

Differential Revision: D4543321

fbshipit-source-id: f7d5823b0d340f8ca17b3dd6caf4e158fa918bcf
This commit is contained in:
Lukas Piatkowski
2017-02-14 09:37:35 -08:00
committed by Facebook Github Bot
parent e28a12c613
commit d8f48d1b51
3 changed files with 78 additions and 24 deletions

View File

@@ -719,9 +719,7 @@ public class DevSupportManagerImpl implements
Toast.LENGTH_LONG).show();
if (responder != null) {
// Responder is provided, so there is a client waiting our response
responder.respond(result == null
? "{\"target\":\"profiler\", \"action\":\"started\"}"
: result);
responder.respond(result == null ? "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

View File

@@ -34,9 +34,13 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
mId = id;
}
public void respond(String result) {
public void respond(Object result) {
try {
mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, result));
JSONObject message = new JSONObject();
message.put("version", PROTOCOL_VERSION);
message.put("target", "profiler");
message.put("action", result);
mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, message.toString()));
} catch (Exception e) {
FLog.e(TAG, "Responding failed", e);
}
@@ -45,6 +49,7 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
public void error(Object error) {
try {
JSONObject message = new JSONObject();
message.put("version", PROTOCOL_VERSION);
message.put("id", mId);
message.put("error", error);
mWebSocket.sendMessage(RequestBody.create(WebSocket.TEXT, message.toString()));