In the below given code I have created rtcobj variable at global scope using var datatype(initially null assigned),but when I am assigning the object RTCPeerConnection(configuration)
the variable points to RTCPeerConnection(configuration) as long as the function lasts, but afterwards rtcobj starts pointing to null again. Why is it happening so I am not getting (Means why rtcobj points to null again instead of rtc object).
navigator.webkitGetUserMedia({video:true,audio:true},function(mystream){
localvideo.srcObject=mystream;
conn.mystream=mystream
var configuration = {
"iceServers": [{ "url": "stun:stun2.1.google.com:19302" }]
};
rtcobj=new RTCPeerConnection(configuration)
console.log(rtcobj)
rtcobj.addStream(mystream);
rtcobj.onaddstream=function(event){
otherpeerspan.style.display="none"
muteunmute.style.display="block"
remotevideo.srcObject=event.stream
}
rtcobj.onicecandidate=function(event){
if(event.candidate){
send({
type: "candidate",
candidate: event.candidate
});
}
}
},function (error) {
console.log(error);
}
)
}
console.log("rtc:"+rtcobj)