Adjusted code in order to broadcast internally responses with empty results, which were skipped before
This commit is contained in:
parent
7e2ef7b705
commit
f8326093a2
1 changed files with 55 additions and 51 deletions
|
@ -256,72 +256,77 @@ public class NetworkService extends Service {
|
||||||
public void onMessage(WebSocket webSocket, String text) {
|
public void onMessage(WebSocket webSocket, String text) {
|
||||||
super.onMessage(webSocket, text);
|
super.onMessage(webSocket, text);
|
||||||
Log.v(TAG,"<- "+text);
|
Log.v(TAG,"<- "+text);
|
||||||
JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class);
|
JsonRpcNotification notification = gson.fromJson(text, JsonRpcNotification.class);
|
||||||
|
|
||||||
// We will only handle messages that relate to the login and API accesses here.
|
if(notification.method != null){
|
||||||
if(response.result != null){
|
// If we are dealing with a notification
|
||||||
if(response.result instanceof Double || response.result instanceof Boolean){
|
handleJsonRpcNotification(notification);
|
||||||
if(mLastCall.equals(RPC.CALL_LOGIN)){
|
}else{
|
||||||
isLoggedIn = true;
|
// If we are dealing with a response
|
||||||
|
JsonRpcResponse<?> response = gson.fromJson(text, JsonRpcResponse.class);
|
||||||
|
if(response.result != null){
|
||||||
|
// Handling initial handshake with the full node (authentication and API access checks)
|
||||||
|
if(response.result instanceof Double || response.result instanceof Boolean){
|
||||||
|
switch (mLastCall) {
|
||||||
|
case RPC.CALL_LOGIN:
|
||||||
|
isLoggedIn = true;
|
||||||
|
|
||||||
// Broadcasting result
|
// Broadcasting result
|
||||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.AUTHENTICATED, ApiAccess.API_NONE));
|
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.AUTHENTICATED, ApiAccess.API_NONE));
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall.equals(RPC.CALL_DATABASE)){
|
break;
|
||||||
// Deserializing integer response
|
case RPC.CALL_DATABASE: {
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
// Deserializing integer response
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||||
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Storing the "database" api id
|
// Storing the "database" api id
|
||||||
mApiIds.put(ApiAccess.API_DATABASE, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_DATABASE, apiIdResponse.result);
|
||||||
|
|
||||||
// Broadcasting result
|
// Broadcasting result
|
||||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_DATABASE));
|
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_DATABASE));
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall.equals(RPC.CALL_HISTORY)){
|
break;
|
||||||
// Deserializing integer response
|
}
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
case RPC.CALL_HISTORY: {
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
// Deserializing integer response
|
||||||
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||||
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Broadcasting result
|
// Broadcasting result
|
||||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_HISTORY));
|
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_HISTORY));
|
||||||
|
|
||||||
// Storing the "history" api id
|
// Storing the "history" api id
|
||||||
mApiIds.put(ApiAccess.API_HISTORY, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_HISTORY, apiIdResponse.result);
|
||||||
|
|
||||||
checkNextRequestedApiAccess();
|
checkNextRequestedApiAccess();
|
||||||
}else if(mLastCall.equals(RPC.CALL_NETWORK_BROADCAST)){
|
break;
|
||||||
// Deserializing integer response
|
}
|
||||||
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>(){}.getType();
|
case RPC.CALL_NETWORK_BROADCAST:
|
||||||
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
// Deserializing integer response
|
||||||
|
Type IntegerJsonResponse = new TypeToken<JsonRpcResponse<Integer>>() {}.getType();
|
||||||
|
JsonRpcResponse<Integer> apiIdResponse = gson.fromJson(text, IntegerJsonResponse);
|
||||||
|
|
||||||
// Broadcasting result
|
// Broadcasting result
|
||||||
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_NETWORK_BROADCAST));
|
RxBus.getBusInstance().send(new ConnectionStatusUpdate(ConnectionStatusUpdate.API_UPDATE, ApiAccess.API_NETWORK_BROADCAST));
|
||||||
|
|
||||||
// Storing the "network_broadcast" api access
|
// Storing the "network_broadcast" api access
|
||||||
mApiIds.put(ApiAccess.API_NETWORK_BROADCAST, apiIdResponse.result);
|
mApiIds.put(ApiAccess.API_NETWORK_BROADCAST, apiIdResponse.result);
|
||||||
|
|
||||||
// All calls have been handled at this point
|
// All calls have been handled at this point
|
||||||
mLastCall = "";
|
mLastCall = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(response.error != null && response.error.message != null){
|
||||||
|
// We could not make sense of this incoming message, just log a warning
|
||||||
|
Log.w(TAG,"Error.Msg: "+response.error.message);
|
||||||
|
}
|
||||||
// Properly de-serialize all other fields and broadcasts to the event bus
|
// Properly de-serialize all other fields and broadcasts to the event bus
|
||||||
handleJsonRpcResponse(response, text);
|
handleJsonRpcResponse(response, text);
|
||||||
}else{
|
|
||||||
// If no 'result' field was found, this incoming message probably corresponds to a
|
|
||||||
// JSON-RPC notification message, which should have a 'method' field with the string
|
|
||||||
// 'notice' as its value
|
|
||||||
JsonRpcNotification notification = gson.fromJson(text, JsonRpcNotification.class);
|
|
||||||
if(notification.method != null && notification.method.equals("notice")){
|
|
||||||
handleJsonRpcNotification(notification);
|
|
||||||
}else{
|
|
||||||
if(response.error != null && response.error.message != null){
|
|
||||||
// We could not make sense of this incoming message, just log a warning
|
|
||||||
Log.w(TAG,"Error.Msg: "+response.error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +397,6 @@ public class NetworkService extends Service {
|
||||||
if(parsedResponse == null){
|
if(parsedResponse == null){
|
||||||
parsedResponse = response;
|
parsedResponse = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcasting the parsed response to all interested listeners
|
// Broadcasting the parsed response to all interested listeners
|
||||||
RxBus.getBusInstance().send(parsedResponse);
|
RxBus.getBusInstance().send(parsedResponse);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue