well I will jump into code part since the header is the problem im facing and I couldnt find any better ways to describe it
function addIceCandidate(message) {
if (message.candidate != null) {
console.trace('add ice candidate');
var iceCandidate = new RTCIceCandidate(message.candidate);
pc1.addIceCandidate(iceCandidate);
}
}
is the function who tries to send ice candidate to the remote peer but in remote peer's chrome debugger it says
Uncaught TypeError: Cannot read property 'addIceCandidate' of undefined and
pc1.addIceCandidate(iceCandidate);
is the line where the error happens
But to my knowladge addIceCandidate
is a WebRTC function which is already defined.
so what am I doing wrong?
I have already gone through here , and for similar problems here , here and also here
and also for the full project Gist is here
Ty for helps in advance and please inform me if you need additional infomation
Uncaught TypeError: Cannot read property 'addIceCandidate' of undefined
This line itself having answer of your question. pc1
object is not defined on which you are trying to access addIceCandidate
property.
Working code :
var pc1 = { addIceCandidate : function(val) { console.log(val); } } function addIceCandidate(message) { if (message.candidate != null) { pc1.addIceCandidate(message.candidate); } } var data = { "candidate": "Rohit" } addIceCandidate(data);
Things to remember:
Once the connection, pc1
, receives an ice candidate via onicecandidate()
event handler, pc1
should send the ice candidate to the remote peer via the signaling server.
Remote peer should use RTCPeerConnection
's addIceCandidate()
to add the ice candidate received via the signaling server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.