org.webrtc.SessionDescription - java examples

Here are the examples of the java api org.webrtc.SessionDescription taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

70 Examples 7

19 View Complete Implementation : WebRTCActivity.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : GoBelieveIO
public void onRemoteDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (peerConnectionClient == null) {
                Log.e(TAG, "Received remote SDP for non-initilized peer connection.");
                return;
            }
            logAndToast("Received remote " + sdp.type + ", delay=" + delta + "ms");
            peerConnectionClient.setRemoteDescription(sdp);
            if (!WebRTCActivity.this.isCaller) {
                logAndToast("Creating ANSWER...");
                // Create answer. Answer SDP will be sent to offering client in
                // PeerConnectionEvents.onLocalDescription event.
                peerConnectionClient.createAnswer();
            }
        }
    });
}

19 View Complete Implementation : CustomSdpObserver.java
Copyright Apache License 2.0
Author : sergiopaniego
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
    Log.d(tag, "onCreateSuccess() called with: sessionDescription = [" + sessionDescription + "]");
}

19 View Complete Implementation : PeerConnectionChannel.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
// SdpObserver
@Override
public void onCreateSuccess(final SessionDescription sessionDescription) {
    localSdp = sessionDescription;
    if (audioCodecs != null) {
        localSdp = preferCodecs(localSdp, false);
    }
    if (videoCodecs != null) {
        localSdp = preferCodecs(localSdp, true);
    }
    callbackExecutor.execute(() -> {
        if (disposed) {
            return;
        }
        observer.onLocalDescription(key, localSdp);
    });
    pcExecutor.execute(() -> {
        if (disposed) {
            return;
        }
        peerConnection.setLocalDescription(PeerConnectionChannel.this, localSdp);
    });
}

19 View Complete Implementation : PeerConnectionChannel.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
private void setRemoteDescription(final SessionDescription remoteDescription) {
    pcExecutor.execute(() -> {
        if (disposed()) {
            return;
        }
        SessionDescription remoteSdp = remoteDescription;
        if (audioCodecs != null) {
            remoteSdp = preferCodecs(remoteSdp, false);
        }
        if (videoCodecs != null) {
            remoteSdp = preferCodecs(remoteSdp, true);
        }
        peerConnection.setRemoteDescription(PeerConnectionChannel.this, remoteSdp);
    });
}

19 View Complete Implementation : CallActivity.java
Copyright Apache License 2.0
Author : androidthings
// -----Implementation of PeerConnectionClient.PeerConnectionEvents.---------
// Send local peer connection SDP and ICE candidates to remote party.
// All callbacks are invoked from peer connection client looper thread and
// are routed to UI thread.
@Override
public void onLocalDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (appRtcClient != null) {
                logAndToast("Sending " + sdp.type + ", delay=" + delta + "ms");
                if (signalingParameters.initiator) {
                    appRtcClient.sendOfferSdp(sdp);
                } else {
                    appRtcClient.sendAnswerSdp(sdp);
                }
            }
            if (peerConnectionParameters.videoMaxBitrate > 0) {
                Log.d(TAG, "Set video maximum bitrate: " + peerConnectionParameters.videoMaxBitrate);
                peerConnectionClient.setVideoMaxBitrate(peerConnectionParameters.videoMaxBitrate);
            }
        }
    });
}

19 View Complete Implementation : DefaultSdpObserver.java
Copyright GNU General Public License v3.0
Author : dakhnod
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
}

19 View Complete Implementation : DefaultSdpObserver.java
Copyright GNU General Public License v3.0
Author : meshenger-app
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
// nothing to do
}

19 View Complete Implementation : SdpAdapter.java
Copyright Apache License 2.0
Author : rome753
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
    log("onCreateSuccess " + sessionDescription);
}

19 View Complete Implementation : CallActivity.java
Copyright MIT License
Author : wmhameed
// -----Implementation of PeerConnectionClient.PeerConnectionEvents.---------
// Send local peer connection SDP and ICE candidates to remote party.
// All callbacks are invoked from peer connection client looper thread and
// are routed to UI thread.
@Override
public void onLocalDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (appRtcClient != null) {
                logAndToast("Sending " + sdp.type + ", delay=" + delta + "ms");
                if (signalingParameters.initiator) {
                    appRtcClient.sendOfferSdp(sdp);
                } else {
                    appRtcClient.sendAnswerSdp(sdp);
                }
            }
        }
    });
}

19 View Complete Implementation : PeerVideoActivity.java
Copyright Apache License 2.0
Author : nubomedia-vtt
@Override
public void onLocalSdpAnswerGenerated(SessionDescription sessionDescription, NBMPeerConnection nbmPeerConnection) {
}

19 View Complete Implementation : CallActivity.java
Copyright Apache License 2.0
Author : androidthings
@Override
public void onRemoteDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (peerConnectionClient == null) {
                Log.e(TAG, "Received remote SDP for non-initilized peer connection.");
                return;
            }
            logAndToast("Received remote " + sdp.type + ", delay=" + delta + "ms");
            peerConnectionClient.setRemoteDescription(sdp);
            if (!signalingParameters.initiator) {
                logAndToast("Creating ANSWER...");
                // Create answer. Answer SDP will be sent to offering client in
                // PeerConnectionEvents.onLocalDescription event.
                peerConnectionClient.createAnswer();
            }
        }
    });
}

19 View Complete Implementation : PeerConnectionWrapper.java
Copyright GNU General Public License v3.0
Author : bcmapp
private SessionDescription correctSessionDescription(SessionDescription sessionDescription) {
    String updatedSdp = sessionDescription.description.replaceAll("(a=fmtp:111 ((?!cbr=).)*)\r?\n", "$1;cbr=1\r\n");
    updatedSdp = updatedSdp.replaceAll(".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", "");
    return new SessionDescription(sessionDescription.type, updatedSdp);
}

18 View Complete Implementation : CallSession.java
Copyright MIT License
Author : ddssingsong
public void onReceiverAnswer(String socketId, String sdp) {
    Log.e("dds_test", "onReceiverAnswer:" + socketId);
    executor.execute(() -> {
        SessionDescription sessionDescription = new SessionDescription(SessionDescription.Type.ANSWER, sdp);
        if (mPeer != null && mPeer.pc != null) {
            Log.e("dds_test", "onReceiverAnswer setRemoteDescription");
            mPeer.pc.setRemoteDescription(mPeer, sessionDescription);
        }
    });
}

