WebRTC error: RTCDataChannel send queue is full


How to fix error: RTCDataChannel send queue is full

Original code: example: simple-peer

send(e){
    this._channel.send(e)
}

Fixed code:

send(e){
	var chunkSize = 65535
	while (e.byteLength) {
		if (this._channel.bufferedAmount > this._channel.bufferedAmountLowThreshold) {
		  this._channel.onbufferedamountlow = () => {
			this._channel.onbufferedamountlow = null;
			this.send(e);
		  };
		  return;
		}
		const chunk = e.slice(0, chunkSize);
		e = e.slice(chunkSize, e.byteLength);
		this._channel.send(chunk);
}

Leave a Reply