Implement DataChannel flow control

This commit is contained in:
Vort 2023-03-27 19:02:10 +03:00 committed by Shelikhoo
parent f8eb86f24d
commit ea01c92cf1
No known key found for this signature in database
GPG key ID: C4D5E79D22B25316
2 changed files with 30 additions and 1 deletions

View file

@ -83,6 +83,8 @@ const (
sessionIDLength = 16
)
const bufferedAmountLowThreshold uint64 = 256 * 1024 // 256 KB
var broker *SignalingServer
var currentNATTypeAccess = &sync.RWMutex{}
@ -408,6 +410,15 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
pr, pw := io.Pipe()
conn := newWebRTCConn(pc, dc, pr, sf.EventDispatcher)
dc.SetBufferedAmountLowThreshold(bufferedAmountLowThreshold)
dc.OnBufferedAmountLow(func() {
select {
case conn.sendMoreCh <- struct{}{}:
default:
}
})
dc.OnOpen(func() {
log.Printf("Data Channel %s-%d open\n", dc.Label(), dc.ID())