org.webrtc.SessionDescription Java Examples

The following examples show how to use org.webrtc.SessionDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onCreateSuccess(final SessionDescription origSdp) {
    if (localSdp != null) {
        reportError("Multiple SDP create.");
        return;
    }
    String sdpDescription = origSdp.description;
    if (preferIsac) {
        sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
    }
    if (isVideoCallEnabled()) {
        sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
    }
    final SessionDescription sdp = new SessionDescription(origSdp.type, sdpDescription);
    localSdp = sdp;
    executor.execute(new Runnable() {
        @Override
        public void run() {
            if (peerConnection != null && !isError) {
                Log.d(TAG, "Set local SDP from " + sdp.type);
                peerConnection.setLocalDescription(sdpObserver, sdp);
            }
        }
    });
}
 
Example #2
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateSuccess(final SessionDescription origSdp) {
  if (localSdp != null) {
    reportError("Multiple SDP create.");
    return;
  }
  String sdpDescription = origSdp.description;
  if (preferIsac) {
    sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
  }
  if (videoCallEnabled) {
    sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
  }
  final SessionDescription sdp = new SessionDescription(origSdp.type, sdpDescription);
  localSdp = sdp;
  executor.execute(new Runnable() {
    @Override
    public void run() {
      if (peerConnection != null && !isError) {
        Log.d(TAG, "Set local SDP from " + sdp.type);
        peerConnection.setLocalDescription(sdpObserver, sdp);
      }
    }
  });
}
 
Example #3
Source File: WebSocketRTCClient.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@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);
            }
        }
    });
}
 
Example #4
Source File: PeerVideoActivity.java    From nubo-test with Apache License 2.0 6 votes vote down vote up
@Override
public void onRoomResponse(RoomResponse response) {
    Log.d(TAG, "OnRoomResponse:" + response);
    int requestId =response.getId();

    if (requestId == publishVideoRequestId){

        SessionDescription sd = new SessionDescription(SessionDescription.Type.ANSWER,
                                                        response.getValue("sdpAnswer").get(0));

        // Check if we are waiting for publication of our own vide
        if (callState == CallState.PUBLISHING){
            callState = CallState.PUBLISHED;
            nbmWebRTCPeer.processAnswer(sd, "local");
            mHandler.postDelayed(offerWhenReady, 2000);

        // Check if we are waiting for the video publication of the other peer
        } else if (callState == CallState.WAITING_REMOTE_USER){
            //String user_name = Integer.toString(publishVideoRequestId);
            callState = CallState.RECEIVING_REMOTE_USER;
            String connectionId = videoRequestUserMapping.get(publishVideoRequestId);
            nbmWebRTCPeer.processAnswer(sd, connectionId);
        }
    }

}
 
Example #5
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public void onOfferReceived(JSONObject data) {
    runOnUiThread(() -> {
        final String socketId = data.optString("from");
        PeerConnection peerConnection = getOrCreatePeerConnection(socketId);
        peerConnection.setRemoteDescription(new SdpAdapter("setRemoteSdp:" + socketId),
                new SessionDescription(SessionDescription.Type.OFFER, data.optString("sdp")));
        peerConnection.createAnswer(new SdpAdapter("localAnswerSdp") {
            @Override
            public void onCreateSuccess(SessionDescription sdp) {
                super.onCreateSuccess(sdp);
                peerConnectionMap.get(socketId).setLocalDescription(new SdpAdapter("setLocalSdp:" + socketId), sdp);
                SignalingClient.get().sendSessionDescription(sdp, socketId);
            }
        }, new MediaConstraints());

    });
}
 
Example #6
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
ListenableFuture<SessionDescription> createOffer() {
    return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
        final SettableFuture<SessionDescription> future = SettableFuture.create();
        peerConnection.createOffer(new CreateSdpObserver() {
            @Override
            public void onCreateSuccess(SessionDescription sessionDescription) {
                future.set(sessionDescription);
            }

            @Override
            public void onCreateFailure(String s) {
                future.setException(new IllegalStateException("Unable to create offer: " + s));
            }
        }, new MediaConstraints());
        return future;
    }, MoreExecutors.directExecutor());
}
 
Example #7
Source File: VideoChatHelper.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {

    this.pc.setLocalDescription(this, sessionDescription);

    // 向服务器发送offer
    JSONObject offer = new JSONObject();
    JSONObject sdp = new JSONObject();
    String type = sessionDescription.type.canonicalForm();
    FLLog.i("查看type是否正确:" + type);
    try {
        sdp.put("type", type);
        sdp.put("sdp", sessionDescription.description);
        FLLog.i("可能错误description");
        offer.put("socketId", this.id);
        offer.put("sdp", sdp);

        String event = "__" + type;
        SocketManager.socket.emit(event, offer);
    } catch (JSONException e) {

        FLLog.i("错误:offer发送为空");
        e.printStackTrace();
    }
}
 
