move createOffer to goroutine

This commit is contained in:
David Colburn
2021-06-17 22:33:26 -07:00
parent 6d6423c29d
commit 089d1d366d
2 changed files with 12 additions and 9 deletions
+9 -7
View File
@@ -93,14 +93,16 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
} }
t.pc.OnICEGatheringStateChange(func(state webrtc.ICEGathererState) { t.pc.OnICEGatheringStateChange(func(state webrtc.ICEGathererState) {
if state == webrtc.ICEGathererStateComplete { if state == webrtc.ICEGathererStateComplete {
t.lock.Lock() go func() {
defer t.lock.Unlock() t.lock.Lock()
if t.restartAfterGathering { defer t.lock.Unlock()
logger.Debugw("restarting ICE after ICE gathering") if t.restartAfterGathering {
if err := t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}); err != nil { logger.Debugw("restarting ICE after ICE gathering")
logger.Warnw("could not restart ICE", err) if err := t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}); err != nil {
logger.Warnw("could not restart ICE", err)
}
} }
} }()
} }
}) })
+3 -2
View File
@@ -5,10 +5,11 @@ import (
"testing" "testing"
"time" "time"
"github.com/livekit/livekit-server/pkg/testutils"
livekit "github.com/livekit/livekit-server/proto"
"github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/testutils"
livekit "github.com/livekit/livekit-server/proto"
) )
func TestMissingAnswerDuringICERestart(t *testing.T) { func TestMissingAnswerDuringICERestart(t *testing.T) {