Search in sources :

Example 1 with AnswerMessage

use of org.whispersystems.signalservice.api.messages.calls.AnswerMessage 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)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 ListenableFutureTask (org.thoughtcrime.securesms.util.ListenableFutureTask)1 PeerConnectionWrapper (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper)1 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)1 MediaConstraints (org.webrtc.MediaConstraints)1 PeerConnection (org.webrtc.PeerConnection)1 SessionDescription (org.webrtc.SessionDescription)1 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)1