VEDANT GAJJAR

VEDANT GAJJAR

  • 1.6k
  • 24
  • 764

In webrtc the onicecandidate event not invoke after sending

Nov 22 2016 5:03 AM

0down votefavorite

I am using signalr for signaling and the javascript code is as below. the following code is base on simple webrtc call and answer. i am using chrome latest version for this code this event work on nodejs correctly but not working in asp.net mvc.

i use this link for creating referance click here.

here is code
 
<script>
var myhub = $.connection.myhub;
var myconn = new webkitRTCPeerConnection(configuration);
var video = document.querySelector('video');
var streamvar;
var configuration = {
iceServers: [
{ urls: "stun:23.21.150.121" },
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "turn:numb.viagenie.ca", credential: "webrtcdemo", username: "louis%40mozilla.com" }
]
}
var IceCandidate = window.mozRTCIceCandidate || window.RTCIceCandidate || window.webkitRTCIceCandidate;
var anotherIce = JSON.stringify({"abc":IceCandidate});
debugger;
$.connection.hub.start();
navigator.getUserMedia = navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia;
var constrain = { audio: true, video: true };
navigator.getUserMedia(constrain, successGetMedia, err);
function successGetMedia(stream) {
window.stream = stream;
if (window.URL) {
video.src = window.URL.createObjectURL(stream);
}
else {
video.src = stream;
}
}
//when user connected event for another user connection
myconn.onaddstream = function (e) {
video.src = window.URL.createObjectURL(stream);
};
function err(err) {
console.log("some error occure");
}
function handleIceCandidate(candidate) {
myconn.addIceCandidate(new RTCIceCandidate(JSON.parse(candidate)));
console.log("Candidate added");
}
function handleoffer(offers) {
debugger;
var myOfferData = JSON.parse(offers);
myconn.setRemoteDescription(new RTCSessionDescription(myOfferData.offer));
let candidate = new RTCIceCandidate(myOfferData.sdp);
myconn.addIceCandidate(candidate).then( _=> {
});
myconn.createAnswer().then(function (answer) {
debugger;
myconn.setLocalDescription(answer);
$.connection.hub.start().done(function () {
myhub.server.answer(JSON.stringify({ 'answer': answer }));
});
});
}
function handleanswer(answer) {
debugger;
var myanswer = JSON.parse(answer);
myconn.setRemoteDescription(new RTCSessionDescription(myanswer.answer));
}
function handleCall() {
debugger;
myconn.createOffer().then(function (offer) {
$.connection.hub.start().done(function () {
myhub.server.offer(JSON.stringify({ 'offer': offer }));
});
});
}
$(function () {
myhub.client.offer = function (offer) {
handleoffer(offer);
}
myhub.client.candidate = function (candidate) {
handleIceCandidate(candidate);
}
myhub.client.answer = function (answer) {
handleanswer(answer);
}
$("#btnCall").click(function () {
handleCall();
});
debugger;
myconn.onicecandidate = function (event) {
debugger;
if (event.candidate) {
debugger;
$.connection.hub.start().done(function () {
myhub.server.offer(JSON.stringify({ 'candidate': event.candidate }));
});
}
};
});
</script>