Example #8
Source File: PeerConnectionClient.java    From janus-gateway-android with MIT License 6 votes vote down vote up
public void subscriberHandleRemoteJsep(final BigInteger handleId, final SessionDescription sdp) {
    executor.execute(new Runnable() {
      @Override
      public void run() {
        PeerConnection peerConnection = createPeerConnection(handleId, false);
        SDPObserver sdpObserver = peerConnectionMap.get(handleId).sdpObserver;
        if (peerConnection == null || isError) {
          return;
        }
        JanusConnection connection = peerConnectionMap.get(handleId);
        peerConnection.setRemoteDescription(sdpObserver, sdp);
        Log.d(TAG, "PC create ANSWER");
        peerConnection.createAnswer(connection.sdpObserver, sdpMediaConstraints);
      }
    });
}
 
Example #9
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
public void onOfferReceived(JSONObject data) {
    runOnUiThread(() -> {
        peerConnection.setRemoteDescription(new SdpAdapter("localSetRemote"),
                new SessionDescription(SessionDescription.Type.OFFER, data.optString("sdp")));
        peerConnection.createAnswer(new SdpAdapter("localAnswerSdp") {
            @Override
            public void onCreateSuccess(SessionDescription sdp) {
                super.onCreateSuccess(sdp);
                peerConnection.setLocalDescription(new SdpAdapter("localSetLocal"), sdp);
                SignalingClient.get().sendSessionDescription(sdp);
            }
        }, new MediaConstraints());

    });
}
 
Example #10
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
ListenableFuture<Void> setRemoteDescription(final SessionDescription sessionDescription) {
    Log.d(EXTENDED_LOGGING_TAG, "setting remote description:");
    for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) {
        Log.d(EXTENDED_LOGGING_TAG, line);
    }
    return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
        final SettableFuture<Void> future = SettableFuture.create();
        peerConnection.setRemoteDescription(new SetSdpObserver() {
            @Override
            public void onSetSuccess() {
                future.set(null);
            }

            @Override
            public void onSetFailure(String s) {
                future.setException(new IllegalArgumentException("unable to set remote session description: " + s));

            }
        }, sessionDescription);
        return future;
    }, MoreExecutors.directExecutor());
}
 
Example #11
Source File: WebRTCActivity.java    From voip_android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();
            }
        }
    });
}
 
Example #12
Source File: CallActivity.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@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);
                }
            }
        }
    });
}
 
Example #13
Source File: WebSocketChannel.java    From janus-gateway-android with MIT License 6 votes vote down vote up
public void publisherCreateOffer(final BigInteger handleId, final SessionDescription sdp) {
    JSONObject publish = new JSONObject();
    JSONObject jsep = new JSONObject();
    JSONObject message = new JSONObject();
    try {
        publish.putOpt("request", "configure");
        publish.putOpt("audio", true);
        publish.putOpt("video", true);

        jsep.putOpt("type", sdp.type);
        jsep.putOpt("sdp", sdp.description);

        message.putOpt("janus", "message");
        message.putOpt("body", publish);
        message.putOpt("jsep", jsep);
        message.putOpt("transaction", randomString(12));
        message.putOpt("session_id", mSessionId);
        message.putOpt("handle_id", handleId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mWebSocket.send(message.toString());
}
 
Example #14
Source File: CallActivity.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@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();
            }
        }
    });
}
 
Example #15
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
@Override
public void onCreateSuccess(final SessionDescription origSdp) {
    if (localSdp != null) {
        reportError("Multiple SDP create.");
        return;
    }
    String sdpDescription = origSdp.description;
    if (preferIsac) {
        sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
    }
    if (videoCallEnabled) {
        sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
    }
    final SessionDescription sdp = new SessionDescription(
            origSdp.type, sdpDescription);
    localSdp = sdp;
    executor.execute(new Runnable() {
        @Override
        public void run() {
            if (peerConnection != null && !isError) {
                Log.d(TAG, "Set local SDP from " + sdp.type);
                peerConnection.setLocalDescription(sdpObserver, sdp);
            }
        }
    });
}
 
Example #16
Source File: ConferenceClient.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #17
Source File: WebRtcClient.java    From imsdk-android with MIT License 6 votes vote down vote up
private void setRemoteSDP(SessionDescription remoteSDP) {
    if (peer.pc == null || isError) {
        return;
    }
    String sdpDescription = remoteSDP.description;
    if (preferIsac) {
        sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
    }
    if (pcParams.videoCallEnabled) {
        sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
    }
    if (pcParams.audioStartBitrate > 0) {
        sdpDescription = setStartBitrate(
                AUDIO_CODEC_OPUS, false, sdpDescription, pcParams.audioStartBitrate);
    }
    if(pcParams.videoMaxBitrate >0)
    {
        sdpDescription = setStartBitrate(preferredVideoCodec,true,sdpDescription,
                pcParams.videoMaxBitrate);
    }
    sdpDescription = setMaxFs(sdpDescription);
    LogUtil.d(TAG, "Set remote SDP.");
    Logger.i(TAG + " Set remote SDP.");
    SessionDescription sdpRemote = new SessionDescription(remoteSDP.type, sdpDescription);
    peer.pc.setRemoteDescription(peer, sdpRemote);
}
 
