【发布时间】:2016-09-16 00:50:54
【问题描述】:
我正在使用 WebRTC 技术进行一些测试,但我在 Chrome 和 Firefox 之间的 RTCDataChannel 方面存在一些问题。连接工作正常,我可以在两个浏览器之间发送数据,但是当两个浏览器之一断开连接时就会出现问题。
当 Chrome 正在发送数据而 Firefox 接收数据并且 Firefox 断开连接时,Chrome 端的通道将其 readyState 设置为关闭,我可以处理此显示消息。
当 Firefox 正在发送数据而 Chrome 接收数据并且 Chrome 断开连接时,Firefox 端的通道 不会更改它的 readyState,所以我无法处理这个问题,显然 Firefox 继续向 ¿ 关闭的通道发送数据?
我的代码很简单:
建立连接:
[...]
if(offerer){
channel = connection.createDataChannel("dataChannel", null);
setChannelEvents(channel);
connection.createOffer(myFunc, showError);
}else{
connection.ondatachannel = function(event){
channel = event.channel;
setChannelEvents(channel);
}
}
[...]
当连接建立并可以发送消息时:
[...]
try{
channel.send(message);
}catch(e){
//handle error here
[...]
}
[...]
正如我所说,在 Chrome 中时 channel.send(message);返回错误(因为 readyState 设置为关闭且无法发送消息)“此处处理错误”中的代码执行,但在 Firefox 中从不执行。
有人可以帮帮我吗?这有点令人沮丧。 谢谢!
【问题讨论】:
标签: javascript google-chrome firefox webrtc