當對等連接已經建立時,是否有創建數據通道的方法?建立peerConnection後創建WebRTC數據通道
下面是我在做什麼:
peerConnection.onstatechange = function(event){
var state = peerConnection.readyState;
console.log('state changed to : '+state);
if(state==='stable'){
console.log('connection is stable');
var dataChannel = peerConnection.createDataChannel('test',{reliable: false});
dataChannel.onopen = function(){
console.log('data channel opened');
dataChannel.send('hello data channel');
};
peerConnection.ondatachannel = function(event){
console.log('ondatachannel event fire ',event);
};
}
};
,它給了我下面的輸出:
state changed to : have-local-offer
state changed to : stable
connection is stable
如何確保連接真正建立起來?我發現here
stable
狀態等於active
狀態。onopen
事件不會因某種原因而觸發,所以我仍然不確定連接是否建立。
如果您需要更多的代碼,請告訴我。
編輯: 我加onnegotiationneeded
事件處理程序,現在peerConnection.ondatachannel
被解僱,但渠道是connecting
狀態
你有解決方案嗎? – 2013-04-15 06:26:54
之類的,但它仍然非常不穩定 – 2013-04-16 08:44:09