fix ice config issues. (#192)
* fix ice config issues. * update comment. * The client has high-priority to set ice settings.
This commit is contained in:
+37
-16
@@ -76,7 +76,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
|||||||
String? get connectedServerAddress => _connectedServerAddress;
|
String? get connectedServerAddress => _connectedServerAddress;
|
||||||
|
|
||||||
// server-provided ice servers
|
// server-provided ice servers
|
||||||
List<lk_rtc.ICEServer> _serverProvidedIceServers = [];
|
List<RTCIceServer> _serverProvidedIceServers = [];
|
||||||
|
|
||||||
late final _signalListener = signalClient.createListener(synchronized: true);
|
late final _signalListener = signalClient.createListener(synchronized: true);
|
||||||
|
|
||||||
@@ -337,27 +337,42 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _configurePeerConnections({bool? forceRelay}) async {
|
Future<void> _configurePeerConnections(
|
||||||
|
{required lk_models.ClientConfigSetting forceRelay,
|
||||||
|
required List<RTCIceServer> serverProvidedIceServers}) async {
|
||||||
if (publisher != null || subscriber != null) {
|
if (publisher != null || subscriber != null) {
|
||||||
logger.warning('Already configured');
|
logger.warning('Already configured');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RTCConfiguration? config;
|
// RTCConfiguration? config;
|
||||||
// use server-provided iceServers if not provided by user
|
|
||||||
final serverIceServers =
|
|
||||||
_serverProvidedIceServers.map((e) => e.toSDKType()).toList();
|
|
||||||
|
|
||||||
RTCConfiguration rtcConfiguration = connectOptions.rtcConfiguration;
|
RTCConfiguration rtcConfiguration = connectOptions.rtcConfiguration;
|
||||||
if (serverIceServers.isNotEmpty) {
|
|
||||||
// use server provided iceServers if exists
|
// The server provided iceServers are only used if
|
||||||
|
// the client's iceServers are not set.
|
||||||
|
if (rtcConfiguration.iceServers == null &&
|
||||||
|
serverProvidedIceServers.isNotEmpty) {
|
||||||
rtcConfiguration = connectOptions.rtcConfiguration
|
rtcConfiguration = connectOptions.rtcConfiguration
|
||||||
.copyWith(iceServers: serverIceServers);
|
.copyWith(iceServers: serverProvidedIceServers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forceRelay != null && forceRelay) {
|
// set forceRelay
|
||||||
rtcConfiguration = rtcConfiguration.copyWith(
|
if (rtcConfiguration.iceTransportPolicy == null) {
|
||||||
iceTransportPolicy: RTCIceTransportPolicy.relay);
|
switch (forceRelay) {
|
||||||
|
case lk_models.ClientConfigSetting.ENABLED:
|
||||||
|
rtcConfiguration = rtcConfiguration.copyWith(
|
||||||
|
iceTransportPolicy: RTCIceTransportPolicy.relay,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case lk_models.ClientConfigSetting.DISABLED:
|
||||||
|
rtcConfiguration = rtcConfiguration.copyWith(
|
||||||
|
iceTransportPolicy: RTCIceTransportPolicy.all,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case lk_models.ClientConfigSetting.UNSET:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publisher = await Transport.create(_peerConnectionCreate,
|
publisher = await Transport.create(_peerConnectionCreate,
|
||||||
@@ -627,16 +642,22 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
|||||||
..on<SignalJoinResponseEvent>((event) async {
|
..on<SignalJoinResponseEvent>((event) async {
|
||||||
// create peer connections
|
// create peer connections
|
||||||
_subscriberPrimary = event.response.subscriberPrimary;
|
_subscriberPrimary = event.response.subscriberPrimary;
|
||||||
_serverProvidedIceServers = event.response.iceServers;
|
|
||||||
_participantSid = event.response.participant.sid;
|
_participantSid = event.response.participant.sid;
|
||||||
|
var iceServersFromServer =
|
||||||
|
event.response.iceServers.map((e) => e.toSDKType()).toList();
|
||||||
|
|
||||||
|
if (iceServersFromServer.isNotEmpty) {
|
||||||
|
_serverProvidedIceServers = iceServersFromServer;
|
||||||
|
}
|
||||||
|
|
||||||
logger.fine('onConnected subscriberPrimary: ${_subscriberPrimary}, '
|
logger.fine('onConnected subscriberPrimary: ${_subscriberPrimary}, '
|
||||||
'serverVersion: ${event.response.serverVersion}, '
|
'serverVersion: ${event.response.serverVersion}, '
|
||||||
'iceServers: ${event.response.iceServers}');
|
'iceServers: ${event.response.iceServers}, '
|
||||||
|
'forceRelay: $event.response.clientConfiguration.forceRelay');
|
||||||
|
|
||||||
await _configurePeerConnections(
|
await _configurePeerConnections(
|
||||||
forceRelay: event.response.clientConfiguration.forceRelay ==
|
forceRelay: event.response.clientConfiguration.forceRelay,
|
||||||
lk_models.ClientConfigSetting.ENABLED);
|
serverProvidedIceServers: _serverProvidedIceServers);
|
||||||
|
|
||||||
if (!_subscriberPrimary) {
|
if (!_subscriberPrimary) {
|
||||||
// for subscriberPrimary, we negotiate when necessary (lazy)
|
// for subscriberPrimary, we negotiate when necessary (lazy)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ extension ICEServerExt on lk_rtc.ICEServer {
|
|||||||
RTCIceServer toSDKType() => RTCIceServer(
|
RTCIceServer toSDKType() => RTCIceServer(
|
||||||
urls: urls,
|
urls: urls,
|
||||||
username: username.isNotEmpty ? username : null,
|
username: username.isNotEmpty ? username : null,
|
||||||
credential: credential.isNotEmpty ? username : null,
|
credential: credential.isNotEmpty ? credential : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user