Files
ttstd_family_care/lib/features/connection/domain/connection_models.dart
T
TongTongStudio 41a514e9cc feat(connection): 添加远程控制路由并更新版本策略
- 新增 /connection 路由,从全局选中设备 SN 读取并渲染远程控制页
- 首页镜像操作改为静默下发 mirror 命令并跳转远程控制页
- 更新 AGENTS.md 版本管理策略为使用最新稳定版本
- 调整 pubspec.lock 中 hooks 与 record_use 版本
2026-08-26 06:16:44 +08:00

90 lines
2.3 KiB
Dart

import 'package:flutter/foundation.dart';
/// WebRTC 远程控制会话状态。
enum ConnectionState {
idle,
connecting,
connected,
ended,
error,
}
/// 信令消息类型(与后端 /ws/signal 及移动端 SignalMessage 对齐)。
class SignalType {
static const offer = 'OFFER';
static const answer = 'ANSWER';
static const iceCandidate = 'ICE_CANDIDATE';
static const registerSuccess = 'REGISTER_SUCCESS';
static const connectionRejected = 'CONNECTION_REJECTED';
static const targetOffline = 'TARGET_OFFLINE';
static const requestTimeout = 'REQUEST_TIMEOUT';
static const forceLogout = 'FORCE_LOGOUT';
static const ping = 'PING';
}
/// 信令消息模型。
@immutable
class SignalMessage {
final String type;
final String? fromDeviceId;
final String? toDeviceId;
final String? deviceType;
final String? payload;
const SignalMessage({
required this.type,
this.fromDeviceId,
this.toDeviceId,
this.deviceType,
this.payload,
});
factory SignalMessage.fromJson(Map<String, dynamic> json) {
return SignalMessage(
type: json['type'] as String? ?? '',
fromDeviceId: json['fromDeviceId'] as String?,
toDeviceId: json['toDeviceId'] as String?,
deviceType: json['deviceType'] as String?,
payload: json['payload'] as String?,
);
}
Map<String, dynamic> toJson() {
return {
'type': type,
if (fromDeviceId != null) 'fromDeviceId': fromDeviceId,
if (toDeviceId != null) 'toDeviceId': toDeviceId,
if (deviceType != null) 'deviceType': deviceType,
if (payload != null) 'payload': payload,
};
}
}
/// 远程控制会话会话上下文(当前控制的目标设备与连接身份)。
@immutable
class ConnectionSession {
final String targetSn;
final String clientName;
final ConnectionState state;
final String? errorMessage;
const ConnectionSession({
required this.targetSn,
required this.clientName,
this.state = ConnectionState.idle,
this.errorMessage,
});
ConnectionSession copyWith({
ConnectionState? state,
String? errorMessage,
}) {
return ConnectionSession(
targetSn: targetSn,
clientName: clientName,
state: state ?? this.state,
errorMessage: errorMessage ?? this.errorMessage,
);
}
}