1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:vitalapp/architecture/utils/json_rpc_ex_interceptor.dart';
- import 'package:vitalapp/global.dart';
- import 'package:vitalapp/mock/mock.dart';
- final _host = _ProxyHost();
- abstract class RpcSettingCache {
- static String hostPath = "http://127.0.0.1:80";
- static void setRpcHostPath(String path) {
- hostPath = path;
- final uri = Uri.parse(hostPath);
- rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == 'https');
- rpc.clearCache();
- }
- }
- JsonRpcProxy get rpc => _host.getProxy();
- class _ProxyHost {
- JsonRpcProxy? _proxy;
- final JsonRpcProxy _mockProxy = JsonRpcMockProxy()
- ..setServerHost(RpcSettingCache.hostPath);
-
- JsonRpcProxy getProxy() {
- if (kIsOnline == false) {
- return _mockProxy;
- }
- if (_proxy == null) {
- _init();
- }
- return _proxy!;
- }
-
- void _init() {
- _buildProxy();
-
- }
-
- void _buildProxy() {
- final originServerHost =
- _proxy?.currentHostAddress ?? RpcSettingCache.hostPath;
- JsonRpcProxy jsonRpcProxy = JsonRpcProxy();
- _proxy = jsonRpcProxy;
- if (originServerHost.isNotEmpty) {
- _setRpcHost(_proxy!, originServerHost);
- }
-
- _proxy!.addInterceptor(JsonRpcExInterceptor());
- }
-
-
-
-
-
-
-
-
- static void _setRpcHost(JsonRpcProxy rpc, url) {
- final uri = Uri.parse(url);
- rpc.setServerHost("${uri.host}:${uri.port}", uri.scheme == "https");
- }
- }
- extension JsonRpcProxyExt on JsonRpcProxy {
- JsonRpcProxy get mock => _host._mockProxy;
- }
|