library fis_jsonrpc; import 'dart:collection'; import 'package:fis_common/extensions/type.dart'; import 'client_base.dart'; import 'interceptor.dart'; import 'services/index.dart'; export 'services/index.dart'; typedef T ServiceBuilder(); /// 默认地址标识 const String _defaultAddressSign = "FLYINSONO"; /// JSON-RPC 代理 class JsonRpcProxy { JsonRpcProxy({ this.defaultServerHost = "cloud.fis.plus", this.platformHost = "platform.fis.plus", }) { _currentHost = this.defaultServerHost; } /// 默认主机地址 final String defaultServerHost; /// 宿主平台代理地址 final String platformHost; late String _currentHost; /// 当前服务主机地址 String get currentHostAddress => "http://$_currentHost"; String get defaultAddressSign => _defaultAddressSign; HashMap _serviceCache = HashMap(); static PlatformService? _platformService; /* 服务代理设置 Start */ /// 平台服务 PlatformService get platform { if (_platformService == null) _platformService = PlatformService("http://$platformHost"); return _platformService!; } AuthenticationService get authentication => findService(() => new AuthenticationService(currentHostAddress)); ClientLogService get clientLog => findService(() => new ClientLogService(currentHostAddress)); ConnectService get connect => findService(() => new ConnectService(currentHostAddress)); DeviceService get device => findService(() => new DeviceService(currentHostAddress)); EmailService get email => findService(() => new EmailService(currentHostAddress)); IdentityApplyService get identityApply => findService(() => new IdentityApplyService(currentHostAddress)); LoginService get login => findService(() => new LoginService(currentHostAddress)); NotificationService get notification => findService(() => new NotificationService(currentHostAddress)); OrganizationService get organization => findService(() => new OrganizationService(currentHostAddress)); PatientService get patient => findService(() => new PatientService(currentHostAddress)); PositionService get position => findService(() => new PositionService(currentHostAddress)); RankService get rank => findService(() => new RankService(currentHostAddress)); RecordInfoService get recordInfo => findService(() => new RecordInfoService(currentHostAddress)); RegionService get region => findService(() => new RegionService(currentHostAddress)); RemedicalService get remedical => findService(() => new RemedicalService(currentHostAddress)); RoleService get role => findService(() => new RoleService(currentHostAddress)); SMSService get sMS => findService(() => new SMSService(currentHostAddress)); StorageService get storage => findService(() => new StorageService(currentHostAddress)); UserService get user => findService(() => new UserService(currentHostAddress)); VidProcessService get vidProcess => findService(() => new VidProcessService(currentHostAddress)); /* 服务代理设置 End */ /// 设置服务主机地址 void setServerHost(String address) { if (address == _defaultAddressSign) { address = defaultServerHost; } _currentHost = address; } /// 添加拦截器 void addInterceptor(JsonRpcInterceptor interceptor) => jsonRpcInterceptHost.addInterceptor(interceptor); /// 清空缓存 void clearCache() => _serviceCache.clear(); /// 查找Service实例 T findService(ServiceBuilder builder) { Type serviceType = typeOf(); if (!_serviceCache.containsKey(serviceType)) { _serviceCache[serviceType] = builder.call(); } return _serviceCache[serviceType] as T; } }