WebRTC即使添加ICE也不会通过公共IP

时间:2019-03-16 07:59:25

标签: webrtc

我已经使用WEBRTC和SignalR作为信令服务器实现了会议应用程序。

在我的局域网中,一切正常,但是在Internet上它无法流数据。

经过多次搜索后,我发现它的发生是由于缺少ICE和STUN服务器(在我的本地WebRtc中使用我的私有IP,但在Internet中它需要可以由STUN和ICE处理的公共IP)。之后,我加冰如下:

function _createConnection() {

  console.log('creating RTCPeerConnection...');

//Define Ice Server
var ice = {"iceServers": [
        {"url": "stun:numb.viagenie.ca:3478"} //{"url": "stun:stun.l.google.com:19302"}
        ,{"url": "turn:numb.viagenie.ca", "username": "m_mramezani", "credential": "*******"}
    ]};
// Create a new PeerConnection
  var connection = new RTCPeerConnection(ice); // null = no ICE servers
  // A new ICE candidate was found

  connection.onicecandidate = function (event) {
        if (event.candidate) {
      // Let's send it to our peer via SignalR
      var message = ChatMessageInput.value;

    }

function SendSDPToDoctorAfterDoctorAccept(){

var userConnectionID = document.getElementById("CallerConnectionId").value;
var doctorConnectionID = document.getElementById("DoctorChatID").value;

console.log("Conn started");
_myConnection = _myConnection || _createConnection(null);
console.log(_myConnection +" " +"test");
// Add our stream to the peer connection
_myConnection.addStream(_myMediaStream);

// Create an offer to send our peer
_myConnection.createOffer(function (desc) {
    // Set the generated SDP to be our local session description
    _myConnection.setLocalDescription(desc, function () {
        // And send it to our peer, where it will become their RemoteDescription


        //Changed By Ramezani
        //var peopleId = localStorage.getItem('peopleId');
        var DoctorpeopleId = document.getElementById("DoctorFamilyID").value;
        console.log(DoctorpeopleId);
        //console.log(doctorChatID);
        //m.porniazi code -----------------------------
        if (localStorage.getItem('peopleId') == null ) {
            alert('session is not founded by anyone');
            return;
        }
        //sessionStorage.setItem('PeopleId', '151185');


        //m.porniazi code -----------------------------
        console.log(desc);
        console.log("sdp "+JSON.stringify({ "sdp": desc }));
        console.log("14799");
        console.log("CallerChatID: " + userConnectionID);
        console.log("DoctorChatID: " + doctorConnectionID);
        connectionSR.invoke("SignalingMessage", doctorConnectionID, userConnectionID, DoctorpeopleId, JSON.stringify({ "sdp": desc })).catch(function (err) {
            return console.log(err.toString());
        });

        //hub.server.send(JSON.stringify({ "sdp": desc }));
    });
}, function (error) { console.log('Error creating session description: ' + error); });

document.getElementById('startBtn').disabled = true;
document.getElementById('hangUpBtn').disabled = false;

}

但是它确实可以在Internet上工作,而且当我在chrome://webrtc-internals/上进行检查时,我找不到我的公共Internet IP,它只包含我的私有IP,我怎么了?

0 个答案:

没有答案