18 View Complete Implementation : CallSession.java
Copyright MIT License
Author : ddssingsong
public void onReceiveOffer(String socketId, String description) {
    Log.e("dds_test", "onReceiveOffer:" + socketId);
    executor.execute(() -> {
        _role = Role.Receiver;
        SessionDescription sdp = new SessionDescription(SessionDescription.Type.OFFER, description);
        if (mPeer != null) {
            Log.e("dds_test", "onReceiveOffer setRemoteDescription");
            mPeer.pc.setRemoteDescription(mPeer, sdp);
        }
    });
}

18 View Complete Implementation : DirectRTCClient.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : duttaime
@Override
public void sendAnswerSdp(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "answer");
            sendMessage(json.toString());
        }
    });
}

18 View Complete Implementation : DirectRTCClient.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : duttaime
@Override
public void sendOfferSdp(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            if (roomState != ConnectionState.CONNECTED) {
                reportError("Sending offer SDP in non connected state.");
                return;
            }
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "offer");
            sendMessage(json.toString());
        }
    });
}

18 View Complete Implementation : WebRTCActivity.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : GoBelieveIO
// -----Implementation of PeerConnectionClient.PeerConnectionEvents.---------
// Send local peer connection SDP and ICE candidates to remote party.
// All callbacks are invoked from peer connection client looper thread and
// are routed to UI thread.
@Override
public void onLocalDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            logAndToast("Sending " + sdp.type + ", delay=" + delta + "ms");
            if (WebRTCActivity.this.isCaller) {
                WebRTCActivity.this.sendOfferSdp(sdp);
            } else {
                WebRTCActivity.this.sendAnswerSdp(sdp);
            }
            if (peerConnectionParameters.videoMaxBitrate > 0) {
                Log.d(TAG, "Set video maximum bitrate: " + peerConnectionParameters.videoMaxBitrate);
                peerConnectionClient.setVideoMaxBitrate(peerConnectionParameters.videoMaxBitrate);
            }
        }
    });
}

18 View Complete Implementation : BlockingSdpObserver.java
Copyright Apache License 2.0
Author : google
/**
 * Called on success of Create{Offer,Answer}().
 */
@Override
public void onCreateSuccess(SessionDescription sdp) {
    createFuture.set(sdp);
}

18 View Complete Implementation : MediaResourceManager.java
Copyright Apache License 2.0
Author : nubomedia-vtt
@Override
public void onLocalSdpOfferGenerated(SessionDescription localSdpOffer, NBMPeerConnection connection) {
}

18 View Complete Implementation : MediaResourceManager.java
Copyright Apache License 2.0
Author : nubomedia-vtt
@Override
public void onLocalSdpAnswerGenerated(SessionDescription localSdpAnswer, NBMPeerConnection connection) {
}

18 View Complete Implementation : NBMPeerConnection.java
Copyright Apache License 2.0
Author : nubomedia-vtt
protected void setRemoteDescription(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            setRemoteDescriptionSync(sdp);
        }
    });
}

18 View Complete Implementation : NBMWebRTCPeer.java
Copyright Apache License 2.0
Author : nubomedia-vtt
/**
 * Processes received SDP answer
 * @param remoteAnswer The received answer
 * @param connectionId A unique identifier for the connection
 */
@SuppressWarnings("unused")
public void processAnswer(SessionDescription remoteAnswer, String connectionId) {
    NBMPeerConnection connection = peerConnectionResourceManager.getConnection(connectionId);
    if (connection != null) {
        connection.setRemoteDescription(remoteAnswer);
    } else {
        observer.onPeerConnectionError("Connection for id " + connectionId + " cannot be found!");
    }
}

18 View Complete Implementation : ConferenceClient.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
@Override
public void onLocalDescription(final String id, final SessionDescription localSdp) {
    try {
        SessionDescription sdp = new SessionDescription(localSdp.type, localSdp.description.replaceAll("a=ice-options:google-ice\r\n", ""));
        JSONObject sdpObj = new JSONObject();
        sdpObj.put("type", sdp.type.toString().toLowerCase(Locale.US));
        sdpObj.put("sdp", sdp.description);
        JSONObject msg = new JSONObject();
        msg.put("id", id);
        msg.put("signaling", sdpObj);
        sendSignalingMessage("soac", msg, null);
    } catch (JSONException e) {
        DCHECK(e);
    }
}

