[webrtc-pc] how to use datachannel bufferedamountlow threshold callback?

fippo has just created a new issue for https://github.com/w3c/webrtc-pc:

== how to use datachannel bufferedamountlow threshold callback? ==
spawning from https://bugs.chromium.org/p/chromium/issues/detail?id=878682

one interpretation of this is the following:
```
sendChannel.bufferedAmountLow = 8192
sendChannel.addEventListener('bufferedamountlow', listener);
sendChannel.send( ... 16384 bytes of data )
```
According to the spec text, sendChannel.bufferedAmount should go to 16384 and consequently cross to 0. This seems like a nice way to do things. But it seems we can't have nice things.
Both Chrome and Firefox seem to hand this off to SCTP immediately, *not* increasing bufferedAmountLow until the sctp buffers are filled.

This requires a slightly different usage pattern (taken from [here](https://github.com/webrtc/samples/blob/4c06b2ebf40f46d7969cb7b035f4dfa71731baf9/src/content/datachannel/datatransfer/js/main.js)
```
var sendAllData = function() {
    // Try to queue up a bunch of data and back off when the channel starts to
    // fill up. We don't setTimeout after each send since this lowers our
    // throughput quite a bit (setTimeout(fn, 0) can take hundreds of milli-
    // seconds to execute).
    while (sendProgress.value < sendProgress.max) {
      if (sendChannel.bufferedAmount > bufferFullThreshold) {
        sendChannel.addEventListener('bufferedamountlow', sendAllData, {once: true});
        return;
      }
      sendProgress.value += chunkSize;
      sendChannel.send(stringToSendRepeatedly);
    }
  };
```
basically calling send() until the SCTP buffers fill up, the browser buffers start to fill and get drained.
Straightforward as well but we don't have an example showing this and the spec text prohibits it.

See https://bugs.chromium.org/p/chromium/issues/detail?id=496700 for the original chrome implementation bug, and https://bugzilla.mozilla.org/show_bug.cgi?id=1178091 for Firefox.
Note in particular @jesup's comment 'bufferedAmount can't currently include data buffered in the stack'.

@lgrahl is what jesup said still true?

Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1979 using your GitHub account

Received on Friday, 31 August 2018 05:59:39 UTC