title: Simple-peer WebRTC Error: Ice connection failed
body: <p>I can not make the Simple-Peer NPM library to connect between two computers in two different networks in Browser. If the computers are in the same local network, the browsers connect each other, but otherwise, I can not make them connect. </p>
  
  <p>Both browsers return this error: </p>
  
  <pre><code>"Error: Ice connection failed. 
  at Peer._onIceStateChange"
  at RTCPeerConnection.Peer.self._pc.oniceconnectionstatechange
  </code></pre>
  
  <p>The signalling looks right for me:</p>
  
  <pre><code>{ type: 'offer',
       sdp: 'v=0\r\no=- 2275520429720515716 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 49523 DTLS/SCTP 5000\r\nc=IN IP4 5.12.206.160\r\na=candidate:2020300070 1 udp 2113937151 192.168.2.8 49523 typ host generation 0 network-cost 50\r\na=candidate:842163049 1 udp 1677729535 5.12.206.160 49523 typ srflx raddr 192.168.2.8 rport 49523 generation 0 network-cost 50\r\na=ice-ufrag:Ph/x\r\na=ice-pwd:csnTbzHs+dxzakEKPY8LfvBg\r\na=fingerprint:sha-256 B9:C0:9D:91:46:1B:E8:5C:83:B1:11:A7:C5:D7:64:97:A6:63:D9:12:11:0F:9A:05:8F:46:83:BC:90:38:86:9E\r\na=setup:actpass\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n' } }
  
  { type: 'answer',
       sdp: 'v=0\r\no=- 1356997482353729498 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 56005 DTLS/SCTP 5000\r\nc=IN IP4 86.126.104.54\r\nb=AS:30\r\na=candidate:2702239670 1 udp 2113937151 192.168.1.103 56003 typ host generation 0 network-cost 50\r\na=candidate:842163049 1 udp 1677729535 86.126.104.54 56005 typ srflx raddr 192.168.1.103 rport 56003 generation 0 network-cost 50\r\na=ice-ufrag:W6zA\r\na=ice-pwd:1NhU5D47rSz83ANxlY+Tz/XI\r\na=ice-options:trickle\r\na=fingerprint:sha-256 2C:0B:78:49:F5:F0:44:6C:86:DD:27:BC:B6:7D:77:B9:B1:07:F4:2F:37:F5:24:D9:A3:54:7D:B3:A0:3C:57:C0\r\na=setup:active\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n' } }
  </code></pre>
  
  <p>but when the library wants to establish the connection, both browsers return the above-mentioned error.</p>
  
  <p>This my code </p>
  
  <pre><code>//TUTORIAL BASED ON
  // https://github.com/feross/simple-peer
  
  var initiator = (location.hash||'') === '#1';
  console.log("inititator",location.hash , initiator);
  
  var Peer = require('simple-peer');
  
  params = {
      initiator: initiator,
      trickle: false,
      reconnectTimer: 100,
      iceTransportPolicy: 'relay',
      config: {
  
          iceServers: [
              {
                  urls: "stun:numb.viagenie.ca",
                  username: "pasaseh@ether123.net",
                  credential: "12345678"
              },
              {
                  urls: "turn:numb.viagenie.ca",
                  username: "pasaseh@ether123.net",
                  credential: "12345678"
              }
          ]
      }
  };
  
  if (typeof window === "undefined"){
      var wrtc = require('wrtc');
      params.wrtc=  wrtc;
  }
  
  var p = new Peer(params);
  
  p.on('error', function (err) { console.log('error', err) })
  
  p.on('signal', function (data) {
      console.log('SIGNAL', JSON.stringify(data));
      document.querySelector('#outgoing').textContent = JSON.stringify(data)
  });
  
  document.querySelector('form').addEventListener('submit', function (ev) {
      ev.preventDefault();
      console.log("am apasat pe button");
      p.signal(JSON.parse(document.querySelector('#incoming').value))
  });
  
  let index = Math.floor(Math.random()*100);
  
  p.on('connect', function (data) {
  
      console.log('CONNECT', data, p);
  
      setInterval(function() {
          if ((typeof p !== 'undefined')&amp;&amp; ( p !== null)) {
              console.log(p);
              p.send('whatever' + index + " ___ " + Math.random())
          }
      }, 500);
  
      p.on("hello", function(data){
          alert(data);
      });
  
      p.emit("hello",55);
  
  })
  
  p.on('data', function (data) {
      console.log('data: ' + data)
  });
  
  module.exports = function(){
      console.log("Hello World Server");
  };
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/GaXoP.png" rel="nofollow noreferrer">webrtc-internals</a></p>
  
  <p>Any solution to this problem? Thanks</p>