Removing old channel code from a few more places.

Plus adding peer connection close event.

R=jiayl@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/37509004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7982 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
glaznev@webrtc.org 2014-12-30 18:15:43 +00:00
parent a9b1ec0247
commit b2bda67497
7 changed files with 51 additions and 97 deletions

View File

@ -65,7 +65,6 @@ public interface AppRTCClient {
* Struct holding the signaling parameters of an AppRTC room. * Struct holding the signaling parameters of an AppRTC room.
*/ */
public class SignalingParameters { public class SignalingParameters {
public final boolean websocketSignaling;
public final List<PeerConnection.IceServer> iceServers; public final List<PeerConnection.IceServer> iceServers;
public final boolean initiator; public final boolean initiator;
public final MediaConstraints pcConstraints; public final MediaConstraints pcConstraints;
@ -74,7 +73,6 @@ public interface AppRTCClient {
public final String roomUrl; public final String roomUrl;
public final String roomId; public final String roomId;
public final String clientId; public final String clientId;
public final String channelToken;
public final String wssUrl; public final String wssUrl;
public final String wssPostUrl; public final String wssPostUrl;
public final SessionDescription offerSdp; public final SessionDescription offerSdp;
@ -85,7 +83,7 @@ public interface AppRTCClient {
boolean initiator, MediaConstraints pcConstraints, boolean initiator, MediaConstraints pcConstraints,
MediaConstraints videoConstraints, MediaConstraints audioConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints,
String roomUrl, String roomId, String clientId, String roomUrl, String roomId, String clientId,
String wssUrl, String wssPostUrl, String channelToken, String wssUrl, String wssPostUrl,
SessionDescription offerSdp, List<IceCandidate> iceCandidates) { SessionDescription offerSdp, List<IceCandidate> iceCandidates) {
this.iceServers = iceServers; this.iceServers = iceServers;
this.initiator = initiator; this.initiator = initiator;
@ -97,14 +95,8 @@ public interface AppRTCClient {
this.clientId = clientId; this.clientId = clientId;
this.wssUrl = wssUrl; this.wssUrl = wssUrl;
this.wssPostUrl = wssPostUrl; this.wssPostUrl = wssPostUrl;
this.channelToken = channelToken;
this.offerSdp = offerSdp; this.offerSdp = offerSdp;
this.iceCandidates = iceCandidates; this.iceCandidates = iceCandidates;
if (channelToken == null || channelToken.length() == 0) {
this.websocketSignaling = true;
} else {
this.websocketSignaling = false;
}
} }
} }
@ -120,12 +112,6 @@ public interface AppRTCClient {
*/ */
public void onConnectedToRoom(final SignalingParameters params); public void onConnectedToRoom(final SignalingParameters params);
/**
* Callback fired once channel for signaling messages is opened and
* ready to receive messages.
*/
public void onChannelOpen();
/** /**
* Callback fired once remote SDP is received. * Callback fired once remote SDP is received.
*/ */

View File

@ -513,14 +513,6 @@ public class AppRTCDemoActivity extends Activity
}; };
videoView.postDelayed(repeatedStatsLogger, 1000); videoView.postDelayed(repeatedStatsLogger, 1000);
logAndToast("Waiting for remote connection...");
}
@Override
public void onChannelOpen() {
if (pc == null) {
return;
}
if (signalingParameters.initiator) { if (signalingParameters.initiator) {
logAndToast("Creating OFFER..."); logAndToast("Creating OFFER...");
// Create offer. Offer SDP will be sent to answering client in // Create offer. Offer SDP will be sent to answering client in
@ -600,6 +592,10 @@ public class AppRTCDemoActivity extends Activity
disconnect(); disconnect();
} }
@Override
public void onPeerConnectionClosed() {
}
@Override @Override
public void onPeerConnectionError(String description) { public void onPeerConnectionError(String description) {
if (!isError) { if (!isError) {

View File

@ -69,7 +69,6 @@ public class ConnectActivity extends Activity {
public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME"; public static final String EXTRA_RUNTIME = "org.appspot.apprtc.RUNTIME";
public static final String EXTRA_BITRATE = "org.appspot.apprtc.BITRATE"; public static final String EXTRA_BITRATE = "org.appspot.apprtc.BITRATE";
public static final String EXTRA_HWCODEC = "org.appspot.apprtc.HWCODEC"; public static final String EXTRA_HWCODEC = "org.appspot.apprtc.HWCODEC";
public static final String EXTRA_WEBSOCKET = "org.appspot.apprtc.WEBSOCKET";
private static final String TAG = "ConnectRTCClient"; private static final String TAG = "ConnectRTCClient";
private final int CONNECTION_REQUEST = 1; private final int CONNECTION_REQUEST = 1;
private static boolean commandLineRun = false; private static boolean commandLineRun = false;

View File

@ -246,6 +246,8 @@ public class PeerConnectionClient {
factory.dispose(); factory.dispose();
factory = null; factory = null;
} }
Log.d(TAG, "Closing peer connection done.");
events.onPeerConnectionClosed();
} }
}); });
} }
@ -276,10 +278,16 @@ public class PeerConnectionClient {
*/ */
public void onIceDisconnected(); public void onIceDisconnected();
/**
* Callback fired once peer connection is closed.
*/
public void onPeerConnectionClosed();
/** /**
* Callback fired once peer connection error happened. * Callback fired once peer connection error happened.
*/ */
public void onPeerConnectionError(String description); public void onPeerConnectionError(String description);
} }
private void reportError(final String errorMessage) { private void reportError(final String errorMessage) {

View File

@ -53,7 +53,6 @@ public class RoomParametersFetcher
private static final String TAG = "RoomRTCClient"; private static final String TAG = "RoomRTCClient";
private Exception exception = null; private Exception exception = null;
private RoomParametersFetcherEvents events = null; private RoomParametersFetcherEvents events = null;
private boolean useNewSignaling;
private boolean loopback; private boolean loopback;
/** /**
@ -73,10 +72,9 @@ public class RoomParametersFetcher
} }
public RoomParametersFetcher(RoomParametersFetcherEvents events, public RoomParametersFetcher(RoomParametersFetcherEvents events,
boolean useNewSignaling, boolean loopback) { boolean loopback) {
super(); super();
this.events = events; this.events = events;
this.useNewSignaling = useNewSignaling;
this.loopback = loopback; this.loopback = loopback;
} }
@ -119,22 +117,11 @@ public class RoomParametersFetcher
// Fetches |url| and fishes the signaling parameters out of the JSON. // Fetches |url| and fishes the signaling parameters out of the JSON.
private SignalingParameters getParametersForRoomUrl(String url) private SignalingParameters getParametersForRoomUrl(String url)
throws IOException, JSONException { throws IOException, JSONException {
if (!useNewSignaling) {
if (url.contains("?")) {
url += "&t=json";
} else {
url += "?t=json";
}
}
Log.d(TAG, "Connecting to room: " + url); Log.d(TAG, "Connecting to room: " + url);
HttpURLConnection connection = HttpURLConnection connection =
(HttpURLConnection) new URL(url).openConnection(); (HttpURLConnection) new URL(url).openConnection();
if (useNewSignaling) { connection.setDoOutput(true);
connection.setDoOutput(true); connection.setRequestMethod("POST");
connection.setRequestMethod("POST");
} else {
connection.setRequestMethod("GET");
}
connection.setDoInput(true); connection.setDoInput(true);
InputStream responseStream = connection.getInputStream(); InputStream responseStream = connection.getInputStream();
@ -142,64 +129,44 @@ public class RoomParametersFetcher
responseStream.close(); responseStream.close();
Log.d(TAG, "Room response: " + response); Log.d(TAG, "Room response: " + response);
JSONObject roomJson = new JSONObject(response); JSONObject roomJson = new JSONObject(response);
String roomId;
String clientId;
String roomUrl;
String channelToken = "";
String wssUrl = "";
String wssPostUrl = "";
boolean initiator;
LinkedList<IceCandidate> iceCandidates = null; LinkedList<IceCandidate> iceCandidates = null;
SessionDescription offerSdp = null; SessionDescription offerSdp = null;
if (useNewSignaling) { String result = roomJson.getString("result");
String result = roomJson.getString("result"); if (!result.equals("SUCCESS")) {
if (!result.equals("SUCCESS")) { throw new JSONException(result);
throw new JSONException(result); }
} response = roomJson.getString("params");
response = roomJson.getString("params"); roomJson = new JSONObject(response);
roomJson = new JSONObject(response); String roomId = roomJson.getString("room_id");
roomId = roomJson.getString("room_id"); String clientId = roomJson.getString("client_id");
clientId = roomJson.getString("client_id"); String wssUrl = roomJson.getString("wss_url");
wssUrl = roomJson.getString("wss_url"); String wssPostUrl = roomJson.getString("wss_post_url");
wssPostUrl = roomJson.getString("wss_post_url"); boolean initiator = (roomJson.getBoolean("is_initiator"));
initiator = (roomJson.getBoolean("is_initiator")); String roomUrl = url.substring(0, url.indexOf("/register"));
roomUrl = url.substring(0, url.indexOf("/register")); if (!initiator) {
if (!initiator) { iceCandidates = new LinkedList<IceCandidate>();
iceCandidates = new LinkedList<IceCandidate>(); String messagesString = roomJson.getString("messages");
String messagesString = roomJson.getString("messages"); JSONArray messages = new JSONArray(messagesString);
JSONArray messages = new JSONArray(messagesString); for (int i = 0; i < messages.length(); ++i) {
for (int i = 0; i < messages.length(); ++i) { String messageString = messages.getString(i);
String messageString = messages.getString(i); JSONObject message = new JSONObject(messageString);
JSONObject message = new JSONObject(messageString); String messageType = message.getString("type");
String messageType = message.getString("type"); Log.d(TAG, "GAE->C #" + i + " : " + messageString);
Log.d(TAG, "GAE->C #" + i + " : " + messageString); if (messageType.equals("offer")) {
if (messageType.equals("offer")) { offerSdp = new SessionDescription(
offerSdp = new SessionDescription( SessionDescription.Type.fromCanonicalForm(messageType),
SessionDescription.Type.fromCanonicalForm(messageType), message.getString("sdp"));
message.getString("sdp")); } else if (messageType.equals("candidate")) {
} else if (messageType.equals("candidate")) { IceCandidate candidate = new IceCandidate(
IceCandidate candidate = new IceCandidate( message.getString("id"),
message.getString("id"), message.getInt("label"),
message.getInt("label"), message.getString("candidate"));
message.getString("candidate")); iceCandidates.add(candidate);
iceCandidates.add(candidate); } else {
} else { Log.e(TAG, "Unknown message: " + messageString);
Log.e(TAG, "Unknown message: " + messageString);
}
} }
} }
} else {
if (roomJson.has("error")) {
JSONArray errors = roomJson.getJSONArray("error_messages");
throw new IOException(errors.toString());
}
roomId = roomJson.getString("room_key");
clientId = roomJson.getString("me");
channelToken = roomJson.optString("token");
initiator = (roomJson.getInt("initiator") == 1);
roomUrl = url.substring(0, url.indexOf('?'));
} }
Log.d(TAG, "RoomId: " + roomId + ". ClientId: " + clientId); Log.d(TAG, "RoomId: " + roomId + ". ClientId: " + clientId);
@ -242,7 +209,7 @@ public class RoomParametersFetcher
iceServers, initiator, iceServers, initiator,
pcConstraints, videoConstraints, audioConstraints, pcConstraints, videoConstraints, audioConstraints,
roomUrl, roomId, clientId, roomUrl, roomId, clientId,
wssUrl, wssPostUrl, channelToken, wssUrl, wssPostUrl,
offerSdp, iceCandidates); offerSdp, iceCandidates);
} }

View File

@ -26,7 +26,6 @@
*/ */
package org.appspot.apprtc; package org.appspot.apprtc;
import android.os.AsyncTask;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log; import android.util.Log;

View File

@ -106,7 +106,6 @@ public class WebSocketRTCClient implements AppRTCClient,
// Fire connection and signaling parameters events. // Fire connection and signaling parameters events.
events.onConnectedToRoom(params); events.onConnectedToRoom(params);
events.onChannelOpen();
if (!params.initiator) { if (!params.initiator) {
// For call receiver get sdp offer and ice candidates // For call receiver get sdp offer and ice candidates
// from room parameters. // from room parameters.
@ -212,7 +211,7 @@ public class WebSocketRTCClient implements AppRTCClient,
wsClient = new WebSocketChannelClient(this); wsClient = new WebSocketChannelClient(this);
// Get room parameters. // Get room parameters.
roomState = ConnectionState.NEW; roomState = ConnectionState.NEW;
fetcher = new RoomParametersFetcher(this, true, loopback); fetcher = new RoomParametersFetcher(this, loopback);
fetcher.execute(url); fetcher.execute(url);
} }