There are already bunch of questions on this issue but they all are related to Javascript. I am trying in Android and my onIceCandidate()
is never get called when I call 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);
}
});
}
Creating Connections:
localPeerConnection = initPeerConnection(true);
remotePeerConnection = initPeerConnection(false);
Create offer. Now it should trigger the 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);
But unfortunately it doesn't trigger it. What is wrong? What needs to be correct?
NOTE: Any answer specific to Android JavaScript will be much appreciated.
You're close. Here is a snippet from my Android code:
The only thing I think you're missing is that you should use onSetSuccess to send the offer.