Search in sources :

Example 21 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)

Example 22 with SessionDescription

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

the class PeerConnectionWrapper method createOffer.

public SessionDescription createOffer(MediaConstraints mediaConstraints) throws PeerConnectionException {
    final SettableFuture<SessionDescription> future = new SettableFuture<>();
    peerConnection.createOffer(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            future.set(sdp);
        }

        @Override
        public void onCreateFailure(String error) {
            future.setException(new PeerConnectionException(error));
        }

        @Override
        public void onSetSuccess() {
            throw new AssertionError();
        }

        @Override
        public void onSetFailure(String error) {
            throw new AssertionError();
        }
    }, mediaConstraints);
    try {
        return correctSessionDescription(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 23 with SessionDescription

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

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.pendingIncomingIceUpdates = new LinkedList<>();
    this.recipient = getRemoteRecipient(intent);
    if (isIncomingMessageExpired(intent)) {
        insertMissedCall(this.recipient, true);
        terminate();
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        setCallInProgressNotification(TYPE_INCOMING_CONNECTING, this.recipient);
    }
    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 = false;
                if (Permissions.hasAny(WebRtcCallService.this, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
                    isSystemContact = ContactAccessor.getInstance().isSystemContact(WebRtcCallService.this, recipient.getAddress().serialize());
                }
                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)));
                for (IceCandidate candidate : pendingIncomingIceUpdates) WebRtcCallService.this.peerConnection.addIceCandidate(candidate);
                WebRtcCallService.this.pendingIncomingIceUpdates = null;
                listenableFutureTask.addListener(new FailureListener<Boolean>(WebRtcCallService.this.callState, WebRtcCallService.this.callId) {

                    @Override
                    public void onFailureContinue(Throwable error) {
                        Log.w(TAG, error);
                        insertMissedCall(recipient, true);
                        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) IceCandidate(org.webrtc.IceCandidate) 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 24 with SessionDescription

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

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.pendingOutgoingIceUpdates = 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.getAddress());
        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)

Example 25 with SessionDescription

use of org.webrtc.SessionDescription in project talk-android by nextcloud.

the class CallActivity method processMessage.

private void processMessage(NCSignalingMessage ncSignalingMessage) {
    if (ncSignalingMessage.getRoomType().equals("video") || ncSignalingMessage.getRoomType().equals("screen")) {
        PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(ncSignalingMessage.getFrom(), ncSignalingMessage.getRoomType(), false);
        String type = null;
        if (ncSignalingMessage.getPayload() != null && ncSignalingMessage.getPayload().getType() != null) {
            type = ncSignalingMessage.getPayload().getType();
        } else if (ncSignalingMessage.getType() != null) {
            type = ncSignalingMessage.getType();
        }
        if (type != null) {
            switch(type) {
                case "unshareScreen":
                    endPeerConnection(ncSignalingMessage.getFrom(), true);
                    break;
                case "offer":
                case "answer":
                    peerConnectionWrapper.setNick(ncSignalingMessage.getPayload().getNick());
                    SessionDescription sessionDescriptionWithPreferredCodec;
                    String sessionDescriptionStringWithPreferredCodec = MagicWebRTCUtils.preferCodec(ncSignalingMessage.getPayload().getSdp(), "H264", false);
                    sessionDescriptionWithPreferredCodec = new SessionDescription(SessionDescription.Type.fromCanonicalForm(type), sessionDescriptionStringWithPreferredCodec);
                    if (peerConnectionWrapper.getPeerConnection() != null) {
                        peerConnectionWrapper.getPeerConnection().setRemoteDescription(peerConnectionWrapper.getMagicSdpObserver(), sessionDescriptionWithPreferredCodec);
                    }
                    break;
                case "candidate":
                    NCIceCandidate ncIceCandidate = ncSignalingMessage.getPayload().getIceCandidate();
                    IceCandidate iceCandidate = new IceCandidate(ncIceCandidate.getSdpMid(), ncIceCandidate.getSdpMLineIndex(), ncIceCandidate.getCandidate());
                    peerConnectionWrapper.addCandidate(iceCandidate);
                    break;
                case "endOfCandidates":
                    peerConnectionWrapper.drainIceCandidates();
                    break;
                default:
                    break;
            }
        }
    } else {
        Log.e(TAG, "unexpected RoomType while processing NCSignalingMessage");
    }
}
Also used : PeerConnectionWrapper(com.nextcloud.talk.webrtc.PeerConnectionWrapper) SessionDescription(org.webrtc.SessionDescription) NCIceCandidate(com.nextcloud.talk.models.json.signaling.NCIceCandidate) NCIceCandidate(com.nextcloud.talk.models.json.signaling.NCIceCandidate) IceCandidate(org.webrtc.IceCandidate)

Aggregations

SessionDescription (org.webrtc.SessionDescription)32 SdpObserver (org.webrtc.SdpObserver)14 MediaConstraints (org.webrtc.MediaConstraints)9 ExecutionException (java.util.concurrent.ExecutionException)8 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)8 PeerConnection (org.webrtc.PeerConnection)8 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)6 List (java.util.List)5 WritableMap (com.facebook.react.bridge.WritableMap)4 LinkedList (java.util.LinkedList)4 ListenableFutureTask (org.thoughtcrime.securesms.util.ListenableFutureTask)4 PeerConnectionWrapper (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper)4 CustomSdpObserver (com.example.webrtcandroidapp.observers.CustomSdpObserver)3 JsonObject (com.google.gson.JsonObject)3 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)3 AudioTrack (org.webrtc.AudioTrack)3 IceCandidate (org.webrtc.IceCandidate)3 MediaStream (org.webrtc.MediaStream)3 VideoTrack (org.webrtc.VideoTrack)3 IOException (java.io.IOException)2