Index: chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java |
index 2fd4a0bf6734014bac14b03cb18a931b7452f7fe..6abb0d6e75ae6cb9bc9a2b813eac4e028b0cf4ec 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastSession.java |
@@ -306,13 +306,6 @@ public class CastSession implements MediaNotificationListener { |
}); |
} |
- public void sendStringMessage(String message, int callbackId) { |
- if (handleInternalMessage(message, callbackId)) return; |
- |
- // TODO(avayvod): figure out what to do with custom namespace messages. |
- mRouteProvider.onMessageSentResult(false, callbackId); |
- } |
- |
public String getSourceId() { |
return mSource.getUrn(); |
} |
@@ -321,6 +314,13 @@ public class CastSession implements MediaNotificationListener { |
return mCastDevice.getDeviceId(); |
} |
+ public void onClientConnected(String clientId) { |
+ sendClientMessageTo( |
+ clientId, "new_session", buildSessionMessage(), INVALID_SEQUENCE_NUMBER); |
+ |
+ if (mMediaPlayer != null && !isApiClientInvalid()) mMediaPlayer.requestStatus(mApiClient); |
+ } |
+ |
///////////////////////////////////////////////////////////////////////////////////////////// |
// MediaNotificationListener implementation. |
@@ -432,55 +432,18 @@ public class CastSession implements MediaNotificationListener { |
} |
} |
- private boolean handleInternalMessage(String message, int callbackId) { |
- Log.d(TAG, "Received message from client: %s", message); |
- boolean success = true; |
- try { |
- JSONObject jsonMessage = new JSONObject(message); |
- |
- String messageType = jsonMessage.getString("type"); |
- if ("client_connect".equals(messageType)) { |
- success = handleClientConnectMessage(jsonMessage); |
- } else if ("client_disconnect".equals(messageType)) { |
- success = handleClientDisconnectMessage(jsonMessage); |
- } else if ("leave_session".equals(messageType)) { |
- success = handleLeaveSessionMessage(jsonMessage); |
- } else if ("v2_message".equals(messageType)) { |
- success = handleCastV2Message(jsonMessage); |
- } else if ("app_message".equals(messageType)) { |
- success = handleAppMessage(jsonMessage); |
- } else { |
- Log.e(TAG, "Unsupported message: %s", message); |
- return false; |
- } |
- } catch (JSONException e) { |
- Log.e(TAG, "JSONException while handling internal message: " + e); |
+ public boolean handleSessionMessage( |
+ JSONObject message, String messageType) throws JSONException { |
+ if ("leave_session".equals(messageType)) { |
+ return handleLeaveSessionMessage(message); |
+ } else if ("v2_message".equals(messageType)) { |
+ return handleCastV2Message(message); |
+ } else if ("app_message".equals(messageType)) { |
+ return handleAppMessage(message); |
+ } else { |
+ Log.e(TAG, "Unsupported message: %s", message); |
return false; |
} |
- |
- mRouteProvider.onMessageSentResult(success, callbackId); |
- return true; |
- } |
- |
- private boolean handleClientConnectMessage(JSONObject jsonMessage) throws JSONException { |
- String clientId = jsonMessage.getString("clientId"); |
- if (clientId == null || !mRouteProvider.getClients().contains(clientId)) return false; |
- |
- sendClientMessageTo( |
- clientId, "new_session", buildSessionMessage(), INVALID_SEQUENCE_NUMBER); |
- |
- if (mMediaPlayer != null && !isApiClientInvalid()) mMediaPlayer.requestStatus(mApiClient); |
- |
- return true; |
- } |
- |
- private boolean handleClientDisconnectMessage(JSONObject jsonMessage) throws JSONException { |
- String clientId = jsonMessage.getString("clientId"); |
- if (clientId == null || !mRouteProvider.getClients().contains(clientId)) return false; |
- |
- mRouteProvider.onClientDisconnected(clientId); |
- |
- return true; |
} |
// An example of the leave_session message. |
@@ -766,8 +729,6 @@ public class CastSession implements MediaNotificationListener { |
Log.e(TAG, "Failed to build the reply: " + e); |
} |
- Log.d(TAG, "Sending message to client: " + json); |
- |
return json.toString(); |
} |