fix(peer): Add backpressure handling to prevent buffer overflow

This commit is contained in:
zarazaex69
2026-04-09 18:34:19 +03:00
parent 1ce40f4f5e
commit b2bc3e18fd

View File

@@ -173,6 +173,11 @@ func (p *Peer) Send(data []byte) error {
if p.dc == nil || p.dc.ReadyState() != webrtc.DataChannelStateOpen {
return fmt.Errorf("datachannel not ready")
}
for p.dc.BufferedAmount() > 1024*1024 {
time.Sleep(1 * time.Millisecond)
}
return p.dc.Send(data)
}