javascript - readyState "conecting"上的 WebRTC 数据通道堆栈

标签 javascript html p2p webrtc peer

我正在尝试创建一个与数据通道的 webRTC 连接(仅),但是当我使用下面提供的代码并运行 initCall() 时,数据通道的就绪状态堆叠在“连接”并且永不改变。我正在使用最新版本的 chrome。可能是什么原因造成的?

检查信令服务器是否正常工作。

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);
}

最佳答案

您是否有任何可能阻止连接的防火墙或其他网络设备?连接到信令服务器通常作为传出连接(客户端到服务器)工作,但 RTC 是客户端到客户端、传出和传入。大多数防火墙都会阻止它,所以您可以先检查一下。

关于javascript - readyState "conecting"上的 WebRTC 数据通道堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21244468/

相关文章:

javascript - 添加到数组时会创建空数组值

javascript - anchor 列表上的jquery单击事件

javascript - 如何将默认图像添加到 Canvas ,同时让用户加载自己的图像

firefox - Firefox webRTC session 描述中的 'sdparta' 代表什么?

VB.net(点对点连接问题)

javascript - 刷新时倒计时再次重新加载

javascript - 使用 javascript 永久更改 html 值?

jquery - 使用 JQuery 临时删除伪 CSS

javascript - 可拖动面板 onclick z-index

webrtc - 在WebRTC中识别在线用户