mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-03 19:14:04 +00:00 
			
		
		
		
	Can hang up conversation
This commit is contained in:
		@@ -239,6 +239,24 @@ public class CallsHelper extends BaseHelper {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Hang up a call
 | 
			
		||||
     *
 | 
			
		||||
     * @param callID Target call ID
 | 
			
		||||
     * @return TRUE for a success / FALSE else
 | 
			
		||||
     */
 | 
			
		||||
    public boolean hangUp(int callID){
 | 
			
		||||
        APIRequest request = new APIRequest(getContext(), "calls/hangUp");
 | 
			
		||||
        request.addInt("call_id", callID);
 | 
			
		||||
        try {
 | 
			
		||||
            return request.exec().getJSONObject().has("success");
 | 
			
		||||
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Turn a {@link JSONObject} object into a {@link CallsConfiguration} object.
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,8 @@ import android.support.annotation.Nullable;
 | 
			
		||||
import android.support.v4.app.ActivityCompat;
 | 
			
		||||
import android.support.v4.content.ContextCompat;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.widget.ImageButton;
 | 
			
		||||
import android.widget.ProgressBar;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
 | 
			
		||||
@@ -23,6 +25,7 @@ import org.communiquons.android.comunic.client.data.models.CallsConfiguration;
 | 
			
		||||
import org.communiquons.android.comunic.client.data.utils.AccountUtils;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.arrays.CallPeersConnectionsList;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.asynctasks.GetCallInformationTask;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.asynctasks.HangUpCallTask;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.asynctasks.RespondToCallTask;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.models.CallPeerConnection;
 | 
			
		||||
import org.communiquons.android.comunic.client.ui.receivers.PendingCallsBroadcastReceiver;
 | 
			
		||||
@@ -85,6 +88,11 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
     */
 | 
			
		||||
    private SignalExchangerClient mSignalExchangerClient = null;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Specify whether call was stopped or not
 | 
			
		||||
     */
 | 
			
		||||
    private boolean mStopped = false;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Connections list
 | 
			
		||||
@@ -102,6 +110,7 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
     * Views
 | 
			
		||||
     */
 | 
			
		||||
    private ProgressBar mProgressBar;
 | 
			
		||||
    private ImageButton mHangUpButton;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -184,7 +193,8 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
    private void initViews(){
 | 
			
		||||
 | 
			
		||||
        mProgressBar = findViewById(R.id.progressBar);
 | 
			
		||||
 | 
			
		||||
        mHangUpButton = findViewById(R.id.hangUp);
 | 
			
		||||
        mHangUpButton.setOnClickListener(v -> hangUp());
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -214,6 +224,8 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
     */
 | 
			
		||||
    private void onGotCallInformation(@Nullable CallInformation info){
 | 
			
		||||
 | 
			
		||||
        if(mStopped) return;
 | 
			
		||||
 | 
			
		||||
        if(info == null){
 | 
			
		||||
            Toast.makeText(this, R.string.err_get_call_info, Toast.LENGTH_SHORT).show();
 | 
			
		||||
            return;
 | 
			
		||||
@@ -225,7 +237,7 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
        //Check if everyone left the conversation
 | 
			
		||||
        if(mCallInformation.hasAllMembersLeftCallExcept(AccountUtils.getID(this))){
 | 
			
		||||
            Toast.makeText(this, R.string.notice_call_terminated, Toast.LENGTH_SHORT).show();
 | 
			
		||||
            finish();
 | 
			
		||||
            hangUp();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -258,6 +270,9 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private void processClientsConnections(){
 | 
			
		||||
 | 
			
		||||
        if(mStopped) return;
 | 
			
		||||
 | 
			
		||||
        //Process each peer connection
 | 
			
		||||
        for(CallMember member : mCallInformation.getMembers())
 | 
			
		||||
            processClientConnection(member);
 | 
			
		||||
@@ -294,6 +309,8 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
     */
 | 
			
		||||
    private void createPeerConnection(CallMember member, boolean isInitiator){
 | 
			
		||||
 | 
			
		||||
        if(mStopped) return;
 | 
			
		||||
 | 
			
		||||
        Log.v(TAG, "Create peer connection for connection with user " + member.getUserID());
 | 
			
		||||
 | 
			
		||||
        CallPeerConnection callPeer = new CallPeerConnection(member);
 | 
			
		||||
@@ -359,10 +376,12 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
 | 
			
		||||
        ProxyVideoSink localProxyVideoSink = new ProxyVideoSink();
 | 
			
		||||
        localProxyVideoSink.setTarget(callPeer.getLocalVideoView());
 | 
			
		||||
        callPeer.setLocalProxyVideoSink(localProxyVideoSink);
 | 
			
		||||
 | 
			
		||||
        ProxyVideoSink remoteProxyRenderer = new ProxyVideoSink();
 | 
			
		||||
        remoteProxyRenderer.setTarget(callPeer.getRemoteViewView());
 | 
			
		||||
        callPeer.getRemoteSinks().add(remoteProxyRenderer);
 | 
			
		||||
        callPeer.setRemoteProxyRenderer(remoteProxyRenderer);
 | 
			
		||||
 | 
			
		||||
        //Start connection
 | 
			
		||||
        peerConnectionClient.createPeerConnection(
 | 
			
		||||
@@ -376,6 +395,27 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
            peerConnectionClient.createOffer();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Hang up call
 | 
			
		||||
     */
 | 
			
		||||
    private void hangUp(){
 | 
			
		||||
 | 
			
		||||
        mHangUpButton.setVisibility(View.GONE);
 | 
			
		||||
        mStopped = true;
 | 
			
		||||
 | 
			
		||||
        mRefreshCallInformation.interrupt();
 | 
			
		||||
 | 
			
		||||
        mSignalExchangerClient.close();
 | 
			
		||||
 | 
			
		||||
        for (CallPeerConnection client : mList)
 | 
			
		||||
            disconnectFromPeer(client.getMember());
 | 
			
		||||
 | 
			
		||||
        HangUpCallTask hangUpCallTask = new HangUpCallTask(getApplicationContext());
 | 
			
		||||
        hangUpCallTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mCallID);
 | 
			
		||||
 | 
			
		||||
        finish();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disconnect from a specific peer
 | 
			
		||||
     *
 | 
			
		||||
@@ -387,6 +427,9 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
 | 
			
		||||
        if(callPeer == null)
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        ((ProxyVideoSink)callPeer.getLocalProxyVideoSink()).setTarget(null);
 | 
			
		||||
        ((ProxyVideoSink)callPeer.getRemoteProxyRenderer()).setTarget(null);
 | 
			
		||||
 | 
			
		||||
        callPeer.getPeerConnectionClient().close();
 | 
			
		||||
 | 
			
		||||
        mList.remove(callPeer);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package org.communiquons.android.comunic.client.ui.asynctasks;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
 | 
			
		||||
import org.communiquons.android.comunic.client.data.helpers.CallsHelper;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Hang up a call
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
public class HangUpCallTask extends SafeAsyncTask<Integer, Void, Boolean> {
 | 
			
		||||
 | 
			
		||||
    public HangUpCallTask(Context context) {
 | 
			
		||||
        super(context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected Boolean doInBackground(Integer... integers) {
 | 
			
		||||
        return new CallsHelper(getContext()).hangUp(integers[0]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -17,6 +17,8 @@ public class CallPeerConnection {
 | 
			
		||||
    //Private fields
 | 
			
		||||
    private CallMember member;
 | 
			
		||||
    private PeerConnectionClient peerConnectionClient;
 | 
			
		||||
    private VideoSink localProxyVideoSink;
 | 
			
		||||
    private VideoSink remoteProxyRenderer;
 | 
			
		||||
    private ArrayList<VideoSink> remoteSinks = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    //Views
 | 
			
		||||
@@ -67,4 +69,20 @@ public class CallPeerConnection {
 | 
			
		||||
    public void setLocalVideoView(SurfaceViewRenderer mLocalVideoView) {
 | 
			
		||||
        this.mLocalVideoView = mLocalVideoView;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public VideoSink getLocalProxyVideoSink() {
 | 
			
		||||
        return localProxyVideoSink;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLocalProxyVideoSink(VideoSink localProxyVideoSink) {
 | 
			
		||||
        this.localProxyVideoSink = localProxyVideoSink;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public VideoSink getRemoteProxyRenderer() {
 | 
			
		||||
        return remoteProxyRenderer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRemoteProxyRenderer(VideoSink remoteProxyRenderer) {
 | 
			
		||||
        this.remoteProxyRenderer = remoteProxyRenderer;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -71,6 +71,14 @@ public class SignalExchangerClient extends WebSocketListener {
 | 
			
		||||
        mWebSocket = mClient.newWebSocket(request, this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Close this socket
 | 
			
		||||
     */
 | 
			
		||||
    public void close(){
 | 
			
		||||
        if(mWebSocket != null)
 | 
			
		||||
            mWebSocket.close(4999, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get current client configuration
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -20,4 +20,19 @@
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    <ImageButton
 | 
			
		||||
        android:id="@+id/hangUp"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_marginStart="8dp"
 | 
			
		||||
        android:layout_marginEnd="8dp"
 | 
			
		||||
        android:layout_marginBottom="8dp"
 | 
			
		||||
        android:backgroundTint="@color/holo_red_dark"
 | 
			
		||||
        android:src="@drawable/ic_call"
 | 
			
		||||
        android:tint="@android:color/white"
 | 
			
		||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        android:contentDescription="@string/action_hang_up"/>
 | 
			
		||||
 | 
			
		||||
</android.support.constraint.ConstraintLayout>
 | 
			
		||||
@@ -332,4 +332,5 @@
 | 
			
		||||
    <string name="err_get_call_info">Impossible de récupérer les infoamtions sur l\'appel !</string>
 | 
			
		||||
    <string name="err_connect_signaling_server">Impossible de connecter au signaling server !</string>
 | 
			
		||||
    <string name="notice_call_terminated">Appel terminé.</string>
 | 
			
		||||
    <string name="action_hang_up">Raccrocher</string>
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -331,4 +331,5 @@
 | 
			
		||||
    <string name="err_get_call_info">Could not get call information!</string>
 | 
			
		||||
    <string name="err_connect_signaling_server">Could not connect to signaling server!</string>
 | 
			
		||||
    <string name="notice_call_terminated">Call terminated</string>
 | 
			
		||||
    <string name="action_hang_up">Hang up</string>
 | 
			
		||||
</resources>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user