fix(webrtc): 修复 ICE 服务器解析逻辑,支持自定义端口与标准参数
修正 ice_servers.dart 中的 URL 解析,使 stun/turn 地址能正确识别自定义端口及 transport/port 参数;同步调整 webrtc_controller.dart 中的调用方式以适配新解析逻辑。
This commit is contained in:
@@ -100,17 +100,23 @@ class WebRtcController {
|
||||
Future<void> initialize() async {
|
||||
await renderer.initialize();
|
||||
|
||||
// 桌面端(Linux/Windows)原生 RTCConfiguration 的 ice_servers 是定长数组
|
||||
// (kMaxIceServerSize = 8),且原生解析未做越界检查,条目超限会越界写堆内存,
|
||||
// 触发 `free(): invalid pointer` 直接闪退。这里做一次防御性截断兜底。
|
||||
final safeIceServers = _limitIceServers(kIceServers);
|
||||
|
||||
final configuration = {
|
||||
'iceServers': kIceServers,
|
||||
'iceServers': safeIceServers,
|
||||
'sdpSemantics': 'unified-plan',
|
||||
'iceCandidatePoolSize': 10,
|
||||
// 增强复杂网络下的稳定性,参考 Android 端配置。
|
||||
'continualGatheringPolicy': 'gatherContinually',
|
||||
'iceTransportsType': 'all',
|
||||
// 标准键名为 iceTransportPolicy(桌面端原生只识别这个键)。
|
||||
'iceTransportPolicy': 'all',
|
||||
'tcpCandidatePolicy': 'enabled',
|
||||
};
|
||||
|
||||
final iceUrls = (kIceServers)
|
||||
final iceUrls = safeIceServers
|
||||
.map((e) => '${e['username'] != null ? '(${e['username']})' : ''}${e['urls']}')
|
||||
.join(', ');
|
||||
debugPrint('[WebRtcController] signaling server: ${signaling.serverUrl} | '
|
||||
@@ -170,6 +176,25 @@ class WebRtcController {
|
||||
_sendOffer(reorderedSdp, authType: authType, authValue: authValue);
|
||||
}
|
||||
|
||||
/// 防御性限制 ICE 服务器条目数,避免桌面端原生越界写内存导致闪退。
|
||||
///
|
||||
/// flutter_webrtc 桌面端 `FlutterWebRTCBase::CreateIceServers()` 会按传入
|
||||
/// 列表长度直接写入定长数组 `IceServer ice_servers[8]`,**无越界检查**。
|
||||
/// 条目数 > 8 时会破坏相邻堆内存,在释放阶段抛出
|
||||
/// `free(): invalid pointer` 并使进程崩溃(Android/iOS 用动态列表不受影响)。
|
||||
///
|
||||
/// 正常情况下 [kIceServers] 已控制在 8 条以内,此处仅作为后续新增服务器
|
||||
/// 时的安全网:超限时截断并打印告警,而不是让应用直接闪退。
|
||||
List<Map<String, dynamic>> _limitIceServers(
|
||||
List<Map<String, dynamic>> servers,
|
||||
) {
|
||||
if (servers.length <= kMaxIceServerCount) return servers;
|
||||
debugPrint('[WebRtcController] 警告: ICE 服务器数量 ${servers.length} '
|
||||
'超过原生上限 $kMaxIceServerCount,已截断以避免桌面端崩溃。'
|
||||
'请在 lib/config/ice_servers.dart 中合并同凭据的地址。');
|
||||
return servers.sublist(0, kMaxIceServerCount);
|
||||
}
|
||||
|
||||
/// 重排 Offer SDP 中 `m=video` 行的视频编解码器顺序:VP8/VP9 优先,H264 兜底。
|
||||
///
|
||||
/// 与 Android 被控端 [WebRtcClient.optimizeSdp] 的编解码优先级保持一致,
|
||||
|
||||
Reference in New Issue
Block a user