Search in sources :

Example 11 with SessionDescription

use of org.webrtc.SessionDescription in project react-native-webrtc by react-native-webrtc.

the class PeerConnectionObserver method onRemoveStream.

@Override
public void onRemoveStream(MediaStream mediaStream) {
    String streamReactTag = getReactTagForStream(mediaStream);
    if (streamReactTag == null) {
        Log.w(TAG, "onRemoveStream - no remote stream for id: " + mediaStream.getId());
        return;
    }
    for (VideoTrack track : mediaStream.videoTracks) {
        this.videoTrackAdapters.removeAdapter(track);
        this.remoteTracks.remove(track.id());
    }
    for (AudioTrack track : mediaStream.audioTracks) {
        this.remoteTracks.remove(track.id());
    }
    this.remoteStreams.remove(streamReactTag);
    WritableMap params = Arguments.createMap();
    params.putInt("id", id);
    params.putString("streamId", streamReactTag);
    SessionDescription newSdp = peerConnection.getRemoteDescription();
    WritableMap newSdpMap = Arguments.createMap();
    newSdpMap.putString("type", newSdp.type.canonicalForm());
    newSdpMap.putString("sdp", newSdp.description);
    params.putMap("sdp", newSdpMap);
    webRTCModule.sendEvent("peerConnectionRemovedStream", params);
}
Also used : SessionDescription(org.webrtc.SessionDescription) WritableMap(com.facebook.react.bridge.WritableMap) VideoTrack(org.webrtc.VideoTrack) AudioTrack(org.webrtc.AudioTrack)

Example 12 with SessionDescription

use of org.webrtc.SessionDescription in project react-native-webrtc by react-native-webrtc.

the class PeerConnectionObserver method onIceGatheringChange.

@Override
public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
    Log.d(TAG, "onIceGatheringChange" + iceGatheringState.name());
    WritableMap params = Arguments.createMap();
    params.putInt("id", id);
    params.putString("iceGatheringState", iceGatheringStateString(iceGatheringState));
    if (iceGatheringState == PeerConnection.IceGatheringState.COMPLETE) {
        SessionDescription newSdp = peerConnection.getLocalDescription();
        WritableMap newSdpMap = Arguments.createMap();
        newSdpMap.putString("type", newSdp.type.canonicalForm());
        newSdpMap.putString("sdp", newSdp.description);
        params.putMap("sdp", newSdpMap);
    }
    webRTCModule.sendEvent("peerConnectionIceGatheringChanged", params);
}
Also used : SessionDescription(org.webrtc.SessionDescription) WritableMap(com.facebook.react.bridge.WritableMap)

Example 13 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 14 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 15 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)

Aggregations

SessionDescription (org.webrtc.SessionDescription)26 SdpObserver (org.webrtc.SdpObserver)12 ExecutionException (java.util.concurrent.ExecutionException)8 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)8 MediaConstraints (org.webrtc.MediaConstraints)7 PeerConnectionException (org.thoughtcrime.securesms.webrtc.PeerConnectionWrapper.PeerConnectionException)6 PeerConnection (org.webrtc.PeerConnection)5 WritableMap (com.facebook.react.bridge.WritableMap)4 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)3 IceCandidate (org.webrtc.IceCandidate)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 AudioTrack (org.webrtc.AudioTrack)2 MediaStream (org.webrtc.MediaStream)2 VideoTrack (org.webrtc.VideoTrack)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2