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 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 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, ); } }