Add android bindings for PeerConnectionState.
This change makes it possible for android apps to use the new standards-compliant PeerConnectionState. Bug: webrtc:9977 Change-Id: Iad19c38e664a59e86879715ec7a04a59a9894bee Reviewed-on: https://webrtc-review.googlesource.com/c/109883 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25652}
This commit is contained in:
@ -171,7 +171,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
private RoomConnectionParameters roomConnectionParameters;
|
||||
@Nullable
|
||||
private PeerConnectionParameters peerConnectionParameters;
|
||||
private boolean iceConnected;
|
||||
private boolean connected;
|
||||
private boolean isError;
|
||||
private boolean callControlFragmentVisible = true;
|
||||
private long callStartedTimeMs;
|
||||
@ -203,7 +203,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
getWindow().getDecorView().setSystemUiVisibility(getSystemUiVisibility());
|
||||
setContentView(R.layout.activity_call);
|
||||
|
||||
iceConnected = false;
|
||||
connected = false;
|
||||
signalingParameters = null;
|
||||
|
||||
// Create UI controls.
|
||||
@ -553,7 +553,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
|
||||
// Helper functions.
|
||||
private void toggleCallControlFragmentVisibility() {
|
||||
if (!iceConnected || !callFragment.isAdded()) {
|
||||
if (!connected || !callFragment.isAdded()) {
|
||||
return;
|
||||
}
|
||||
// Show/hide call control fragment
|
||||
@ -649,7 +649,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
audioManager.stop();
|
||||
audioManager = null;
|
||||
}
|
||||
if (iceConnected && !isError) {
|
||||
if (connected && !isError) {
|
||||
setResult(RESULT_OK);
|
||||
} else {
|
||||
setResult(RESULT_CANCELED);
|
||||
@ -911,8 +911,6 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
@Override
|
||||
public void run() {
|
||||
logAndToast("ICE connected, delay=" + delta + "ms");
|
||||
iceConnected = true;
|
||||
callConnected();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -923,7 +921,30 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
@Override
|
||||
public void run() {
|
||||
logAndToast("ICE disconnected");
|
||||
iceConnected = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
final long delta = System.currentTimeMillis() - callStartedTimeMs;
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logAndToast("DTLS connected, delay=" + delta + "ms");
|
||||
connected = true;
|
||||
callConnected();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logAndToast("DTLS disconnected");
|
||||
connected = false;
|
||||
disconnect();
|
||||
}
|
||||
});
|
||||
@ -937,7 +958,7 @@ public class CallActivity extends Activity implements AppRTCClient.SignalingEven
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isError && iceConnected) {
|
||||
if (!isError && connected) {
|
||||
hudFragment.updateEncoderStatistics(reports);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ import org.webrtc.MediaStreamTrack;
|
||||
import org.webrtc.MediaStreamTrack.MediaType;
|
||||
import org.webrtc.PeerConnection;
|
||||
import org.webrtc.PeerConnection.IceConnectionState;
|
||||
import org.webrtc.PeerConnection.PeerConnectionState;
|
||||
import org.webrtc.PeerConnectionFactory;
|
||||
import org.webrtc.RtpParameters;
|
||||
import org.webrtc.RtpReceiver;
|
||||
@ -293,11 +294,23 @@ public class PeerConnectionClient {
|
||||
void onIceConnected();
|
||||
|
||||
/**
|
||||
* Callback fired once connection is closed (IceConnectionState is
|
||||
* Callback fired once connection is disconnected (IceConnectionState is
|
||||
* DISCONNECTED).
|
||||
*/
|
||||
void onIceDisconnected();
|
||||
|
||||
/**
|
||||
* Callback fired once DTLS connection is established (PeerConnectionState
|
||||
* is CONNECTED).
|
||||
*/
|
||||
void onConnected();
|
||||
|
||||
/**
|
||||
* Callback fired once DTLS connection is disconnected (PeerConnectionState
|
||||
* is DISCONNECTED).
|
||||
*/
|
||||
void onDisconnected();
|
||||
|
||||
/**
|
||||
* Callback fired once peer connection is closed.
|
||||
*/
|
||||
@ -1263,6 +1276,20 @@ public class PeerConnectionClient {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionChange(final PeerConnection.PeerConnectionState newState) {
|
||||
executor.execute(() -> {
|
||||
Log.d(TAG, "PeerConnectionState: " + newState);
|
||||
if (newState == PeerConnectionState.CONNECTED) {
|
||||
events.onConnected();
|
||||
} else if (newState == PeerConnectionState.DISCONNECTED) {
|
||||
events.onDisconnected();
|
||||
} else if (newState == PeerConnectionState.FAILED) {
|
||||
reportError("DTLS connection failed.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIceGatheringChange(PeerConnection.IceGatheringState newState) {
|
||||
Log.d(TAG, "IceGatheringState: " + newState);
|
||||
|
||||
Reference in New Issue
Block a user