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.
*/
public class SignalingParameters {
public final boolean websocketSignaling;
public final List<PeerConnection.IceServer> iceServers;
public final boolean initiator;
public final MediaConstraints pcConstraints;
@ -74,7 +73,6 @@ public interface AppRTCClient {
public final String roomUrl;
public final String roomId;
public final String clientId;
public final String channelToken;
public final String wssUrl;
public final String wssPostUrl;
public final SessionDescription offerSdp;
@ -85,7 +83,7 @@ public interface AppRTCClient {
boolean initiator, MediaConstraints pcConstraints,
MediaConstraints videoConstraints, MediaConstraints audioConstraints,
String roomUrl, String roomId, String clientId,
String wssUrl, String wssPostUrl, String channelToken,
String wssUrl, String wssPostUrl,
SessionDescription offerSdp, List<IceCandidate> iceCandidates) {
this.iceServers = iceServers;
this.initiator = initiator;
@ -97,14 +95,8 @@ public interface AppRTCClient {
this.clientId = clientId;
this.wssUrl = wssUrl;
this.wssPostUrl = wssPostUrl;
this.channelToken = channelToken;
this.offerSdp = offerSdp;
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);
/**
* Callback fired once channel for signaling messages is opened and
* ready to receive messages.
*/
public void onChannelOpen();
/**
* Callback fired once remote SDP is received.
*/

View File

@ -513,14 +513,6 @@ public class AppRTCDemoActivity extends Activity
};
videoView.postDelayed(repeatedStatsLogger, 1000);
logAndToast("Waiting for remote connection...");
}
@Override
public void onChannelOpen() {
if (pc == null) {
return;
}
if (signalingParameters.initiator) {
logAndToast("Creating OFFER...");
// Create offer. Offer SDP will be sent to answering client in
@ -600,6 +592,10 @@ public class AppRTCDemoActivity extends Activity
disconnect();
}
@Override
public void onPeerConnectionClosed() {
}
@Override
public void onPeerConnectionError(String description) {
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_BITRATE = "org.appspot.apprtc.BITRATE";
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 final int CONNECTION_REQUEST = 1;
private static boolean commandLineRun = false;

View File

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

View File

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

View File

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

View File

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