firefoxwebrtcsctp

Firefox does not allow initiating unreliable WebRTC dataChannels?


In this example I'm using simple-peer, although I have tested with other implementations as well as my own. This seems to be an issue with creating the data channels.

The example from the github page of simple-peer has been slightly modified and used: 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");
  }
})

When initiating the connection using Firefox(61.0.2 x64), the connection is forced to reliable, even when trying to set it to unreliable using unreliable:false, ordered:false and maxRetransmits:0. Only the ordered property is properly used. When checking the connection object, the maxRetransmits and maxRetransmitTime settings are not exposed. If you connect to the Firefox connection using Chrome, both maxRetransmits and maxRetransmitTime will be set to 65535 in Chrome.

If you initiate the connection using Chrome, and connect using Firefox, the connection will be opened as unordered and unreliable in both Chrome and Firefox as well as having 0 maxRetransmits in Chrome.

Is this a bug, or am I missing something in setting up the connection to support unreliable data channels when initiating the connection using a Firefox browser?


Solution

  • Yes, this is a very unfortunate bug in Firefox tracked here that leads to 0 values being ignored for both maxRetransmits and maxPacketLifeTime. It has been fixed in Firefox 62. If you have to support Firefox < 62, you can work around this by setting maxPacketLifeTime to 1. But you should only do this in Firefox since older Chrome versions do not support maxPacketLifeTime. Yes, it's a mess.

    Please note that there is no reliable member in the RTCDataChannelInit dictionary. There is also no maxRetransmitTime attribute on the RTCDataChannel interface. Both have been removed a long time ago.