Search in sources :

Example 6 with SessionDescription

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

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 || pendingIceUpdates == null) {
            throw new AssertionError("assert");
        }
        if (!pendingIceUpdates.isEmpty()) {
            ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forIceUpdates(pendingIceUpdates));
            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.pendingIceUpdates = null;
    } catch (PeerConnectionException e) {
        Log.w(TAG, e);
        terminate();
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)

Example 7 with SessionDescription

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

the class WebRtcCallService method handleOutgoingCall.

private void handleOutgoingCall(Intent intent) {
    Log.w(TAG, "handleOutgoingCall...");
    if (callState != CallState.STATE_IDLE)
        throw new IllegalStateException("Dialing from non-idle?");
    try {
        this.callState = CallState.STATE_DIALING;
        this.recipient = getRemoteRecipient(intent);
        this.callId = SecureRandom.getInstance("SHA1PRNG").nextLong();
        this.pendingIceUpdates = new LinkedList<>();
        initializeVideo();
        sendMessage(WebRtcViewModel.State.CALL_OUTGOING, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
        lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
        audioManager.initializeAudioForCall();
        audioManager.startOutgoingRinger(OutgoingRinger.Type.SONAR);
        bluetoothStateManager.setWantsConnection(true);
        setCallInProgressNotification(TYPE_OUTGOING_RINGING, recipient);
        DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(recipient.getNumber());
        timeoutExecutor.schedule(new TimeoutRunnable(this.callId), 2, TimeUnit.MINUTES);
        retrieveTurnServers().addListener(new SuccessOnlyListener<List<PeerConnection.IceServer>>(this.callState, this.callId) {

            @Override
            public void onSuccessContinue(List<PeerConnection.IceServer> result) {
                try {
                    boolean isAlwaysTurn = TextSecurePreferences.isTurnOnly(WebRtcCallService.this);
                    WebRtcCallService.this.peerConnection = new PeerConnectionWrapper(WebRtcCallService.this, peerConnectionFactory, WebRtcCallService.this, localRenderer, result, isAlwaysTurn);
                    WebRtcCallService.this.dataChannel = WebRtcCallService.this.peerConnection.createDataChannel(DATA_CHANNEL_NAME);
                    WebRtcCallService.this.dataChannel.registerObserver(WebRtcCallService.this);
                    SessionDescription sdp = WebRtcCallService.this.peerConnection.createOffer(new MediaConstraints());
                    WebRtcCallService.this.peerConnection.setLocalDescription(sdp);
                    Log.w(TAG, "Sending offer: " + sdp.description);
                    ListenableFutureTask<Boolean> listenableFutureTask = sendMessage(recipient, SignalServiceCallMessage.forOffer(new OfferMessage(WebRtcCallService.this.callId, sdp.description)));
                    listenableFutureTask.addListener(new FailureListener<Boolean>(callState, callId) {

                        @Override
                        public void onFailureContinue(Throwable error) {
                            Log.w(TAG, error);
                            if (error instanceof UntrustedIdentityException) {
                                sendMessage(WebRtcViewModel.State.UNTRUSTED_IDENTITY, recipient, ((UntrustedIdentityException) error).getIdentityKey(), localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof UnregisteredUserException) {
                                sendMessage(WebRtcViewModel.State.NO_SUCH_USER, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            } else if (error instanceof IOException) {
                                sendMessage(WebRtcViewModel.State.NETWORK_FAILURE, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
                            }
                            terminate();
                        }
                    });
                } catch (PeerConnectionException e) {
                    Log.w(TAG, e);
                    terminate();
                }
            }
        });
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}
Also used : SessionDescription(org.webrtc.SessionDescription) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) PeerConnection(org.webrtc.PeerConnection) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PeerConnectionWrapper(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper) MediaConstraints(org.webrtc.MediaConstraints) ListenableFutureTask(org.thoughtcrime.securesms.util.ListenableFutureTask) PeerConnectionException(org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

SessionDescription (org.webrtc.SessionDescription)7 ExecutionException (java.util.concurrent.ExecutionException)4 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)4 SdpObserver (org.webrtc.SdpObserver)4 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ListenableFutureTask (org.thoughtcrime.securesms.util.ListenableFutureTask)2 PeerConnectionWrapper (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper)2 MediaConstraints (org.webrtc.MediaConstraints)2 PeerConnection (org.webrtc.PeerConnection)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)1 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)1 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)1 UnregisteredUserException (org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException)1