Search in sources :

Example 1 with SessionDescription

use of org.webrtc.SessionDescription in project Signal-Android by WhisperSystems.

the class WebRtcCallService method handleIncomingCall.

// Handlers
private void handleIncomingCall(final Intent intent) {
    Log.w(TAG, "handleIncomingCall()");
    if (callState != CallState.STATE_IDLE)
        throw new IllegalStateException("Incoming on non-idle");
    final String offer = intent.getStringExtra(EXTRA_REMOTE_DESCRIPTION);
    this.callState = CallState.STATE_ANSWERING;
    this.callId = intent.getLongExtra(EXTRA_CALL_ID, -1);
    this.recipient = getRemoteRecipient(intent);
    if (isIncomingMessageExpired(intent)) {
        insertMissedCall(this.recipient, true);
        terminate();
        return;
    }
    timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
    initializeVideo();
    retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {

        @Override
        public void onSuccessContinue(List<PeerConnection.IceServer> result) {
            try {
                boolean isSystemContact = ContactAccessor.getInstance().isSystemContact(WebRtcCallService.this, recipient.getNumber());
                boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
                WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, !isSystemContact || isAlwaysTurn);
                WebRtcCallService.this.peerConnection.setRemoteDescription(new SessionDescription(SessionDescription.Type.OFFER, offer));
                WebRtcCallService.this.lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING);
                SessionDescription sdp = WebRtcCallService.this.peerConnection.createAnswer(new MediaConstraints());
                Log.w(TAG, "Answer SDP: " + sdp.description);
                WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forAnswer(new AnswerMessage(WebRtcCallService.this.callId, sdp.description)));
                listenableFutureTask.addListener(new FailureListener<Boolean>(WebRtcCallService.this.callState, WebRtcCallService.this.callId) {

                    @Override
                    public void onFailureContinue(Throwable error) {
                        Log.w(TAG, error);
                        terminate();
                    }
                });
            } catch (PeerConnectionException e) {
                Log.w(TAG, e);
                terminate();
            }
        }
    });
}
Also used : SessionDescription(org.webrtc.SessionDescription) PeerConnection(org.webrtc.PeerConnection) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) List(java.util.List) LinkedList(java.util.LinkedList)

Example 2 with SessionDescription

use of org.webrtc.SessionDescription in project Signal-Android by WhisperSystems.

the class PeerConnectionWrapper method setLocalDescription.

public void setLocalDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setLocalDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            throw new AssertionError();
        }

        @Override
        public void onCreateFailure(String error) {
            throw new AssertionError();
        }

        @Override
        public void onSetSuccess() {
            future.set(true);
        }

        @Override
        public void onSetFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }
    }, sdp);
    try {
        future.get();
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Example 3 with SessionDescription

use of org.webrtc.SessionDescription in project Signal-Android by signalapp.

the class WebRtcCallService method handleResponseMessage.

private void handleResponseMessage(Intent intent) {
    try {
        Log.w(TAG, "Got response: " + intent.getStringExtra(EXTRA_REMOTE_DESCRIPTION));
        if (callState != CallState.STATE_DIALING || !getRemoteRecipient(intent).equals(recipient) || !Util.isEquals(this.callId, getCallId(intent))) {
            Log.w(TAG, "Got answer for recipient and call id we're not currently dialing: " + getCallId(intent) + ", " + getRemoteRecipient(intent));
            return;
        }
        if (peerConnection == null || pendingOutgoingIceUpdates == null) {
            throw new AssertionError("assert");
        }
        if (!pendingOutgoingIceUpdates.isEmpty()) {
            ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forIceUpdates(pendingOutgoingIceUpdates));
            listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                @Override
                public void onFailureContinue(Throwable error) {
                    Log.w(TAG, error);
                    sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                    terminate();
                }
            });
        }
        this.peerConnection.setRemoteDescription(new SessionDescription(SessionDescription.Type.ANSWER, intent.getStringExtra(EXTRA_REMOTE_DESCRIPTION)));
        this.pendingOutgoingIceUpdates = null;
    } catch (PeerConnectionException e) {
        Log.w(TAG, e);
        terminate();
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)

Example 4 with SessionDescription

use of org.webrtc.SessionDescription in project Signal-Android by signalapp.

the class PeerConnectionWrapper method setLocalDescription.

public void setLocalDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setLocalDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            throw new AssertionError();
        }

        @Override
        public void onCreateFailure(String error) {
            throw new AssertionError();
        }

        @Override
        public void onSetSuccess() {
            future.set(true);
        }

        @Override
        public void onSetFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }
    }, sdp);
    try {
        future.get();
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Example 5 with SessionDescription

use of org.webrtc.SessionDescription in project Signal-Android by signalapp.

the class PeerConnectionWrapper method setRemoteDescription.

public void setRemoteDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setRemoteDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
        }

        @Override
        public void onCreateFailure(String error) {
        }

        @Override
        public void onSetSuccess() {
            future.set(true);
        }

        @Override
        public void onSetFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }
    }, sdp);
    try {
        future.get();
    } catch (InterruptedException e) {
        throw new AssertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) SessionDescription(org.webrtc.SessionDescription) ExecutionException(java.util.concurrent.ExecutionException) SdpObserver(org.webrtc.SdpObserver)

Aggregations

SessionDescription (org.webrtc.SessionDescription)17 SdpObserver (org.webrtc.SdpObserver)11 ExecutionException (java.util.concurrent.ExecutionException)8 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)8 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)6 MediaConstraints (org.webrtc.MediaConstraints)6 PeerConnection (org.webrtc.PeerConnection)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ListenableFutureTask (org.thoughtcrime.securesms.util.ListenableFutureTask)4 PeerConnectionWrapper (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper)4 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 IceCandidate (org.webrtc.IceCandidate)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)2 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)2 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)2 SuppressLint (android.annotation.SuppressLint)1