From 9e559ed56840140ae739afad5d091d049250e6bc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 26 Feb 2019 18:48:58 +0100 Subject: [PATCH] Improved the way ready messages are sent. --- .../client/ui/activities/CallActivity.java | 23 +++++++++++++++---- .../client/ui/models/CallPeerConnection.java | 9 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/CallActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/CallActivity.java index 263bc07..e0f277f 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/CallActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/CallActivity.java @@ -293,12 +293,17 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac if(mList.find(member) == null && member.getUserID() > AccountUtils.getID(this)) { createPeerConnection(member, false); - mSignalExchangerClient.sendReadyMessage(member.getUserCallID()); } + CallPeerConnection connection = mList.find(member); - if(mList.find(member) != null) - Objects.requireNonNull(mList.find(member)).setMember(member); + if(connection != null) { + + if(!connection.isConnected()) + mSignalExchangerClient.sendReadyMessage(connection.getMember().getUserCallID()); + + Objects.requireNonNull(connection).setMember(member); + } } /** @@ -403,9 +408,11 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac mHangUpButton.setVisibility(View.GONE); mStopped = true; - mRefreshCallInformation.interrupt(); + if(mRefreshCallInformation != null) + mRefreshCallInformation.interrupt(); - mSignalExchangerClient.close(); + if(mSignalExchangerClient != null) + mSignalExchangerClient.close(); for (CallPeerConnection client : mList) disconnectFromPeer(client.getMember()); @@ -592,24 +599,28 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac public void onIceConnected() { Log.v(TAG, "Ice connected with peer " + connection.getMember().getUserID()); + connection.setConnected(true); } @Override public void onIceDisconnected() { Log.v(TAG, "Ice disconnected from peer " + connection.getMember().getUserID()); + connection.setConnected(false); } @Override public void onConnected() { Log.v(TAG, "Connected to peer " + connection.getMember().getUserID()); + connection.setConnected(true); } @Override public void onDisconnected() { Log.v(TAG, "Disconnected from peer " + connection.getMember().getUserID()); + connection.setConnected(false); } @Override @@ -617,6 +628,7 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac Log.v(TAG, "Connection close from user " + connection.getMember().getUserID()); runOnUiThread(() -> disconnectFromPeer(connection.getMember())); + connection.setConnected(false); } @Override @@ -629,6 +641,7 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac public void onPeerConnectionError(String description) { Log.e(TAG, "Peer connection error with " + connection.getMember().getUserID() + " " + description); + connection.setConnected(false); } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/models/CallPeerConnection.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/models/CallPeerConnection.java index 53f383b..159a87a 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/models/CallPeerConnection.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/models/CallPeerConnection.java @@ -17,6 +17,7 @@ public class CallPeerConnection { //Private fields private CallMember member; private PeerConnectionClient peerConnectionClient; + private boolean connected = false; private VideoSink localProxyVideoSink; private VideoSink remoteProxyRenderer; private ArrayList remoteSinks = new ArrayList<>(); @@ -45,6 +46,14 @@ public class CallPeerConnection { this.peerConnectionClient = peerConnectionClient; } + public boolean isConnected() { + return connected; + } + + public void setConnected(boolean connected) { + this.connected = connected; + } + public ArrayList getRemoteSinks() { return remoteSinks; }