Skip to content

Commit d399fc3

Browse files
Merged with latest dev
2 parents 13fc123 + f277e80 commit d399fc3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/services/connection/api_manager/binary_api.dart

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:developer' as dev;
44
import 'dart:io';
55

66
import 'package:flutter/widgets.dart';
7+
import 'package:flutter_system_proxy/flutter_system_proxy.dart';
78
import 'package:web_socket_channel/io.dart';
89

910
import 'package:flutter_deriv_api/api/models/enums.dart';
@@ -23,8 +24,10 @@ import 'package:flutter_deriv_api/services/connection/call_manager/subscription_
2324
/// This class is for handling Binary API connection and calling Binary APIs.
2425
class BinaryAPI extends BaseAPI {
2526
/// Initializes [BinaryAPI] instance.
26-
BinaryAPI({String? key, bool enableDebug = false})
27-
: super(key: key ?? '${UniqueKey()}', enableDebug: enableDebug);
27+
BinaryAPI({
28+
String? key,
29+
bool enableDebug = false,
30+
}) : super(key: key ?? '${UniqueKey()}', enableDebug: enableDebug);
2831

2932
static const Duration _disconnectTimeOut = Duration(seconds: 5);
3033
static const Duration _websocketConnectTimeOut = Duration(seconds: 10);
@@ -74,12 +77,14 @@ class BinaryAPI extends BaseAPI {
7477
_logDebugInfo('connecting to $uri.');
7578

7679
await _setUserAgent();
80+
final String proxy = await FlutterSystemProxy.findProxyFromEnvironment(
81+
uri.toString().replaceAll('wss', 'https'));
82+
83+
final HttpClient client = HttpClient()..findProxy = (Uri uri) => proxy;
7784

7885
// Initialize connection to websocket server.
79-
_webSocketChannel = IOWebSocketChannel.connect(
80-
'$uri',
81-
pingInterval: _websocketConnectTimeOut,
82-
);
86+
_webSocketChannel = IOWebSocketChannel.connect('$uri',
87+
pingInterval: _websocketConnectTimeOut, customClient: client);
8388

8489
_webSocketListener = _webSocketChannel?.stream
8590
.map<Map<String, dynamic>?>((Object? result) => jsonDecode('$result'))

lib/state/connection/connection_cubit.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ class ConnectionCubit extends Cubit<ConnectionState> {
2525
this.printResponse = false,
2626
}) : super(const ConnectionInitialState()) {
2727
APIInitializer().initialize(
28-
api: api ?? BinaryAPI(key: _key, enableDebug: enableDebug),
28+
api: api ??
29+
BinaryAPI(
30+
key: _key,
31+
enableDebug: enableDebug,
32+
),
2933
);
3034

3135
_api = Injector()<BaseAPI>();

pubspec.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ dependencies:
2828
meta: ^1.8.0
2929
recase: ^4.0.0
3030
rxdart: ^0.27.7
31-
web_socket_channel: ^2.3.0
3231
device_info_plus: ^8.1.0
32+
flutter_system_proxy:
33+
git:
34+
url: [email protected]:BrowserStackCE/flutter_system_proxy.git
35+
ref: main
3336
package_info_plus: ^4.2.0
3437
connectivity_plus: ^5.0.2
3538

0 commit comments

Comments
 (0)