18 View Complete Implementation : PeerConnectionWrapper.java
Copyright GNU General Public License v3.0
Author : bcmapp
public void setLocalDescription(SessionDescription sdp) throws PeerConnectionException {
    final SettableFuture<Boolean> future = new SettableFuture<>();
    peerConnection.setLocalDescription(new SdpObserver() {

        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            throw new replacedertionError();
        }

        @Override
        public void onCreateFailure(String error) {
            throw new replacedertionError();
        }

        @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 replacedertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}

18 View Complete Implementation : SignalingParameters.java
Copyright GNU Affero General Public License v3.0
Author : RestComm
public clreplaced SignalingParameters {

    private static final String TAG = "SignalingParameters";

    public List<PeerConnection.IceServer> iceServers;

    public final boolean initiator;

    public final String clientId;

    // public final String wssUrl;
    public final String sipUrl;

    public final String wssPostUrl;

    public SessionDescription offerSdp;

    public SessionDescription answerSdp;

    public List<IceCandidate> iceCandidates;

    public HashMap<String, String> sipHeaders;

    public boolean videoEnabled;

    // public List<IceCandidate> answerIceCandidates;
    public SignalingParameters(List<PeerConnection.IceServer> iceServers, boolean initiator, String clientId, String sipUrl, String wssPostUrl, SessionDescription offerSdp, List<IceCandidate> iceCandidates, HashMap<String, String> sipHeaders, boolean videoEnabled) {
        this.iceServers = iceServers;
        this.initiator = initiator;
        this.clientId = clientId;
        this.sipUrl = sipUrl;
        this.wssPostUrl = wssPostUrl;
        this.offerSdp = offerSdp;
        this.answerSdp = null;
        this.iceCandidates = iceCandidates;
        this.sipHeaders = sipHeaders;
        this.videoEnabled = videoEnabled;
    // this.answerIceCandidates = null;
    }

    public SignalingParameters() {
        this.iceServers = null;
        this.initiator = false;
        this.clientId = "";
        this.sipUrl = "";
        this.wssPostUrl = "";
        this.offerSdp = null;
        this.answerSdp = null;
        this.iceCandidates = null;
        this.sipHeaders = null;
        this.videoEnabled = false;
    // this.answerIceCandidates = null;
    }

    // combines offerSdp with iceCandidates and comes up with the full SDP
    public String generateSipSdp(SessionDescription offerSdp, List<IceCandidate> iceCandidates) {
        // concatenate all candidates in one String
        String audioCandidates = "";
        String videoCandidates = "";
        boolean isVideo = false;
        for (IceCandidate candidate : iceCandidates) {
            // Log.e(TAG, "@@@@ candidate.sdp: " + candidate.sdp);
            // Remember that chrome distinguishes audio vs video with different names than FF.
            // Chrome uses 'audio' while FF uses 'sdparta_0' for audio
            // and chrome uses 'video' while FF uses 'sdparta_1' for video
            if (candidate.sdpMid.equals("audio") || candidate.sdpMid.equals("sdparta_0")) {
                audioCandidates += "a=" + candidate.sdp + "\r\n";
            }
            if (candidate.sdpMid.equals("video") || candidate.sdpMid.equals("sdparta_1")) {
                videoCandidates += "a=" + candidate.sdp + "\r\n";
                isVideo = true;
            }
        }
        // Log.e(TAG, "@@@@ audio candidates: " + audioCandidates);
        // Log.e(TAG, "@@@@ video candidates: " + videoCandidates);
        // Log.e(TAG, "@@@@ Before replace: " + offerSdp.description);
        // first, audio
        // place the candidates after the 'a=rtcp:' string; use replace all because
        // we are supporting both audio and video so more than one replacements will be made
        // String resultString = offerSdp.description.replaceFirst("(a=rtcp:.*?\\r\\n)", "$1" + audioCandidates);
        Matcher matcher = Pattern.compile("(a=rtcp:.*?\\r\\n)").matcher(offerSdp.description);
        int index = 0;
        StringBuffer stringBuffer = new StringBuffer();
        while (matcher.find()) {
            if (index == 0) {
                // audio
                matcher.appendReplacement(stringBuffer, "$1" + audioCandidates);
            } else {
                // video
                matcher.appendReplacement(stringBuffer, "$1" + videoCandidates);
            }
            index++;
        }
        matcher.appendTail(stringBuffer);
        // Log.v(TAG, "@@@@ After replace: " + stringBuffer.toString());
        return stringBuffer.toString();
    }

    // gets a full SDP and a. populates .iceCandidates with individual candidates, and
    // b. removes the candidates from the SDP string and returns it as .offerSdp
    public static SignalingParameters extractCandidates(SessionDescription sdp) {
        SignalingParameters params = new SignalingParameters();
        params.iceCandidates = new LinkedList<IceCandidate>();
        // first parse the candidates
        // TODO: for video to work properly we need to do some more work to split the full SDP and differentiate candidates
        // based on media type (i.e. audio vs. video)
        // Matcher matcher = Pattern.compile("a=(candidate.*?)\\r\\n").matcher(sdp.description);
        Matcher matcher = Pattern.compile("m=audio|m=video|a=(candidate.*)\\r\\n").matcher(sdp.description);
        String collectionState = "none";
        while (matcher.find()) {
            if (matcher.group(0).equals("m=audio")) {
                collectionState = "audio";
                continue;
            }
            if (matcher.group(0).equals("m=video")) {
                collectionState = "video";
                continue;
            }
            IceCandidate iceCandidate = new IceCandidate(collectionState, 0, matcher.group(1));
            params.iceCandidates.add(iceCandidate);
        }
        // remove candidates from SDP
        params.offerSdp = new SessionDescription(sdp.type, sdp.description.replaceAll("a=candidate.*?\\r\\n", ""));
        // remove candidates from SDP together with any 'end-of-candidates' a-line.
        // params.offerSdp = new SessionDescription(sdp.type, sdp.description.replaceAll("a=candidate.*?\\r\\n", "").replaceAll("a=end-of-candidates.*?\\r\\n", ""));
        return params;
    }

    public void addIceCandidate(IceCandidate iceCandidate) {
        if (this.iceCandidates == null) {
            this.iceCandidates = new LinkedList<IceCandidate>();
        }
        this.iceCandidates.add(iceCandidate);
    }

    public void addIceServer(PeerConnection.IceServer iceServer) {
        if (this.iceServers == null) {
            this.iceServers = new LinkedList<PeerConnection.IceServer>();
        }
        this.iceServers.add(iceServer);
    }
}

18 View Complete Implementation : PeerConnectionClient.java
Copyright MIT License
Author : wmhameed
public void setRemoteDescription(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            if (peerConnection == null || isError) {
                return;
            }
            String sdpDescription = sdp.description;
            if (preferIsac) {
                sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
            }
            if (videoCallEnabled) {
                sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
            }
            if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) {
                sdpDescription = setStartBitrate(VIDEO_CODEC_VP8, true, sdpDescription, peerConnectionParameters.videoStartBitrate);
                sdpDescription = setStartBitrate(VIDEO_CODEC_VP9, true, sdpDescription, peerConnectionParameters.videoStartBitrate);
                sdpDescription = setStartBitrate(VIDEO_CODEC_H264, true, sdpDescription, peerConnectionParameters.videoStartBitrate);
            }
            if (peerConnectionParameters.audioStartBitrate > 0) {
                sdpDescription = setStartBitrate(AUDIO_CODEC_OPUS, false, sdpDescription, peerConnectionParameters.audioStartBitrate);
            }
            Log.d(TAG, "Set remote SDP.");
            SessionDescription sdpRemote = new SessionDescription(sdp.type, sdpDescription);
            peerConnection.setRemoteDescription(sdpObserver, sdpRemote);
        }
    });
}

