对接远程遥控
This commit is contained in:
@@ -60,48 +60,48 @@ class AuthTcpDatasourceImpl implements AuthTcpDatasource {
|
||||
debugPrint('✅ sendAuthPacket[AuthTcp] 认证包已发送');
|
||||
|
||||
// 获取用户设备列表
|
||||
try {
|
||||
// 1. 获取 Either 结果
|
||||
final eitherResult = await getUserDeviceUseCase.repository.getUserDevice(username);
|
||||
|
||||
// 2. 使用 fold 解包 Either
|
||||
// left: 处理错误情况 (DeviceFailure)
|
||||
// right: 处理成功情况 (List<DeviceEntity>)
|
||||
await eitherResult.fold(
|
||||
(failure) {
|
||||
// 处理失败:打印日志或抛出异常
|
||||
debugPrint('❌ sendAuthPacket [AuthTcp] 获取设备列表失败:$failure');
|
||||
throw Exception('获取设备列表失败:$failure');
|
||||
},
|
||||
(devices) async {
|
||||
// 处理成功:devices 现在是真正的 List<DeviceEntity>
|
||||
if (devices.isEmpty) {
|
||||
debugPrint('⚠️ sendAuthPacket[AuthTcp] 当前用户无可用设备,跳过切换步骤');
|
||||
return;
|
||||
}
|
||||
|
||||
// 取第一个设备
|
||||
final DeviceEntity targetDevice = devices.first;
|
||||
debugPrint('📱 sendAuthPacket[AuthTcp] 准备切换至默认设备:${targetDevice.deviceName}');
|
||||
|
||||
// 切换设备 (同样,如果 switchDeviceUseCase 也返回 Either,也需要 fold 处理)
|
||||
final switchResult = await switchDeviceUseCase.deviceRepository.switchDevice("app",targetDevice.deviceName);
|
||||
|
||||
await switchResult.fold(
|
||||
(failure) {
|
||||
debugPrint('❌ sendAuthPacket[AuthTcp] 切换设备失败:$failure');
|
||||
throw Exception('切换设备失败:$failure');
|
||||
},
|
||||
(success) {
|
||||
debugPrint('✅ sendAuthPacket[AuthTcp] 设备切换成功,服务端应开始推送数据');
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('❌ sendAuthPacket[AuthTcp] 设备订阅流程异常:$e');
|
||||
rethrow;
|
||||
}
|
||||
// try {
|
||||
// // 1. 获取 Either 结果
|
||||
// final eitherResult = await getUserDeviceUseCase.repository.getUserDevice(username);
|
||||
//
|
||||
// // 2. 使用 fold 解包 Either
|
||||
// // left: 处理错误情况 (DeviceFailure)
|
||||
// // right: 处理成功情况 (List<DeviceEntity>)
|
||||
// await eitherResult.fold(
|
||||
// (failure) {
|
||||
// // 处理失败:打印日志或抛出异常
|
||||
// debugPrint('❌ sendAuthPacket [AuthTcp] 获取设备列表失败:$failure');
|
||||
// throw Exception('获取设备列表失败:$failure');
|
||||
// },
|
||||
// (devices) async {
|
||||
// // 处理成功:devices 现在是真正的 List<DeviceEntity>
|
||||
// if (devices.isEmpty) {
|
||||
// debugPrint('⚠️ sendAuthPacket[AuthTcp] 当前用户无可用设备,跳过切换步骤');
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 取第一个设备
|
||||
// final DeviceEntity targetDevice = devices.first;
|
||||
// debugPrint('📱 sendAuthPacket[AuthTcp] 准备切换至默认设备:${targetDevice.deviceName}');
|
||||
//
|
||||
// // 切换设备 (同样,如果 switchDeviceUseCase 也返回 Either,也需要 fold 处理)
|
||||
// final switchResult = await switchDeviceUseCase.deviceRepository.switchDevice("app",targetDevice.deviceName);
|
||||
//
|
||||
// await switchResult.fold(
|
||||
// (failure) {
|
||||
// debugPrint('❌ sendAuthPacket[AuthTcp] 切换设备失败:$failure');
|
||||
// throw Exception('切换设备失败:$failure');
|
||||
// },
|
||||
// (success) {
|
||||
// debugPrint('✅ sendAuthPacket[AuthTcp] 设备切换成功,服务端应开始推送数据');
|
||||
// },
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// } catch (e) {
|
||||
// debugPrint('❌ sendAuthPacket[AuthTcp] 设备订阅流程异常:$e');
|
||||
// rethrow;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user