WebRTC data channel stack on readyState “conecting”

情到浓时终转凉″ 提交于 2019-12-08 02:39:42

问题


I am trying to create a webRTC connection with a datachannel (only), but when I use the code provided bellow, and run initCall(), the readyState of the data channel is stack on "connecting" and never changes. I am using the atest version of chrome. What coud be causing it?

The signaling server is checkd to be working alright.

var ottowa = initIO({//Init a connection to the signaling server
    onMessage: function(data) { //got message from the signalin server
        trace("onMessage with data = " + JSON.stringify(data));

        //var signal = JSON.parse(data.toString());
        var signal = data;

        if(signal.title == "offer")
            gotOffer(signal.data);
        else if (signal.title == "offerResponse")
            gotResponse(signal.data);

    },
    onCount: function(data) {

    }
});

var configuration = {
    'iceServers': [{
        'url':'stun:stun.l.google.com:19302'
    }]
};

joinRoom('demo');//Joins a room in the signaloing server

var pc, channel;

pc = new webkitRTCPeerConnection(configuration, { 'optional': [{'DtlsSrtpKeyAgreement': true}, {'RtpDataChannels': true }] }); 
channel = pc.createDataChannel("data");

pc.onaddstream = function(obj){
    trace("onaddstream");
}

function initCall(){
    pc.createOffer(function(offer) {
        pc.setLocalDescription(new RTCSessionDescription(offer), function() {
            send({//send a message thru the signaling server
                title: "offer",
                data: offer
            });
        }, error);
    },error);
}

function gotOffer(offer) {
    pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
        pc.createAnswer(function(answer) {
            pc.setLocalDescription(new RTCSessionDescription(answer), function(){
                send({//send a message thru the signaling server
                    title:"offerResponse",
                    data: answer
                });
            }, error);
        },error);
    },error);
}

function gotResponse(offer) {
    pc.setRemoteDescription(new RTCSessionDescription(offer), function() {
        trace("gotResponse and successfully connected");
    },error);
}

channel.onopen = function(event) {
    trace("onopen with event = " + event);
}

channel.onmessage = function(event) {
    trace("onmessage with event = " + event);
}

function trace(text) {
    console.log((performance.now() / 1000).toFixed(3) + ": " + text.toString);
}

function error(err) {
    trace("error = " + err);
}

回答1:


Do you have any firewall or other network device that might block the connection? Connecting to signalling servers generally works as that is an outgoing connection (client to server), but RTC goes client to client, outgoing and incoming. Most firewalls block that, so you might check that first.



来源:https://stackoverflow.com/questions/21244468/webrtc-data-channel-stack-on-readystate-conecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!