MDN self-hosted library · e01.org

RTCDataChannel: bufferedamountlow event

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

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;

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