diff --git a/src/com/connectsdk/service/sessions/WebOSWebAppSession.java b/src/com/connectsdk/service/sessions/WebOSWebAppSession.java index 7e52946e..4012f79f 100644 --- a/src/com/connectsdk/service/sessions/WebOSWebAppSession.java +++ b/src/com/connectsdk/service/sessions/WebOSWebAppSession.java @@ -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; @@ -396,7 +396,7 @@ public void sendMessage(final JSONObject message, final ResponseListener sendP2PMessage(message, listener); } - private void sendP2PMessage(Object message, final ResponseListener listener) { + private void sendP2PMessage(final Object message, final ResponseListener listener) { JSONObject _payload = new JSONObject(); try { @@ -416,7 +416,7 @@ private void sendP2PMessage(Object message, final ResponseListener liste if (listener != null) listener.onSuccess(null); } else { - ResponseListener joinListener = new ResponseListener() { + ResponseListener connectListener = new ResponseListener() { @Override public void onError(ServiceCommandError error) { @@ -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); } } @@ -732,11 +729,11 @@ public void onSuccess(Object object) { } }; - ServiceCommand> command = new ServiceCommand>(null, null, null, response); + ServiceCommand> command = new ServiceCommand>(socket, null, null, response); mActiveCommands.put(requestId, command); - sendMessage(message, new ResponseListener() { + sendP2PMessage(message, new ResponseListener() { @Override public void onError(ServiceCommandError error) {