18 View Complete Implementation : PeerConnectionHelper.java
Copyright MIT License
Author : ddssingsong
public void onReceiverAnswer(String socketId, String sdp) {
    executor.execute(() -> {
        Peer mPeer = _connectionPeerDic.get(socketId);
        SessionDescription sessionDescription = new SessionDescription(SessionDescription.Type.ANSWER, sdp);
        if (mPeer != null) {
            mPeer.pc.setRemoteDescription(mPeer, sessionDescription);
        }
    });
}

18 View Complete Implementation : PeerConnectionHelper.java
Copyright MIT License
Author : ddssingsong
public void onReceiveOffer(String socketId, String description) {
    executor.execute(() -> {
        _role = Role.Receiver;
        Peer mPeer = _connectionPeerDic.get(socketId);
        String sessionDescription = description;
        if (videoEnable) {
            sessionDescription = preferCodec(description, VIDEO_CODEC_H264, false);
        }
        SessionDescription sdp = new SessionDescription(SessionDescription.Type.OFFER, sessionDescription);
        if (mPeer != null) {
            mPeer.pc.setRemoteDescription(mPeer, sdp);
        }
    });
}

17 View Complete Implementation : WebRTCActivity.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : GoBelieveIO
// Send local answer SDP to the other participant.
public void sendAnswerSdp(final SessionDescription sdp) {
    JSONObject json = new JSONObject();
    jsonPut(json, "sdp", sdp.description);
    jsonPut(json, "type", "answer");
    sendP2PMessage(json);
}

17 View Complete Implementation : WebRTCActivity.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : GoBelieveIO
public void sendOfferSdp(final SessionDescription sdp) {
    JSONObject json = new JSONObject();
    jsonPut(json, "sdp", sdp.description);
    jsonPut(json, "type", "offer");
    sendP2PMessage(json);
}

17 View Complete Implementation : PeerVideoActivity.java
Copyright Apache License 2.0
Author : nubomedia-vtt
@Override
public void onLocalSdpOfferGenerated(final SessionDescription sessionDescription, final NBMPeerConnection nbmPeerConnection) {
    if (callState == CallState.PUBLISHING || callState == CallState.PUBLISHED) {
        Log.d(TAG, "Sending " + sessionDescription.type);
        publishVideoRequestId = ++Constants.id;
        MainActivity.getKurentoRoomAPIInstance().sendPublishVideo(sessionDescription.description, false, publishVideoRequestId);
    } else {
        // Asking for remote user video
        Log.d(TAG, "Sending " + sessionDescription.type);
        publishVideoRequestId = ++Constants.id;
        String username = nbmPeerConnection.getConnectionId();
        videoRequestUserMapping.put(publishVideoRequestId, username);
        MainActivity.getKurentoRoomAPIInstance().sendReceiveVideoFrom(username, "webcam", sessionDescription.description, publishVideoRequestId);
    }
}

17 View Complete Implementation : NBMPeerConnection.java
Copyright Apache License 2.0
Author : nubomedia-vtt
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
    replacedert (localSdp != null);
    String sdpDescription = sessionDescription.description;
    if (preferIsac) {
        sdpDescription = preferCodec(sdpDescription, NBMMediaConfiguration.NBMAudioCodec.ISAC.toString(), true);
    }
    if (videoCallEnabled && preferH264) {
        sdpDescription = preferCodec(sdpDescription, NBMMediaConfiguration.NBMVideoCodec.H264.toString(), false);
    }
    final SessionDescription sdp = new SessionDescription(sessionDescription.type, sdpDescription);
    localSdp = sdp;
    executor.execute(new Runnable() {

        @Override
        public void run() {
            if (pc != null) {
                // && !isError) {
                Log.d(TAG, "Set local SDP from " + sdp.type);
                pc.setLocalDescription(NBMPeerConnection.this, sdp);
            }
        }
    });
}

17 View Complete Implementation : NBMWebRTCPeer.java
Copyright Apache License 2.0
Author : nubomedia-vtt
/**
 * Processes received SDP offer
 * <p>
 *
 * <p>
 * @param remoteOffer The received offer
 * @param connectionId A unique identifier for the connection
 */
@SuppressWarnings("unused")
public void processOffer(SessionDescription remoteOffer, String connectionId) {
    executor.execute(new ProcessOfferTask(remoteOffer, connectionId));
}

17 View Complete Implementation : PeerConnectionChannel.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
public void processSignalingMessage(JSONObject data) throws JSONException {
    String signalingType = data.getString("type");
    if (signalingType.equals("candidates")) {
        IceCandidate candidate = new IceCandidate(data.getString("sdpMid"), data.getInt("sdpMLineIndex"), data.getString("candidate"));
        addOrQueueCandidate(candidate);
    } else if (signalingType.equals("offer") || signalingType.equals("answer")) {
        // When gets an SDP during onError, it means that i'm waiting for peer to re-configure
        // itself to keep compatibility with me.
        if (onError) {
            // Ignore the SDP only once.
            onError = false;
            return;
        }
        String sdpString = data.getString("sdp");
        SessionDescription remoteSdp = new SessionDescription(SessionDescription.Type.fromCanonicalForm(signalingType), sdpString);
        setRemoteDescription(remoteSdp);
    }
}

17 View Complete Implementation : PeerConnectionChannel.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
private SessionDescription preferCodecs(SessionDescription sdp, boolean video) {
    LinkedHashSet<String> preferredCodecs = new LinkedHashSet<>();
    if (video) {
        for (VideoCodec codec : this.videoCodecs) {
            preferredCodecs.add(codec.name);
        }
        preferredCodecs.add("red");
        preferredCodecs.add("ulpfec");
    } else {
        for (AudioCodec codec : audioCodecs) {
            preferredCodecs.add(codec.name);
        }
        preferredCodecs.add("CN");
        preferredCodecs.add("telephone-event");
    }
    return preferCodec(sdp, preferredCodecs, video);
}

