我能够在本地创建报价并将 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: FAILED”需要我添加到 -> addIceCandidate 吗?