feat: 增加请求弹窗和拒绝说明

This commit is contained in:
2026-07-15 21:40:00 +08:00
parent 839a980b45
commit f1457e68eb
13 changed files with 645 additions and 5 deletions

View File

@@ -34,6 +34,9 @@ class RemoteController {
/// 目标被控端不在线(服务器回送 TARGET_OFFLINE用于提示用户并复位 UI
void Function(String message)? onTargetOffline;
/// 被控端拒绝了连接请求(用于提示用户并复位 UI
void Function(String message)? onConnectionRejected;
/// 远端视频渲染器就绪。
void Function(RTCVideoRenderer renderer)? onRemoteStream;
@@ -90,6 +93,8 @@ class RemoteController {
switch (message.type?.toUpperCase()) {
case 'ANSWER':
final payload = jsonDecode(message.payload!) as Map<String, dynamic>;
// 被控端已接受连接请求,进入 WebRTC 协商阶段。
onStatusChanged?.call('状态: 被控端已接受连接,正在建立连接...');
_webRtc?.handleAnswer(payload['sdp'] as String);
break;
case 'ICE_CANDIDATE':
@@ -101,6 +106,13 @@ class RemoteController {
onStatusChanged?.call('状态: $text');
onTargetOffline?.call(text);
break;
case 'CONNECTION_REJECTED':
case 'REQUEST_ERROR':
case 'REQUEST_TIMEOUT':
final text = message.payload ?? '连接请求失败';
onStatusChanged?.call('状态: $text');
onConnectionRejected?.call(text);
break;
}
}

View File

@@ -102,6 +102,9 @@ class _ControllerHomeState extends State<ControllerHome> {
_controller!.onTargetOffline = (message) {
_onTargetOffline(message);
};
_controller!.onConnectionRejected = (message) {
_onConnectionRejected(message);
};
_controller!.onRemoteStream = (renderer) {
setState(() => _renderer = renderer);
renderer.addListener(_onRendererUpdate);
@@ -147,6 +150,20 @@ class _ControllerHomeState extends State<ControllerHome> {
setState(() => _connected = false);
}
/// 被控端拒绝连接请求:提示用户并复位到连接设置面板。
Future<void> _onConnectionRejected(String message) async {
final scaffoldCtx = _scaffoldKey.currentState?.context;
if (mounted && scaffoldCtx != null) {
ScaffoldMessenger.of(scaffoldCtx).showSnackBar(
SnackBar(
content: Text(message),
duration: const Duration(seconds: 3),
),
);
}
setState(() => _connected = false);
}
Future<void> _disconnect() async {
await _controller?.disconnect();
_controller = null;