diff --git a/lib/services/connection/api_manager/binary_api.dart b/lib/services/connection/api_manager/binary_api.dart index 784e1d4f54..43b58c060c 100644 --- a/lib/services/connection/api_manager/binary_api.dart +++ b/lib/services/connection/api_manager/binary_api.dart @@ -27,11 +27,15 @@ class BinaryAPI extends BaseAPI { BinaryAPI({ String? key, bool enableDebug = false, + this.proxyAwareConnection = false, }) : super(key: key ?? '${UniqueKey()}', enableDebug: enableDebug); static const Duration _disconnectTimeOut = Duration(seconds: 5); static const Duration _websocketConnectTimeOut = Duration(seconds: 10); + /// A flag to indicate if the connection is proxy aware. + final bool proxyAwareConnection; + /// Represents the active websocket connection. /// /// This is used to send and receive data from the websocket server. @@ -77,10 +81,15 @@ class BinaryAPI extends BaseAPI { _logDebugInfo('connecting to $uri.'); await _setUserAgent(); - final String proxy = await FlutterSystemProxy.findProxyFromEnvironment( - uri.toString().replaceAll('wss', 'https')); - final HttpClient client = HttpClient()..findProxy = (Uri uri) => proxy; + HttpClient? client; + + if (proxyAwareConnection) { + final String proxy = await FlutterSystemProxy.findProxyFromEnvironment( + uri.toString().replaceAll('wss', 'https')); + + client = HttpClient()..findProxy = (Uri uri) => proxy; + } // Initialize connection to websocket server. _webSocketChannel = IOWebSocketChannel.connect('$uri', diff --git a/lib/state/connection/connection_cubit.dart b/lib/state/connection/connection_cubit.dart index f8e43800da..4659014740 100644 --- a/lib/state/connection/connection_cubit.dart +++ b/lib/state/connection/connection_cubit.dart @@ -22,12 +22,15 @@ class ConnectionCubit extends Cubit { ConnectionInformation connectionInformation, { BaseAPI? api, this.enableDebug = false, + // TODO(NA): Refactor to only get BinaryAPI instance. and printResponse and proxyAwareConnection can be part of BinaryAPI only. this.printResponse = false, + this.proxyAwareConnection = false, }) : super(const ConnectionInitialState()) { APIInitializer().initialize( api: api ?? BinaryAPI( key: _key, + proxyAwareConnection: proxyAwareConnection, enableDebug: enableDebug, ), ); @@ -55,6 +58,9 @@ class ConnectionCubit extends Cubit { /// Default value is `false`. final bool printResponse; + /// A flag to indicate if the connection is proxy aware. + final bool proxyAwareConnection; + // In some devices like Samsung J6 or Huawei Y7, the call manager doesn't response to the ping call less than 5 sec. final Duration _pingTimeout = const Duration(seconds: 5);