17 View Complete Implementation : P2PClient.java
Copyright Apache License 2.0
Author : open-webrtc-toolkit
@Override
public void onLocalDescription(final String peerId, SessionDescription localSdp) {
    try {
        JSONObject sdpObject = new JSONObject();
        sdpObject.put("type", localSdp.type.canonicalForm());
        sdpObject.put("sdp", localSdp.description);
        sendSignalingMessage(peerId, SIGNALING_MESSAGE, sdpObject, new ActionCallback<Void>() {

            @Override
            public void onSuccess(Void result) {
            // succeed to send sdp, no action needed here.
            }

            @Override
            public void onFailure(OwtError error) {
                synchronized (pcChannelsLock) {
                    // failed to send sdp, trigger callbacks.
                    getPeerConnection(peerId).processError(error);
                    getPeerConnection(peerId).dispose();
                    pcChannels.remove(peerId);
                }
            }
        });
    } catch (JSONException e) {
        DCHECK(e);
    }
}

17 View Complete Implementation : SignalingClient.java
Copyright Apache License 2.0
Author : rome753
public void sendSessionDescription(SessionDescription sdp) {
    JSONObject jo = new JSONObject();
    try {
        jo.put("type", sdp.type.canonicalForm());
        jo.put("sdp", sdp.description);
        socket.emit("message", jo);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

17 View Complete Implementation : CallActivity.java
Copyright Apache License 2.0
Author : sokunmin
@Override
public void onRemoteDescription(final SessionDescription sdp) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(() -> {
        if (peerConnectionClient == null) {
            Log.e(LOG_TAG, "Received remote SDP for non-initilized peer connection.");
            return;
        }
        logAndToast("Received remote " + sdp.type + ", delay=" + delta + "ms");
        peerConnectionClient.setRemoteDescription(sdp);
        if (!signalingParameters.initiator) {
            logAndToast("Creating ANSWER...");
            // Create answer. Answer SDP will be sent to offering client in
            // PeerConnectionEvents.onLocalDescription event.
            peerConnectionClient.createAnswer();
        }
    });
}

17 View Complete Implementation : WebSocketRTCClient.java
Copyright MIT License
Author : wmhameed
// Send local answer SDP to the other participant.
@Override
public void sendAnswerSdp(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            if (connectionParameters.loopback) {
                Log.e(TAG, "Sending answer in loopback mode.");
                return;
            }
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "answer");
            wsClient.send(json.toString());
        }
    });
}

17 View Complete Implementation : WebSocketRTCClient.java
Copyright MIT License
Author : wmhameed
// Send local offer SDP to the other participant.
@Override
public void sendOfferSdp(final SessionDescription sdp) {
    executor.execute(new Runnable() {

        @Override
        public void run() {
            if (roomState != ConnectionState.CONNECTED) {
                reportError("Sending offer SDP in non connected state.");
                return;
            }
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "offer");
            sendPostMessage(MessageType.MESSAGE, messageUrl, json.toString());
            if (connectionParameters.loopback) {
                // In loopback mode rename this offer to answer and route it back.
                SessionDescription sdpAnswer = new SessionDescription(SessionDescription.Type.fromCanonicalForm("answer"), sdp.description);
                events.onRemoteDescription(sdpAnswer);
            }
        }
    });
}

17 View Complete Implementation : WebSocketRTCClient.java
Copyright Apache License 2.0
Author : androidthings
// Send local answer SDP to the other participant.
@Override
public void sendAnswerSdp(final SessionDescription sdp) {
    handler.post(new Runnable() {

        @Override
        public void run() {
            if (connectionParameters.loopback) {
                Log.e(TAG, "Sending answer in loopback mode.");
                return;
            }
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "answer");
            wsClient.send(json.toString());
        }
    });
}

17 View Complete Implementation : WebSocketRTCClient.java
Copyright Apache License 2.0
Author : androidthings
// Send local offer SDP to the other participant.
@Override
public void sendOfferSdp(final SessionDescription sdp) {
    handler.post(new Runnable() {

        @Override
        public void run() {
            if (roomState != ConnectionState.CONNECTED) {
                reportError("Sending offer SDP in non connected state.");
                return;
            }
            JSONObject json = new JSONObject();
            jsonPut(json, "sdp", sdp.description);
            jsonPut(json, "type", "offer");
            sendPostMessage(MessageType.MESSAGE, messageUrl, json.toString());
            if (connectionParameters.loopback) {
                // In loopback mode rename this offer to answer and route it back.
                SessionDescription sdpAnswer = new SessionDescription(SessionDescription.Type.fromCanonicalForm("answer"), sdp.description);
                events.onRemoteDescription(sdpAnswer);
            }
        }
    });
}

17 View Complete Implementation : PeerConnectionWrapper.java
Copyright GNU General Public License v3.0
Author : bcmapp
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 replacedertionError(e);
    } catch (ExecutionException e) {
        throw new PeerConnectionException(e);
    }
}