Example #18
Source File: PeerConnectionChannel.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@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);
    });
}
 
Example #19
Source File: PeerConnectionChannel.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #20
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
    });
}
 
Example #21
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 6 votes vote down vote up
@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();
            }
        }
    });
}
 
Example #22
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
ListenableFuture<Void> setLocalDescription(final SessionDescription sessionDescription) {
    Log.d(EXTENDED_LOGGING_TAG, "setting local description:");
    for (final String line : sessionDescription.description.split(eu.siacs.conversations.xmpp.jingle.SessionDescription.LINE_DIVIDER)) {
        Log.d(EXTENDED_LOGGING_TAG, line);
    }
    return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
        final SettableFuture<Void> future = SettableFuture.create();
        peerConnection.setLocalDescription(new SetSdpObserver() {
            @Override
            public void onSetSuccess() {
                future.set(null);
            }

            @Override
            public void onSetFailure(final String s) {
                future.setException(new IllegalArgumentException("unable to set local session description: " + s));

            }
        }, sessionDescription);
        return future;
    }, MoreExecutors.directExecutor());
}
 
Example #23
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
ListenableFuture<SessionDescription> createAnswer() {
    return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
        final SettableFuture<SessionDescription> future = SettableFuture.create();
        peerConnection.createAnswer(new CreateSdpObserver() {
            @Override
            public void onCreateSuccess(SessionDescription sessionDescription) {
                future.set(sessionDescription);
            }

            @Override
            public void onCreateFailure(String s) {
                future.setException(new IllegalStateException("Unable to create answer: " + s));
            }
        }, new MediaConstraints());
        return future;
    }, MoreExecutors.directExecutor());
}
 
Example #24
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
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 (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);
    }
  });
}
 
Example #25
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateSuccess(final SessionDescription origSdp) {
  if (localSdp != null) {
    reportError("Multiple SDP create.");
    return;
  }
  String sdpDescription = origSdp.description;
  if (preferIsac) {
    sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
  }
  if (videoCallEnabled) {
    sdpDescription = preferCodec(sdpDescription, preferredVideoCodec, false);
  }
  final SessionDescription sdp = new SessionDescription(origSdp.type, sdpDescription);
  localSdp = sdp;
  executor.execute(new Runnable() {
    @Override
    public void run() {
      if (peerConnection != null && !isError) {
        Log.d(TAG, "Set local SDP from " + sdp.type);
        peerConnection.setLocalDescription(sdpObserver, sdp);
      }
    }
  });
}
 
Example #26
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 6 votes vote down vote up
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 (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);
    }
  });
}
 
Example #27
Source File: CallActivity.java    From RTCStartupDemo with GNU General Public License v3.0 6 votes vote down vote up
public void doAnswerCall() {
    logcatOnUI("Answer Call, Wait ...");
    if (mPeerConnection == null) {
        mPeerConnection = createPeerConnection();
    }
    MediaConstraints sdpMediaConstraints = new MediaConstraints();
    Log.i(TAG, "Create answer ...");
    mPeerConnection.createAnswer(new SimpleSdpObserver() {
        @Override
        public void onCreateSuccess(SessionDescription sessionDescription) {
            Log.i(TAG, "Create answer success !");
            mPeerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription);
            JSONObject message = new JSONObject();
            try {
                message.put("userId", RTCSignalClient.getInstance().getUserId());
                message.put("msgType", RTCSignalClient.MESSAGE_TYPE_ANSWER);
                message.put("sdp", sessionDescription.description);
                RTCSignalClient.getInstance().sendMessage(message);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, sdpMediaConstraints);
    updateCallState(false);
}
 
Example #28
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
ListenableFuture<SessionDescription> createAnswer() {
    return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
        final SettableFuture<SessionDescription> future = SettableFuture.create();
        peerConnection.createAnswer(new CreateSdpObserver() {
            @Override
            public void onCreateSuccess(SessionDescription sessionDescription) {
                future.set(sessionDescription);
            }

            @Override
            public void onCreateFailure(String s) {
                future.setException(new IllegalStateException("Unable to create answer: " + s));
            }
        }, new MediaConstraints());
        return future;
    }, MoreExecutors.directExecutor());
}
 
Example #29
Source File: PnPeer.java    From AndroidRTC with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example #30
Source File: CustomWebSocketListener.java    From WebRTCapp with Apache License 2.0 5 votes vote down vote up
private void saveAnswer(JSONObject json) throws JSONException {
    SessionDescription sessionDescription = new SessionDescription(SessionDescription.Type.ANSWER, json.getString("sdpAnswer"));
    if (localPeer.getRemoteDescription() == null) {
        localPeer.setRemoteDescription(new CustomSdpObserver("localSetRemoteDesc"), sessionDescription);
    } else {
        participants.get(remoteParticipantId).getPeerConnection().setRemoteDescription(new CustomSdpObserver("remoteSetRemoteDesc"), sessionDescription);
    }
}