[英]WebRTC data channel stack on readyState “conecting”
我試圖創建一個與數據通道的webRTC連接(僅),但是當我使用下面提供的代碼並運行initCall()
,數據通道的readyState在“正在連接”時處於堆棧狀態,並且永不更改。 我正在使用chrome的atest版本。 是什么原因引起的?
檢查信令服務器是否正常工作。
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可以進行客戶端到客戶端的傳出和傳入。 大多數防火牆都會阻止它,因此您可以先檢查一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.