16 View Complete Implementation : PnPeer.java
Copyright MIT License
Author : GleasonK
@Override
public void onCreateSuccess(final SessionDescription sdp) {
    // TODO: modify sdp to use pcParams prefered codecs
    try {
        JSONObject payload = new JSONObject();
        payload.put("type", sdp.type.canonicalForm());
        payload.put("sdp", sdp.description);
        pcClient.transmitMessage(id, payload);
        pc.setLocalDescription(PnPeer.this, sdp);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

16 View Complete Implementation : PnPeerConnectionClient.java
Copyright MIT License
Author : GleasonK
/**
 * <h1>PeerConnection manager for {@link me.kevingleason.pnwebrtc.PnRTCClient}</h1>
 * <pre>
 * Author:  Kevin Gleason - Boston College '16
 * File:    PnPeerConnectionClient.java
 * Date:    7/20/15
 * Use:     WebRTC PeerConnection Manager
 * © 2009 - 2015 PubNub, Inc.
 * </pre>
 *
 * {@link PnPeerConnectionClient} is used to manage peer connections.
 */
public clreplaced PnPeerConnectionClient {

    // either offer or answer SDP
    private SessionDescription localSdp = null;

    private MediaStream localMediaStream = null;

    PeerConnectionFactory pcFactory;

    PnRTCListener mRtcListener;

    PnSignalingParams signalingParams;

    int MAX_CONNECTIONS = Integer.MAX_VALUE;

    private Pubnub mPubNub;

    private PnRTCReceiver mSubscribeReceiver;

    private Map<String, PnAction> actionMap;

    private Map<String, PnPeer> peers;

    private String id;

    public PnPeerConnectionClient(Pubnub pubnub, PnSignalingParams signalingParams, PnRTCListener rtcListener) {
        this.mPubNub = pubnub;
        this.signalingParams = signalingParams;
        this.mRtcListener = rtcListener;
        // TODO: Check it allowed, else extra param
        this.pcFactory = new PeerConnectionFactory();
        this.peers = new HashMap<String, PnPeer>();
        init();
    }

    private void init() {
        this.actionMap = new HashMap<String, PnAction>();
        this.actionMap.put(CreateOfferAction.TRIGGER, new CreateOfferAction());
        this.actionMap.put(CreateAnswerAction.TRIGGER, new CreateAnswerAction());
        this.actionMap.put(SetRemoteSDPAction.TRIGGER, new SetRemoteSDPAction());
        this.actionMap.put(AddIceCandidateAction.TRIGGER, new AddIceCandidateAction());
        this.actionMap.put(PnUserHangupAction.TRIGGER, new PnUserHangupAction());
        this.actionMap.put(PnUserMessageAction.TRIGGER, new PnUserMessageAction());
        mSubscribeReceiver = new PnRTCReceiver();
    }

    boolean listenOn(String myId) {
        // Todo: return success?
        if (localMediaStream == null) {
            // Not true for streaming?
            mRtcListener.onDebug(new PnRTCMessage("Need to add media stream before you can connect."));
            return false;
        }
        if (this.id != null) {
            // Prevent listening on multiple channels.
            mRtcListener.onDebug(new PnRTCMessage("Already listening on " + this.id + ". Cannot have multiple connections."));
            return false;
        }
        this.id = myId;
        subscribe(myId);
        return true;
    }

    /**
     * TODO: Add a max user threshold.
     *  Connect with another user by their ID.
     *  @param userId The user to establish a WebRTC connection with
     *  @return boolean value of success
     */
    boolean connect(String userId) {
        if (!peers.containsKey(userId)) {
            // Prevents duplicate dials.
            if (peers.size() < MAX_CONNECTIONS) {
                PnPeer peer = addPeer(userId);
                peer.pc.addStream(this.localMediaStream);
                try {
                    actionMap.get(CreateOfferAction.TRIGGER).execute(userId, new JSONObject());
                } catch (JSONException e) {
                    e.printStackTrace();
                    return false;
                }
                return true;
            }
        }
        this.mRtcListener.onDebug(new PnRTCMessage("CONNECT FAILED. Duplicate dial or max peer " + "connections exceeded. Max: " + MAX_CONNECTIONS + " Current: " + this.peers.size()));
        return false;
    }

    public void setRTCListener(PnRTCListener listener) {
        this.mRtcListener = listener;
    }

    private void subscribe(String channel) {
        try {
            mPubNub.subscribe(channel, this.mSubscribeReceiver);
        } catch (PubnubException e) {
            e.printStackTrace();
        }
    }

    public void setLocalMediaStream(MediaStream localStream) {
        this.localMediaStream = localStream;
        mRtcListener.onLocalStream(localStream);
    }

    public MediaStream getLocalMediaStream() {
        return this.localMediaStream;
    }

    private PnPeer addPeer(String id) {
        PnPeer peer = new PnPeer(id, this);
        peers.put(id, peer);
        return peer;
    }

    PnPeer removePeer(String id) {
        PnPeer peer = peers.get(id);
        peer.pc.close();
        return peers.remove(peer.id);
    }

    List<PnPeer> getPeers() {
        return new ArrayList<PnPeer>(this.peers.values());
    }

    /**
     * Close connection (hangup) no a certain peer.
     * @param id PnPeer id to close connection with
     */
    public void closeConnection(String id) {
        JSONObject packet = new JSONObject();
        try {
            if (!this.peers.containsKey(id))
                return;
            PnPeer peer = this.peers.get(id);
            peer.hangup();
            packet.put(PnRTCMessage.JSON_HANGUP, true);
            transmitMessage(id, packet);
            mRtcListener.onPeerConnectionClosed(peer);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    /**
     * Close connections (hangup) on all open connections.
     */
    public void closeAllConnections() {
        Iterator<String> peerIds = this.peers.keySet().iterator();
        while (peerIds.hasNext()) {
            closeConnection(peerIds.next());
        }
    }

    /**
     * Send SDP Offers/Answers nd ICE candidates to peers.
     * @param toID The id or "number" that you wish to transmit a message to.
     * @param packet The JSON data to be transmitted
     */
    void transmitMessage(String toID, JSONObject packet) {
        if (this.id == null) {
            // Not logged in. Put an error in the debug cb.
            mRtcListener.onDebug(new PnRTCMessage("Cannot transmit before calling Client.connect"));
        }
        try {
            JSONObject message = new JSONObject();
            message.put(PnRTCMessage.JSON_PACKET, packet);
            // Todo: session id, unused in js SDK?
            message.put(PnRTCMessage.JSON_ID, "");
            message.put(PnRTCMessage.JSON_NUMBER, this.id);
            this.mPubNub.publish(toID, message, new // Todo: reconsider callback.
            Callback() {

                @Override
                public void successCallback(String channel, Object message, String timetoken) {
                    mRtcListener.onDebug(new PnRTCMessage((JSONObject) message));
                }

                @Override
                public void errorCallback(String channel, PubnubError error) {
                    mRtcListener.onDebug(new PnRTCMessage(error.errorObject));
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private interface PnAction {

        void execute(String peerId, JSONObject payload) throws JSONException;
    }

    private clreplaced CreateOfferAction implements PnAction {

        public static final String TRIGGER = "init";

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("COAction", "CreateOfferAction");
            PnPeer peer = peers.get(peerId);
            peer.setDialed(true);
            peer.setType(PnPeer.TYPE_ANSWER);
            peer.pc.createOffer(peer, signalingParams.pcConstraints);
        }
    }

    private clreplaced CreateAnswerAction implements PnAction {

        public static final String TRIGGER = "offer";

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("CAAction", "CreateAnswerAction");
            PnPeer peer = peers.get(peerId);
            peer.setType(PnPeer.TYPE_OFFER);
            peer.setStatus(PnPeer.STATUS_CONNECTED);
            SessionDescription sdp = new SessionDescription(SessionDescription.Type.fromCanonicalForm(payload.getString("type")), payload.getString("sdp"));
            peer.pc.setRemoteDescription(peer, sdp);
            peer.pc.createAnswer(peer, signalingParams.pcConstraints);
        }
    }

    private clreplaced SetRemoteSDPAction implements PnAction {

        public static final String TRIGGER = "answer";

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("SRSAction", "SetRemoteSDPAction");
            PnPeer peer = peers.get(peerId);
            SessionDescription sdp = new SessionDescription(SessionDescription.Type.fromCanonicalForm(payload.getString("type")), payload.getString("sdp"));
            peer.pc.setRemoteDescription(peer, sdp);
        }
    }

    private clreplaced AddIceCandidateAction implements PnAction {

        public static final String TRIGGER = "candidate";

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("AICAction", "AddIceCandidateAction");
            PeerConnection pc = peers.get(peerId).pc;
            if (pc.getRemoteDescription() != null) {
                IceCandidate candidate = new IceCandidate(payload.getString("sdpMid"), payload.getInt("sdpMLineIndex"), payload.getString("candidate"));
                pc.addIceCandidate(candidate);
            }
        }
    }

    private clreplaced PnUserHangupAction implements PnAction {

        public static final String TRIGGER = PnRTCMessage.JSON_HANGUP;

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("PnUserHangup", "PnUserHangupAction");
            PnPeer peer = peers.get(peerId);
            peer.hangup();
            mRtcListener.onPeerConnectionClosed(peer);
        // Todo: Consider Callback?
        }
    }

    private clreplaced PnUserMessageAction implements PnAction {

        public static final String TRIGGER = PnRTCMessage.JSON_USERMSG;

        public void execute(String peerId, JSONObject payload) throws JSONException {
            Log.d("PnUserMessage", "AddIceCandidateAction");
            JSONObject msgJson = payload.getJSONObject(PnRTCMessage.JSON_USERMSG);
            PnPeer peer = peers.get(peerId);
            mRtcListener.onMessage(peer, msgJson);
        }
    }

    /**
     * @param userId Your id. Used to tag the message before publishing it to another user.
     * @return
     */
    public static JSONObject generateHangupPacket(String userId) {
        JSONObject json = new JSONObject();
        try {
            JSONObject packet = new JSONObject();
            packet.put(PnRTCMessage.JSON_HANGUP, true);
            json.put(PnRTCMessage.JSON_PACKET, packet);
            // Todo: session id, unused in js SDK?
            json.put(PnRTCMessage.JSON_ID, "");
            json.put(PnRTCMessage.JSON_NUMBER, userId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    /**
     * Static method to generate the proper JSON for a user message. Use this when you don't have
     *   a {@link me.kevingleason.pnwebrtc.PnRTCClient} instantiated. Simply send a publish with the
     *   returned JSONObject to the ID that a user is subscribed to.
     * @param userId Your UserID, needed to tag the message
     * @param message The message you with to send some other user
     * @return JSONObject properly formatted for the PubNub WebRTC API
     */
    public static JSONObject generateUserMessage(String userId, JSONObject message) {
        JSONObject json = new JSONObject();
        try {
            JSONObject packet = new JSONObject();
            packet.put(PnRTCMessage.JSON_USERMSG, message);
            json.put(PnRTCMessage.JSON_PACKET, packet);
            // Todo: session id, unused in js SDK?
            json.put(PnRTCMessage.JSON_ID, "");
            json.put(PnRTCMessage.JSON_NUMBER, userId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    private clreplaced PnRTCReceiver extends Callback {

        @Override
        public void connectCallback(String channel, Object message) {
            mRtcListener.onDebug(new PnRTCMessage(((JSONArray) message).toString()));
            mRtcListener.onConnected(channel);
        }

        @Override
        public void successCallback(String channel, Object message) {
            // Ignore if not valid JSON.
            if (!(message instanceof JSONObject))
                return;
            JSONObject jsonMessage = (JSONObject) message;
            mRtcListener.onDebug(new PnRTCMessage(jsonMessage));
            try {
                String peerId = jsonMessage.getString(PnRTCMessage.JSON_NUMBER);
                JSONObject packet = jsonMessage.getJSONObject(PnRTCMessage.JSON_PACKET);
                PnPeer peer;
                if (!peers.containsKey(peerId)) {
                    // Possibly threshold number of allowed users
                    peer = addPeer(peerId);
                    peer.pc.addStream(localMediaStream);
                } else {
                    peer = peers.get(peerId);
                }
                // Do nothing if disconnected.
                if (peer.getStatus().equals(PnPeer.STATUS_DISCONNECTED))
                    return;
                if (packet.has(PnRTCMessage.JSON_USERMSG)) {
                    actionMap.get(PnUserMessageAction.TRIGGER).execute(peerId, packet);
                    return;
                }
                if (packet.has(PnRTCMessage.JSON_HANGUP)) {
                    actionMap.get(PnUserHangupAction.TRIGGER).execute(peerId, packet);
                    return;
                }
                if (packet.has(PnRTCMessage.JSON_THUMBNAIL)) {
                    // No handler for thumbnail or hangup yet, will be separate controller callback
                    return;
                }
                if (packet.has(PnRTCMessage.JSON_SDP)) {
                    if (!peer.received) {
                        peer.setReceived(true);
                        mRtcListener.onDebug(new PnRTCMessage("SDP - " + peer.toString()));
                    // Todo: reveivercb(peer);
                    }
                    String type = packet.getString(PnRTCMessage.JSON_TYPE);
                    actionMap.get(type).execute(peerId, packet);
                    return;
                }
                if (packet.has(PnRTCMessage.JSON_ICE)) {
                    actionMap.get(AddIceCandidateAction.TRIGGER).execute(peerId, packet);
                    return;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void errorCallback(String channel, PubnubError error) {
            super.errorCallback(channel, error);
        }
    }
}

16 View Complete Implementation : WebRTCActivity.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : GoBelieveIO
protected void processP2PMessage(JSONObject json) {
    try {
        String type = json.optString("type");
        if (type.equals("candidate")) {
            this.onRemoteIceCandidate(toJavaCandidate(json));
        } else if (type.equals("remove-candidates")) {
            JSONArray candidateArray = json.getJSONArray("candidates");
            IceCandidate[] candidates = new IceCandidate[candidateArray.length()];
            for (int i = 0; i < candidateArray.length(); ++i) {
                candidates[i] = toJavaCandidate(candidateArray.getJSONObject(i));
            }
            this.onRemoteIceCandidatesRemoved(candidates);
        } else if (type.equals("answer")) {
            if (this.isCaller) {
                SessionDescription sdp = new SessionDescription(SessionDescription.Type.fromCanonicalForm(type), json.getString("sdp"));
                this.onRemoteDescription(sdp);
            } else {
                reportError("Received answer for call initiator");
            }
        } else if (type.equals("offer")) {
            if (!this.isCaller) {
                SessionDescription sdp = new SessionDescription(SessionDescription.Type.fromCanonicalForm(type), json.getString("sdp"));
                this.onRemoteDescription(sdp);
            } else {
                reportError("Received offer for call receiver");
            }
        } else {
            reportError("Unexpected WebSocket message");
        }
    } catch (JSONException e) {
        reportError("WebSocket message JSON parsing error: " + e.toString());
    }
}

16 View Complete Implementation : ViewfinderManager.java
Copyright Apache License 2.0
Author : google
private SessionDescription acceptOffer(SessionDescription remoteSessionDescription, PeerConnection peerConnection) throws IOException {
    BlockingSdpObserver sdbObserver = new BlockingSdpObserver();
    peerConnection.setRemoteDescription(sdbObserver, remoteSessionDescription);
    sdbObserver.waitForSet();
    peerConnection.createAnswer(sdbObserver, createAnswerConstraints());
    SessionDescription localDescription = sdbObserver.waitForCreate();
    peerConnection.setLocalDescription(sdbObserver, localDescription);
    sdbObserver.waitForSet();
    return localDescription;
}

16 View Complete Implementation : NBMPeerConnection.java
Copyright Apache License 2.0
Author : nubomedia-vtt
protected void setRemoteDescriptionSync(SessionDescription sdp) {
    if (pc == null) {
        // || isError) {
        return;
    }
    String sdpDescription = sdp.description;
    if (preferIsac) {
        sdpDescription = preferCodec(sdpDescription, NBMMediaConfiguration.NBMAudioCodec.ISAC.toString(), true);
    }
    if (videoCallEnabled && preferH264) {
        sdpDescription = preferCodec(sdpDescription, NBMMediaConfiguration.NBMVideoCodec.H264.toString(), false);
    }
    if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) {
        sdpDescription = setStartBitrate(NBMMediaConfiguration.NBMVideoCodec.VP8.toString(), true, sdpDescription, peerConnectionParameters.videoStartBitrate);
        sdpDescription = setStartBitrate(NBMMediaConfiguration.NBMVideoCodec.VP9.toString(), true, sdpDescription, peerConnectionParameters.videoStartBitrate);
        sdpDescription = setStartBitrate(NBMMediaConfiguration.NBMVideoCodec.H264.toString(), true, sdpDescription, peerConnectionParameters.videoStartBitrate);
    }
    if (peerConnectionParameters.audioStartBitrate > 0) {
        sdpDescription = setStartBitrate(NBMMediaConfiguration.NBMAudioCodec.OPUS.toString(), false, sdpDescription, peerConnectionParameters.audioStartBitrate);
    }
    Log.d(TAG, "Set remote SDP.");
    SessionDescription sdpRemote = new SessionDescription(sdp.type, sdpDescription);
    pc.setRemoteDescription(NBMPeerConnection.this, sdpRemote);
}

16 View Complete Implementation : SignalingParameters.java
Copyright GNU Affero General Public License v3.0
Author : RestComm
// gets a full SDP and a. populates .iceCandidates with individual candidates, and
// b. removes the candidates from the SDP string and returns it as .offerSdp
public static SignalingParameters extractCandidates(SessionDescription sdp) {
    SignalingParameters params = new SignalingParameters();
    params.iceCandidates = new LinkedList<IceCandidate>();
    // first parse the candidates
    // TODO: for video to work properly we need to do some more work to split the full SDP and differentiate candidates
    // based on media type (i.e. audio vs. video)
    // Matcher matcher = Pattern.compile("a=(candidate.*?)\\r\\n").matcher(sdp.description);
    Matcher matcher = Pattern.compile("m=audio|m=video|a=(candidate.*)\\r\\n").matcher(sdp.description);
    String collectionState = "none";
    while (matcher.find()) {
        if (matcher.group(0).equals("m=audio")) {
            collectionState = "audio";
            continue;
        }
        if (matcher.group(0).equals("m=video")) {
            collectionState = "video";
            continue;
        }
        IceCandidate iceCandidate = new IceCandidate(collectionState, 0, matcher.group(1));
        params.iceCandidates.add(iceCandidate);
    }
    // remove candidates from SDP
    params.offerSdp = new SessionDescription(sdp.type, sdp.description.replaceAll("a=candidate.*?\\r\\n", ""));
    // remove candidates from SDP together with any 'end-of-candidates' a-line.
    // params.offerSdp = new SessionDescription(sdp.type, sdp.description.replaceAll("a=candidate.*?\\r\\n", "").replaceAll("a=end-of-candidates.*?\\r\\n", ""));
    return params;
}

16 View Complete Implementation : SignalingClient.java
Copyright Apache License 2.0
Author : rome753
public void sendSessionDescription(SessionDescription sdp, String to) {
    JSONObject jo = new JSONObject();
    try {
        jo.put("type", sdp.type.canonicalForm());
        jo.put("sdp", sdp.description);
        jo.put("from", socket.id());
        jo.put("to", to);
        socket.emit("message", jo);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}