title: Why ICE candidate failing While Webrtc video calling?
body: <p>I wrote a simple video calling application with <code>webRTC Technology</code> . This is working fine <code>first 3 minutes</code> and after that i am facing some <code>"ICE candidate failing"</code> error . </p>
  
  <p>This is what happening : </p>
  
  <p><strong>Steps :</strong></p>
  
  <h2>set up a peer connection</h2>
  
  <ul>
  <li>When window loading allow webcam with getUserMedia ( access webcam
  and microphone )</li>
  <li>create RTC peer connection with remote stream added and
  icecandidateAdded</li>
  </ul>
  
  <h2>start peer connection</h2>
  
  <ul>
  <li>create offer ,send offer request</li>
  <li>addIceCandidate</li>
  <li>create answer , send answer response</li>
  </ul>
  
  <p>This is my code :</p>
  
  <pre><code>function hasUserMedia() {
      navigator.getUserMedia = navigator.getUserMedia ||
                           navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
      return !!navigator.getUserMedia;
  };
  
  function hasRTCPeerConnection(){
      window.RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
      window.RTCSessionDescription = window.RTCSessionDescription || window.webkitRTCSessionDescription || window.mozRTCSessionDescription;
      window.RTCIceCandidate = window.RTCIceCandidate || window.webkitRTCIceCandidate || window.mozRTCIceCandidate;
  
      return !!window.RTCPeerConnection;
  };
  
  //when window loading 
  function startConnection() {
  
      if (hasUserMedia()){
  
          navigator.getUserMedia({ video: true, audio: true }, function(my_stream) {
          stream = my_stream;
          client_Video.src = window.URL.createObjectURL(stream);
  
          if(hasRTCPeerConnection()){
                  console.log("RTC peer connection is ready");
                  //set up peer connection
                  setup_Peer_Connection(stream);
              }
  
      }
  }
  
  function setup_Peer_Connection(stream){
  
      var configuration = {"iceServers": [{ "url": "stun:stun.1.google.com:19302" }]};
      my_Connection = new RTCPeerConnection(configuration,{optional:[]});
      my_Connection.addStream(stream);
      my_Connection.onaddstream = remoteStreamAdded;
      my_Connection.onicecandidate = icecandidateAdded;
  }
  
  function remoteStreamAdded(ev){
  
      m_PeerVideo.src = window.URL.createObjectURL(ev.stream);
  }
  
  function icecandidateAdded(ev) {
      if (ev.candidate) {
              send({type: "candidate",candidate: ev.candidate});
          }
  };  
  </code></pre>
  
  <p>and for start peer connection :</p>
  
  <pre><code>var mediaConstraints = {
      optional: [],
      mandatory: {
          OfferToReceiveAudio: true,
          OfferToReceiveVideo: true
      }
  };
  
  function calluser(){
      //start video call with user
      Start_Peer_Connection();
  }
  
  function Start_Peer_Connection(){
  
      my_Connection.createOffer(function (offer) {
          console.log("offer started");
          send({type: "offer",offer: offer});
                  my_Connection.setLocalDescription(offer, success2, failure_offer);
      }, failure_Start_Peer_Connection,mediaConstraints);
  }
  
  
  //getting message from server
  
  connection.onmessage = function (message) {
  
      console.log("Got message", message.data);   
  
      var data = JSON.parse(message.data);
  
      switch(data.type) {
  
          case "offer":
              Client_Offer(data.offer, data.name);
          break;
  
          case "answer":
              Client_Answer(data.answer);
          break;
  
          case "candidate":
              Client_Candidate(data.candidate);
          break;
  
          case "leave":
              Client_Leave();
          break;
  
          default:
          break;
      }
  };
  
  function Client_Offer(offer, name) {
  
      my_Connection.setRemoteDescription(new RTCSessionDescription(offer));
  
          my_Connection.createAnswer(function (answer) {
  
              my_Connection.setLocalDescription(answer);
  
              send({type: "answer",answer: answer});
  
          },failure_Client_Offer); 
  
      }
  }   
  
  function Client_Answer(answer) {
  
      my_Connection.setRemoteDescription(new RTCSessionDescription(answer));
  }
  
  function Client_Candidate(candidate) {
  
      my_Connection.addIceCandidate(new RTCIceCandidate(candidate));
  }
  </code></pre>
  
  <p>I am using Mozilla Firefox browser . i don't know why this is not working after 3 minutes . Connection is fine . But why ice candidate failing after some time ? Any code missing ? Any suggestions ?   </p>