【发布时间】:2019-02-06 12:58:56
【问题描述】:
在这个示例中,我使用的是 simple-peer,尽管我已经测试了其他实现以及我自己的实现。这似乎是创建数据通道的问题。
simple-peer的github页面中的例子稍作修改使用:https://github.com/feross/simple-peer
var init = location.hash === '#1';
var config = {reliable:true, maxRetransmits:0, ordered:false};
var p = new SimplePeer({ initiator: init, trickle: false, channelConfig: config })
console.log(p);
p.on('error', function (err) { console.log('error', err) })
p.on('signal', function (data) {
console.log('SIGNAL', JSON.stringify(data))
document.querySelector('#outgoing').textContent = JSON.stringify(data)
})
document.querySelector('form').addEventListener('submit', function (ev) {
ev.preventDefault()
p.signal(JSON.parse(document.querySelector('#incoming').value))
})
p.on('connect', function () {
console.log('CONNECT')
console.log(p);
console.log(p._channel);
if(init){
for(let i=0;i<100;i++){
p.send(JSON.stringify(i));
}
}
})
var rec = 0;
p.on('data', function (data) {
rec++;
console.log('data: ' + JSON.parse(data));
if(!init){
p.send(data);
}
if(rec >= 100){
console.log("got all");
}
})
使用 Firefox(61.0.2 x64) 启动连接时,即使尝试使用 unreliable:false、ordered:false 和 maxRetransmits:0 将其设置为不可靠,连接也会被强制为可靠。只有有序的属性被正确使用。 检查连接对象时,不会公开 maxRetransmits 和 maxRetransmitTime 设置。如果您使用 Chrome 连接到 Firefox 连接,则在 Chrome 中 maxRetransmits 和 maxRetransmitTime 都将设置为 65535。
如果您使用 Chrome 启动连接,然后使用 Firefox 进行连接,则连接将在 Chrome 和 Firefox 中以无序和不可靠的方式打开,并且在 Chrome 中具有 0 maxRetransmits。
这是一个错误,还是我在使用 Firefox 浏览器启动连接时设置连接以支持不可靠的数据通道时遗漏了什么?
【问题讨论】: