I'm trying to stream live video from a remote webcam but it crashes on Android when I try to add the ice candidates to the peerConnection. This same code works on ios and I believe have followed the Android setup correctly. I read somewhere that I need to make sure the answer is created before adding ice candidates so I have created an array and now wait for the answer to be created and local description set but that didn't help my problem. I wonder if it has to do with the proper format of the candidate?
Here is how I'm adding ice candidates
try {
peerConnection.addIceCandidate(candidate).catch(e => {
console.log(`Failure during addIceCandidate(): ${e.name}`) //this never logs
})
console.log('added ice candidate')
} catch (err) {
console.log('Failed to add remote ICE candidate', err)
}
This is the format of candidate:
{"candidate": "candidate:1 1 UDP 2013266431 fe80::e446:fbff:fe30:d913 53393 typ host", "sdpMLineIndex": 0, "sdpMid": undefined}
I have commented out almost everything else from this code so I believe the addIceCandidate is my problem, plus I see this in the backtrace of the crash:
#09 pc 00000000000412c0 [anon:dalvik-classes10.dex extracted in memory from /data/app/~~XBCQ7AoUnEeLqIu8zNssPA==/com.myappname-_s6oKL5s7auBSrV7jp3f9g==/base.apk!classes10.dex] (org.webrtc.PeerConnection.addIceCandidate+12)
I see this in the Hermes log:
16:22:25.900 2832 System.err java.lang.NullPointerException: Attempt to invoke virtual method 'byte[] java.lang.String.getBytes(java.lang.String)' on a null object reference 16:22:25.907 2832 System.err at org.webrtc.JniHelper.getStringBytes(JniHelper.java:25) 16:22:25.907 2832 System.err at org.webrtc.PeerConnection.nativeAddIceCandidate(Native Method) 16:22:25.907 2832 System.err at org.webrtc.PeerConnection.addIceCandidate(PeerConnection.java:896) 16:22:25.907 2832 System.err at com.oney.WebRTCModule.WebRTCModule.peerConnectionAddICECandidateAsync(WebRTCModule.java:877) 16:22:25.907 2832 System.err at com.oney.WebRTCModule.WebRTCModule.lambda$peerConnectionAddICECandidate$18$com-oney-WebRTCModule-WebRTCModule(WebRTCModule.java:862) 16:22:25.907 2832 System.err at com.oney.WebRTCModule.WebRTCModule$$ExternalSyntheticLambda1.run(Unknown Source:8) 16:22:25.907 2832 System.err at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) 16:22:25.907 2832 System.err at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) 16:22:25.907 2832 System.err at java.lang.Thread.run(Thread.java:1012)
Do I need to convert the candidate to JSON or string? Is there something else I can do to find out more about the specific error?