59 lines
1.5 KiB
Dart
59 lines
1.5 KiB
Dart
import 'dart:ffi';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import '../../../../core/storage/user_storage.dart';
|
|
|
|
class RemoteHttpDatasource {
|
|
final Dio _dio;
|
|
final UserStorage _userStorage; // 🔥 新增字段
|
|
|
|
|
|
RemoteHttpDatasource(this._dio, this._userStorage);
|
|
|
|
/// 示例:获取控制授权 (对应之前逻辑中的权限申请)
|
|
/* Future<Map<String, dynamic>> requestControlAuth(String robotId) async {
|
|
try {
|
|
final response = await _dio.post(
|
|
'/robot/auth/request',
|
|
data: {'robotId': robotId},
|
|
);
|
|
return response.data;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}*/
|
|
|
|
|
|
Future<bool> requestRemoteControlViaHttp( String deviceId, String currentDeviceId) async {
|
|
final user = await _userStorage.getUser();
|
|
if (user == null) {
|
|
return false;
|
|
}
|
|
final token = user.token;
|
|
final response = await _dio.post(
|
|
'/forward/device/remoteControl',
|
|
options: Options(
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ${token}',
|
|
},
|
|
),
|
|
data: {'deviceId': deviceId, 'platform': "app"});
|
|
|
|
try {
|
|
final data = response.data as Map<String, dynamic>;
|
|
final success = data['success'] as bool? ?? false;
|
|
if (success) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} catch (e) {
|
|
debugPrint('❌ [RemoteHttp] 解析响应失败:$e');
|
|
return false;
|
|
}
|
|
}
|
|
}
|