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'; export 'request.dart'; export 'exception.dart'; export 'interceptor.dart'; export 'listener/listener.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!; } *******Separator****** /* 服务代理设置 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; } }