From 7cfe402f1a392bc0d05143178b8a03e7fe3c6157 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sun, 11 Sep 2022 11:49:48 +0800 Subject: [PATCH] chore: add force relay config. (#169) --- lib/src/core/engine.dart | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/src/core/engine.dart b/lib/src/core/engine.dart index f5a1169..0720685 100644 --- a/lib/src/core/engine.dart +++ b/lib/src/core/engine.dart @@ -333,7 +333,7 @@ class Engine extends Disposable with EventsEmittable { } } - Future _configurePeerConnections() async { + Future _configurePeerConnections({bool? forceRelay}) async { if (publisher != null || subscriber != null) { logger.warning('Already configured'); return; @@ -351,6 +351,11 @@ class Engine extends Disposable with EventsEmittable { .copyWith(iceServers: serverIceServers); } + if (forceRelay != null && forceRelay) { + rtcConfiguration = rtcConfiguration.copyWith( + iceTransportPolicy: RTCIceTransportPolicy.relay); + } + publisher = await Transport.create(_peerConnectionCreate, rtcConfiguration); subscriber = await Transport.create(_peerConnectionCreate, rtcConfiguration); @@ -593,7 +598,9 @@ class Engine extends Disposable with EventsEmittable { 'serverVersion: ${event.response.serverVersion}, ' 'iceServers: ${event.response.iceServers}'); - await _configurePeerConnections(); + await _configurePeerConnections( + forceRelay: event.response.clientConfiguration.forceRelay == + lk_models.ClientConfigSetting.ENABLED); if (!_subscriberPrimary) { // for subscriberPrimary, we negotiate when necessary (lazy)