@@ -4,6 +4,7 @@ import 'dart:developer' as dev;
4
4
import 'dart:io' ;
5
5
6
6
import 'package:flutter/widgets.dart' ;
7
+ import 'package:flutter_system_proxy/flutter_system_proxy.dart' ;
7
8
import 'package:web_socket_channel/io.dart' ;
8
9
9
10
import 'package:flutter_deriv_api/api/models/enums.dart' ;
@@ -23,8 +24,10 @@ import 'package:flutter_deriv_api/services/connection/call_manager/subscription_
23
24
/// This class is for handling Binary API connection and calling Binary APIs.
24
25
class BinaryAPI extends BaseAPI {
25
26
/// 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);
28
31
29
32
static const Duration _disconnectTimeOut = Duration (seconds: 5 );
30
33
static const Duration _websocketConnectTimeOut = Duration (seconds: 10 );
@@ -74,12 +77,14 @@ class BinaryAPI extends BaseAPI {
74
77
_logDebugInfo ('connecting to $uri .' );
75
78
76
79
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;
77
84
78
85
// 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);
83
88
84
89
_webSocketListener = _webSocketChannel? .stream
85
90
.map <Map <String , dynamic >?>((Object ? result) => jsonDecode ('$result ' ))
0 commit comments