123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import 'package:fis_jsonrpc/services/authentication.m.dart';
- import 'package:fis_lib_media_rt/implementations/trtc/client_getter_mixin.dart';
- import 'package:flyinsonolite/jsonrpc/fisLib/services/log.m.dart';
- import 'package:flyinsonolite/jsonrpc/jsonrpcclientforFISLib.dart';
- import 'package:flyinsonolite/infrastructure/logger.dart';
- import 'package:flyinsonolite/infrastructure/storage.dart';
- import 'package:tencent_trtc_cloud/tx_device_manager.dart';
- /// 音视频硬件设置
- class HardwareSetting with TrtcClientGetterMixin {
- HardwareSetting._internal();
- static HardwareSetting? _instance;
- /// 获取单例
- static HardwareSetting get ins {
- _instance ??= HardwareSetting._internal();
- return _instance!;
- }
- String _cameraName = '';
- String _speakerName = '';
- String _micName = '';
- /// 推荐的Web端摄像头设备名称
- String get cameraName => _cameraName;
- /// 推荐的Web端扬声器设备名称
- String get speakerName => _speakerName;
- /// 推荐的Web端麦克风设备名称
- String get micName => _micName;
- Future setHardwareSettingsAsync() async {
- try {
- var hardwareInfo =
- await jsonRpcProxyForFISLib.hardware.getCurrentHardwareInfo();
- _cameraName = hardwareInfo.cameraInfo == null
- ? ''
- : (await _getTrtcCameraNameAsync(hardwareInfo.cameraInfo!.name!));
- _micName = hardwareInfo.micInfo == null
- ? ''
- : (await _getTrtcMicNameAsync(hardwareInfo.micInfo!.name!));
- _speakerName = hardwareInfo.speakerInfo?.name ?? '';
- await loggerAsyn(FISDeviceLogCategory.Info,
- "setHardwareSetting cameraName:$_cameraName,micName:$_micName,speakerName:$_speakerName");
- } catch (ex) {
- await loggerAsyn(FISDeviceLogCategory.Error,
- 'HardwareSetting setHardwareSettingsAsync error :$ex');
- }
- }
- Future<String> _getTrtcCameraNameAsync(String deviceName) async {
- final TXDeviceManager deviceManager = client.getDeviceManager();
- final Map<dynamic, dynamic>? cameras =
- await deviceManager.getDevicesList(2);
- if (Storage.platform != Platform.Windows) {
- switch (deviceName.toLowerCase()) {
- case "back camera":
- deviceName = "camera_1";
- break;
- default:
- deviceName = "camera_0"; //默认前置摄像头
- break;
- }
- }
- String cameraLabel = '';
- if (cameras != null && cameras.isNotEmpty) {
- cameras.forEach((key, value) {
- if (key == 'deviceList') {
- // print("🔍 _trtcGetCameras $key $value");
- if (value is List) {
- for (var element in value) {
- if (element is Map) {
- if (element["label"]
- .toString()
- .toLowerCase()
- .contains(deviceName.toLowerCase())) {
- cameraLabel = element["label"];
- }
- }
- }
- }
- }
- });
- }
- return cameraLabel;
- }
- Future<String> _getTrtcMicNameAsync(String deviceName) async {
- final Map<dynamic, dynamic>? microphones =
- await deviceManager.getDevicesList(0);
- String micLabel = '';
- if (microphones != null && microphones.isNotEmpty) {
- microphones.forEach((key, value) {
- if (key == 'deviceList') {
- // print("🔍 _trtcGetCameras $key $value");
- if (value is List) {
- for (var element in value) {
- if (element is Map) {
- if (element["label"]
- .toString()
- .toLowerCase()
- .contains(deviceName.toLowerCase())) {
- micLabel = element["label"];
- }
- }
- }
- }
- }
- });
- }
- return micLabel;
- }
- }
|