【发布时间】:2013-03-10 16:21:21
【问题描述】:
有没有办法在对等连接已经建立时创建数据通道?
这是我正在做的事情:
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
stablestate 等于activesat。onopen事件由于某种原因没有触发,所以我仍然不确定是否已建立连接。
如果您需要更多代码,请告诉我。
编辑:
我添加了onnegotiationneeded 事件处理程序,现在peerConnection.ondatachannel 正在触发,但通道处于connecting 状态
【问题讨论】:
-
您找到解决方案了吗?
-
有点,但还是很不稳定
标签: webrtc