RTCDataChannel: bufferedamountlow event

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

A bufferedamountlow event is sent to an RTCDataChannel when the number of bytes currently in the outbound data transfer buffer (bufferedAmount) falls from above to below or equal the threshold specified in bufferedAmountLowThreshold.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("bufferedamountlow", (event) => { })

onbufferedamountlow = (event) => { }

Event type

A generic Event.

Examples

This example sets up a handler for bufferedamountlow to request more data any time the data channel's buffer falls below the number of bytes specified by bufferedAmountLowThreshold, which we have set to 65536. In other words, we'll try to keep at least 64kB of data in the buffer, reading 64kB at a time from the source.

js
let pc = new RTCPeerConnection();
let dc = pc.createDataChannel("SendFile");
// Replace with your own source object, such as a file handle
let source = null;
dc.bufferedAmountLowThreshold = 65536;

pc.addEventListener("bufferedamountlow", (ev) => {
  if (source.position <= source.length) {
    dc.send(source.readFile(65536));
  }
});

After creating the RTCPeerConnection, this calls RTCPeerConnection.createDataChannel() to create the data channel. Then a listener is created for bufferedamountlow to refill the incoming data buffer any time its contents fall below 65536 bytes.

You can also set up a listener for bufferedamountlow using its event handler property, onbufferedamountlow:

js
pc.onbufferedamountlow = (ev) => {
  if (source.position <= source.length) {
    dc.send(source.readFile(65536));
  }
};

Specifications

Specification
WebRTC: Real-Time Communication in Browsers
# event-datachannel-bufferedamountlow
WebRTC: Real-Time Communication in Browsers
# dom-rtcdatachannel-onbufferedamountlow

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
bufferedamountlow event
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote
footnote The default for rtcpMuxPolicy is require.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote The default for rtcpMuxPolicy is require.
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote
footnote The default for rtcpMuxPolicy is require.
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote
footnote The default for rtcpMuxPolicy is require.
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote
footnote The default for rtcpMuxPolicy is require.
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote
footnote The default for rtcpMuxPolicy is require.
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote
footnote The default for rtcpMuxPolicy is require.
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also