Browse Source

add support for setting timeout of service

Melon 2 years ago
parent
commit
29f7c5ab75
2 changed files with 72 additions and 60 deletions
  1. 15 6
      lib/client_base.dart
  2. 57 54
      lib/rpc.dart

+ 15 - 6
lib/client_base.dart

@@ -12,19 +12,25 @@ const _C_DIO_FUTURE_ERR_KEYWORDS = "browser_adapter";
 
 /// JSON-RPC Client 基类
 class JsonRpcClientBase {
-  /// 服务主机地址
-  final String host;
+  /// 默认超时时间
+  // ignore: non_constant_identifier_names
+  static int DEAULT_TIMEOUT = 3000;
+
+  late int _timeout;
 
   late String _serviceName;
 
-  /// 服务名称
-  String get serviceName => _serviceName;
+  /// 服务主机地址
+  final String host;
 
   /// 自定义Http header
   final Map<String, String>? headers;
 
   /// 超时时间(ms)
-  final int? timeout;
+  int get timeout => _timeout;
+
+  /// 服务名称
+  String get serviceName => _serviceName;
 
   /// 服务请求地址
   String get servicePath =>
@@ -34,11 +40,14 @@ class JsonRpcClientBase {
     this.host,
     String serviceName, {
     this.headers,
-    this.timeout,
+    int? timeout,
   }) {
+    _timeout = timeout ?? DEAULT_TIMEOUT;
     _serviceName = serviceName;
   }
 
+  void setTimeout(int milliseconds) {}
+
   /// 设置服务名
   void setServiceName(String name) => _serviceName = name;
 

+ 57 - 54
lib/rpc.dart

@@ -46,88 +46,90 @@ class JsonRpcProxy {
   /// 平台服务
   PlatformService get platform {
     if (_platformService == null)
-      _platformService = PlatformService(
-        "http://$platformHost",
-        timeout: 15000,
-      );
+      _platformService = PlatformService("http://$platformHost");
     return _platformService!;
   }
 
-  WingRtcService get wingRtc =>
-      findService(() => new WingRtcService(currentHostAddress));
+	WingRtcService get wingRtc =>
+	findService(() => new WingRtcService(currentHostAddress));
 
-  MasterInteractionCenterService get masterInteractionCenter =>
-      findService(() => new MasterInteractionCenterService(currentHostAddress));
+	MasterInteractionCenterService get masterInteractionCenter =>
+	findService(() => new MasterInteractionCenterService(currentHostAddress));
 
-  SlaveInteractionCenterService get slaveInteractionCenter =>
-      findService(() => new SlaveInteractionCenterService(currentHostAddress));
+	SlaveInteractionCenterService get slaveInteractionCenter =>
+	findService(() => new SlaveInteractionCenterService(currentHostAddress));
 
-  LiveConsultationService get liveConsultation =>
-      findService(() => new LiveConsultationService(currentHostAddress));
+	LiveConsultationService get liveConsultation =>
+	findService(() => new LiveConsultationService(currentHostAddress));
 
-  AIDiagnosisService get aIDiagnosis =>
-      findService(() => new AIDiagnosisService(currentHostAddress));
+	AIDiagnosisService get aIDiagnosis =>
+	findService(() => new AIDiagnosisService(currentHostAddress));
 
-  ASRService get aSR => findService(() => new ASRService(currentHostAddress));
+	ASRService get aSR =>
+	findService(() => new ASRService(currentHostAddress));
 
-  AuthenticationService get authentication =>
-      findService(() => new AuthenticationService(currentHostAddress));
+	AuthenticationService get authentication =>
+	findService(() => new AuthenticationService(currentHostAddress));
 
-  ConnectService get connect =>
-      findService(() => new ConnectService(currentHostAddress));
+	ConnectService get connect =>
+	findService(() => new ConnectService(currentHostAddress));
 
-  LockService get lock =>
-      findService(() => new LockService(currentHostAddress));
+	DeviceService get device =>
+	findService(() => new DeviceService(currentHostAddress));
 
-  LoginService get login =>
-      findService(() => new LoginService(currentHostAddress));
+	EmailService get email =>
+	findService(() => new EmailService(currentHostAddress));
 
-  DeviceService get device =>
-      findService(() => new DeviceService(currentHostAddress));
+	IdentityApplyService get identityApply =>
+	findService(() => new IdentityApplyService(currentHostAddress));
 
-  EmailService get email =>
-      findService(() => new EmailService(currentHostAddress));
+	LockService get lock =>
+	findService(() => new LockService(currentHostAddress));
 
-  IdentityApplyService get identityApply =>
-      findService(() => new IdentityApplyService(currentHostAddress));
+	LoginService get login =>
+	findService(() => new LoginService(currentHostAddress));
 
-  OrganizationService get organization =>
-      findService(() => new OrganizationService(currentHostAddress));
+	OrganizationService get organization =>
+	findService(() => new OrganizationService(currentHostAddress));
 
-  PatientService get patient =>
-      findService(() => new PatientService(currentHostAddress));
+	PatientService get patient =>
+	findService(() => new PatientService(currentHostAddress));
 
-  PositionService get position =>
-      findService(() => new PositionService(currentHostAddress));
+	PositionService get position =>
+	findService(() => new PositionService(currentHostAddress));
 
-  RankService get rank =>
-      findService(() => new RankService(currentHostAddress));
+	RankService get rank =>
+	findService(() => new RankService(currentHostAddress));
 
-  RecordInfoService get recordInfo =>
-      findService(() => new RecordInfoService(currentHostAddress));
+	RecordInfoService get recordInfo =>
+	findService(() => new RecordInfoService(currentHostAddress));
 
-  RegionService get region =>
-      findService(() => new RegionService(currentHostAddress));
+	RegionService get region =>
+	findService(() => new RegionService(currentHostAddress));
 
-  RemedicalService get remedical =>
-      findService(() => new RemedicalService(currentHostAddress));
+	RemedicalService get remedical =>
+	findService(() => new RemedicalService(currentHostAddress));
 
-  ReportService get report =>
-      findService(() => new ReportService(currentHostAddress));
+	ReportService get report =>
+	findService(() => new ReportService(currentHostAddress));
 
-  RoleService get role =>
-      findService(() => new RoleService(currentHostAddress));
+	RoleService get role =>
+	findService(() => new RoleService(currentHostAddress));
 
-  SMSService get sMS => findService(() => new SMSService(currentHostAddress));
+	SMSService get sMS =>
+	findService(() => new SMSService(currentHostAddress));
 
-  StorageService get storage =>
-      findService(() => new StorageService(currentHostAddress));
+	StorageService get storage =>
+	findService(() => new StorageService(currentHostAddress));
 
-  UserService get user =>
-      findService(() => new UserService(currentHostAddress));
+	UserService get user =>
+	findService(() => new UserService(currentHostAddress));
 
-  VinnoServerService get vinnoServer =>
-      findService(() => new VinnoServerService(currentHostAddress));
+	VinnoServerService get vinnoServer =>
+	findService(() => new VinnoServerService(currentHostAddress));
+
+
+  /* 服务代理设置 End */
 
   /// 设置服务主机地址
   void setServerHost(String address) {
@@ -151,3 +153,4 @@ class JsonRpcProxy {
     return _serviceCache[serviceType] as T;
   }
 }
+