Skip to content

Commit

Permalink
Fixed issue with parsing media command responses in webOS, fixes #109
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy White committed Jun 20, 2014
1 parent fdffb59 commit 92030f5
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/com/connectsdk/service/sessions/WebOSWebAppSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,16 @@ public Boolean onReceiveMessage(JSONObject payload) {
JSONObject messageJSON = (JSONObject) message;

String contentType = messageJSON.optString("contentType");
Integer contentTypeIndex = contentType.lastIndexOf("connectsdk.");
Integer contentTypeIndex = contentType.indexOf("connectsdk.");

if (contentType != null && contentTypeIndex >= 0)
{
String payloadKey = contentType.substring(contentTypeIndex);
String payloadKey = contentType.split("connectsdk.")[1];

if (payloadKey == null || payloadKey.length() == 0)
return false;

JSONObject messagePayload = messageJSON.optJSONObject("payloadKey");
JSONObject messagePayload = messageJSON.optJSONObject(payloadKey);

if (messagePayload == null)
return false;
Expand Down Expand Up @@ -396,7 +396,7 @@ public void sendMessage(final JSONObject message, final ResponseListener<Object>
sendP2PMessage(message, listener);
}

private void sendP2PMessage(Object message, final ResponseListener<Object> listener) {
private void sendP2PMessage(final Object message, final ResponseListener<Object> listener) {
JSONObject _payload = new JSONObject();

try {
Expand All @@ -416,7 +416,7 @@ private void sendP2PMessage(Object message, final ResponseListener<Object> liste
if (listener != null)
listener.onSuccess(null);
} else {
ResponseListener<Object> joinListener = new ResponseListener<Object>() {
ResponseListener<Object> connectListener = new ResponseListener<Object>() {

@Override
public void onError(ServiceCommandError error) {
Expand All @@ -426,14 +426,11 @@ public void onError(ServiceCommandError error) {

@Override
public void onSuccess(Object object) {
socket.sendMessage(payload, null);

if (listener != null)
listener.onSuccess(null);
sendP2PMessage(message, listener);
}
};

join(joinListener);
connect(connectListener);
}
}

Expand Down Expand Up @@ -732,11 +729,11 @@ public void onSuccess(Object object) {
}
};

ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(null, null, null, response);
ServiceCommand<ResponseListener<Object>> command = new ServiceCommand<ResponseListener<Object>>(socket, null, null, response);

mActiveCommands.put(requestId, command);

sendMessage(message, new ResponseListener<Object>() {
sendP2PMessage(message, new ResponseListener<Object>() {

@Override
public void onError(ServiceCommandError error) {
Expand Down

0 comments on commit 92030f5

Please sign in to comment.