@@ -323,22 +323,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
323
323
if (_subscriberPrimary) {
324
324
// make sure publisher transport is connected
325
325
326
- if ((await publisher? .pc.getConnectionState ())? .isConnected () != true ) {
327
- logger.fine ('Publisher is not connected...' );
328
-
329
- // start negotiation
330
- if (await publisher? .pc.getConnectionState () !=
331
- rtc.RTCPeerConnectionState .RTCPeerConnectionStateConnecting ) {
332
- await negotiate ();
333
- }
334
- if (! lkPlatformIsTest ()) {
335
- logger.fine ('Waiting for publisher to ice-connect...' );
336
- await events.waitFor <EnginePublisherPeerStateUpdatedEvent >(
337
- filter: (event) => event.state.isConnected (),
338
- duration: connectOptions.timeouts.peerConnection,
339
- );
340
- }
341
- }
326
+ await _publisherEnsureConnected ();
342
327
343
328
// wait for data channel to open (if not already)
344
329
if (_publisherDataChannelState (reliabilityType) !=
@@ -367,6 +352,25 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
367
352
channel.bufferedAmountLowThreshold! ;
368
353
}
369
354
355
+ Future <void > _publisherEnsureConnected () async {
356
+ if ((await publisher? .pc.getConnectionState ())? .isConnected () != true ) {
357
+ logger.fine ('Publisher is not connected...' );
358
+
359
+ // start negotiation
360
+ if (await publisher? .pc.getConnectionState () !=
361
+ rtc.RTCPeerConnectionState .RTCPeerConnectionStateConnecting ) {
362
+ await negotiate ();
363
+ }
364
+ if (! lkPlatformIsTest ()) {
365
+ logger.fine ('Waiting for publisher to ice-connect...' );
366
+ await events.waitFor <EnginePublisherPeerStateUpdatedEvent >(
367
+ filter: (event) => event.state.isConnected (),
368
+ duration: connectOptions.timeouts.peerConnection,
369
+ );
370
+ }
371
+ }
372
+ }
373
+
370
374
Future <RTCConfiguration > _buildRtcConfiguration (
371
375
{required lk_models.ClientConfigSetting serverResponseForceRelay,
372
376
required List <RTCIceServer > serverProvidedIceServers}) async {
@@ -896,13 +900,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
896
900
);
897
901
898
902
if (_hasPublished) {
899
- await negotiate ();
900
- logger
901
- .fine ('restartConnection: Waiting for publisher to ice-connect...' );
902
- await events.waitFor <EnginePublisherPeerStateUpdatedEvent >(
903
- filter: (event) => event.state.isConnected (),
904
- duration: connectOptions.timeouts.peerConnection,
905
- );
903
+ await _publisherEnsureConnected ();
906
904
}
907
905
fullReconnectOnNext = false ;
908
906
_regionUrlProvider? .resetAttempts ();
0 commit comments