feat: flutter优化滑动不跟手
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
|
||||
import '../config/ice_servers.dart';
|
||||
@@ -49,6 +50,10 @@ class WebRtcController {
|
||||
'iceServers': kIceServers,
|
||||
'sdpSemantics': 'unified-plan',
|
||||
'iceCandidatePoolSize': 10,
|
||||
// 增强复杂网络下的稳定性,参考 Android 端配置。
|
||||
'continualGatheringPolicy': 'gatherContinually',
|
||||
'iceTransportsType': 'all',
|
||||
'tcpCandidatePolicy': 'enabled',
|
||||
};
|
||||
|
||||
_pc = await createPeerConnection(configuration);
|
||||
@@ -64,8 +69,11 @@ class WebRtcController {
|
||||
init: RTCRtpTransceiverInit(direction: TransceiverDirection.RecvOnly),
|
||||
);
|
||||
|
||||
// 创建控制用 DataChannel(有序)。
|
||||
final dcInit = RTCDataChannelInit()..ordered = true;
|
||||
// 创建控制用 DataChannel。
|
||||
// 使用非可靠、无序模式以降低延迟,解决“不跟手”问题。
|
||||
final dcInit = RTCDataChannelInit()
|
||||
..ordered = false
|
||||
..maxRetransmits = 0;
|
||||
_dataChannel = await _pc!.createDataChannel(kDataChannelLabel, dcInit);
|
||||
_setupDataChannel(_dataChannel!);
|
||||
|
||||
@@ -166,6 +174,7 @@ class WebRtcController {
|
||||
/// 通过 DataChannel 发送控制指令(JSON 字符串)。
|
||||
void sendControlCommand(String commandJson) {
|
||||
if (_dataChannel?.state == RTCDataChannelState.RTCDataChannelOpen) {
|
||||
debugPrint('WebRtcController: Sending command -> $commandJson');
|
||||
_dataChannel!.send(RTCDataChannelMessage(commandJson));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user