关于这个问题已经有很多问题,但它们都与 Javascript 有关。我正在尝试使用 Android,但我onIceCandidate()
打电话时永远不会被调用setLocalDescription
。
private PeerConnection initPeerConnection(boolean isLocal) {
MediaConstraints sdpConstraints = new MediaConstraints();
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true"));
sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true"));
List<PeerConnection.IceServer> servers = new ArrayList<>();
return peerConnectionFactory.createPeerConnection(servers, new CustomPeerConnectionObserver() {
@Override
public void onIceCandidate(IceCandidate iceCandidate) {
super.onIceCandidate(iceCandidate);
if (isLocal)
onIceCandidateReceived(localPeerConnection, iceCandidate);
else
onIceCandidateReceived(remotePeerConnection, iceCandidate);
}
@Override
public void onAddStream(MediaStream mediaStream) {
super.onAddStream(mediaStream);
if (!isLocal)
gotRemoteStream(mediaStream);
}
});
}
创建连接:
localPeerConnection = initPeerConnection(true);
remotePeerConnection = initPeerConnection(false);
创建报价。现在它应该触发 onIceCandidate():
localPeerConnection.createOffer(new SimpleSdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
Log.e("SDP", sessionDescription.description + sessionDescription.type.toString());
localPeerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription);
sendOffer(sessionDescription);
}
}, sdpMediaConstraints);
但不幸的是它不会触发它。怎么了?什么是正确的?
注意:任何特定于Android JavaScript的答案将不胜感激。