Search in sources :

Example 16 with SessionDescription

use of org.webrtc.SessionDescription in project webrtc-tutorials by dalkofjac.

the class SessionCallActivity method sendOffer.

private void sendOffer() {
    Log.d(TAG, "sendOffer");
    addTransceivers();
    mPeerConnection.createOffer(new CustomSdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sessionDescription) {
            mPeerConnection.setLocalDescription(new CustomSdpObserver(), sessionDescription);
            try {
                LinkedTreeMap<String, Object> offer = new LinkedTreeMap<String, Object>();
                offer.put("type", sessionDescription.type.canonicalForm());
                offer.put("sdp", sessionDescription.description);
                sendMessage(offer);
            } catch (Exception e) {
                Log.e(TAG, "sendOffer failed.", e);
            }
        }
    }, new MediaConstraints());
}
Also used : SessionDescription(org.webrtc.SessionDescription) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) MediaConstraints(org.webrtc.MediaConstraints) CustomSdpObserver(com.example.webrtcandroidapp.observers.CustomSdpObserver)

Example 17 with SessionDescription

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

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 18 with SessionDescription

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

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)

Example 19 with SessionDescription

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

the class PeerConnectionWrapper method createAnswer.

public SessionDescription createAnswer(MediaConstraints mediaConstraints) throws PeerConnectionException {
    final SettableFuture<SessionDescription> future = new SettableFuture<>();
    peerConnection.createAnswer(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 20 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)

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