我能够在本地创建Offoff并将sdp发送到服务器。此外,我还得到了服务器的答复并得到了sdp。
现在,如何将本地视频流发送到服务器?我不要服务器视频。
private void startStreamingVideo() {
//creating local mediastream
MediaStream mediaStream = factory.createLocalMediaStream("ARDAMS");
mediaStream.addTrack(localAudioTrack);
mediaStream.addTrack(localVideoTrack);
localPeerConnection.addStream(mediaStream);
MediaConstraints sdpMediaConstraints = new MediaConstraints();
sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "false"));
sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "false"));
localPeerConnection.createOffer(new SimpleSdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
Log.d(TAG, "onCreateSuccess: ");
localPeerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription);
//remotePeerConnection.setRemoteDescription(new SimpleSdpObserver(), sessionDescription);
callApiOffer(new Example(sessionDescription.description,sessionDescription.type.name().toLowerCase()));
}
}, sdpMediaConstraints);
}
private void callApiOffer(Example example){
Utils.getInstance().getRetrofitInstance1().postRequest(example).enqueue(new Callback<ResponseExample>() {
@Override
public void onResponse(Call<ResponseExample> call, Response<ResponseExample> response) {
ResponseExample body = response.body();
if (body != null) {
Log.e(TAG, body.getType());
Log.e(TAG, body.getSdp());
// Here, I got server sdp and type="answer"
SessionDescription sessionDescription = new SessionDescription(Type.ANSWER, body.getSdp());
localPeerConnection.setRemoteDescription(new SimpleSdpObserver(), sessionDescription);
//doAnswer();
}
}
@Override
public void onFailure(Call<ResponseExample> call, Throwable t) {
t.printStackTrace();
}
});
}
后端服务器在Python aiortc中
我收到“ onIceConnectionChange:失败” 我需要添加到-> addIceCandidate吗?
答案 0 :(得分:0)
您必须添加对等连接观察器并在onIceCandidate方法中发送icecandidate。在接收方,您可以添加icecandidate。