Start negotiate immediately if last one is before debouce interval (#2979)
This commit is contained in:
+15
-8
@@ -167,6 +167,7 @@ type PCTransport struct {
|
|||||||
|
|
||||||
debouncedNegotiate func(func())
|
debouncedNegotiate func(func())
|
||||||
debouncePending bool
|
debouncePending bool
|
||||||
|
lastNegotiate time.Time
|
||||||
|
|
||||||
onNegotiationStateChanged func(state transport.NegotiationState)
|
onNegotiationStateChanged func(state transport.NegotiationState)
|
||||||
|
|
||||||
@@ -398,6 +399,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
|||||||
previousTrackDescription: make(map[string]*trackDescription),
|
previousTrackDescription: make(map[string]*trackDescription),
|
||||||
canReuseTransceiver: true,
|
canReuseTransceiver: true,
|
||||||
connectionDetails: types.NewICEConnectionDetails(params.Transport, params.Logger),
|
connectionDetails: types.NewICEConnectionDetails(params.Transport, params.Logger),
|
||||||
|
lastNegotiate: time.Now(),
|
||||||
}
|
}
|
||||||
if params.IsSendSide {
|
if params.IsSendSide {
|
||||||
t.streamAllocator = streamallocator.NewStreamAllocator(streamallocator.StreamAllocatorParams{
|
t.streamAllocator = streamallocator.NewStreamAllocator(streamallocator.StreamAllocatorParams{
|
||||||
@@ -1000,23 +1002,22 @@ func (t *PCTransport) Negotiate(force bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if force {
|
var postEvent bool
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
|
if force || (!t.debouncePending && time.Since(t.lastNegotiate) > negotiationFrequency) {
|
||||||
t.debouncedNegotiate(func() {
|
t.debouncedNegotiate(func() {
|
||||||
// no op to cancel pending negotiation
|
// no op to cancel pending negotiation
|
||||||
})
|
})
|
||||||
t.debouncePending = false
|
t.debouncePending = false
|
||||||
t.lock.Unlock()
|
t.lastNegotiate = time.Now()
|
||||||
|
|
||||||
t.postEvent(event{
|
postEvent = true
|
||||||
signal: signalSendOffer,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
t.lock.Lock()
|
|
||||||
if !t.debouncePending {
|
if !t.debouncePending {
|
||||||
t.debouncedNegotiate(func() {
|
t.debouncedNegotiate(func() {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
t.debouncePending = false
|
t.debouncePending = false
|
||||||
|
t.lastNegotiate = time.Now()
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
|
|
||||||
t.postEvent(event{
|
t.postEvent(event{
|
||||||
@@ -1025,7 +1026,13 @@ func (t *PCTransport) Negotiate(force bool) {
|
|||||||
})
|
})
|
||||||
t.debouncePending = true
|
t.debouncePending = true
|
||||||
}
|
}
|
||||||
t.lock.Unlock()
|
}
|
||||||
|
t.lock.Unlock()
|
||||||
|
|
||||||
|
if postEvent {
|
||||||
|
t.postEvent(event{
|
||||||
|
signal: signalSendOffer,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user