@@ -3,7 +3,7 @@ import 'dart:convert';
3
3
import 'dart:developer' as dev;
4
4
import 'dart:io' ;
5
5
6
- import 'package:flutter/widgets .dart' ;
6
+ import 'package:flutter/foundation .dart' ;
7
7
import 'package:web_socket_channel/io.dart' ;
8
8
9
9
import 'package:flutter_deriv_api/api/models/enums.dart' ;
@@ -19,6 +19,7 @@ import 'package:flutter_deriv_api/services/connection/call_manager/call_history.
19
19
import 'package:flutter_deriv_api/services/connection/call_manager/call_manager.dart' ;
20
20
import 'package:flutter_deriv_api/services/connection/call_manager/exceptions/call_manager_exception.dart' ;
21
21
import 'package:flutter_deriv_api/services/connection/call_manager/subscription_manager.dart' ;
22
+ import 'package:web_socket_channel/web_socket_channel.dart' ;
22
23
23
24
/// This class is for handling Binary API connection and calling Binary APIs.
24
25
class BinaryAPI extends BaseAPI {
@@ -32,7 +33,7 @@ class BinaryAPI extends BaseAPI {
32
33
/// Represents the active websocket connection.
33
34
///
34
35
/// This is used to send and receive data from the websocket server.
35
- IOWebSocketChannel ? _webSocketChannel;
36
+ WebSocketChannel ? _webSocketChannel;
36
37
37
38
/// Stream subscription to API data.
38
39
StreamSubscription <Map <String , dynamic >?>? _webSocketListener;
@@ -73,13 +74,18 @@ class BinaryAPI extends BaseAPI {
73
74
74
75
_logDebugInfo ('connecting to $uri .' );
75
76
76
- await _setUserAgent ();
77
-
77
+ if (! kIsWeb) {
78
+ await _setUserAgent ();
79
+ }
78
80
// Initialize connection to websocket server.
79
- _webSocketChannel = IOWebSocketChannel .connect (
80
- '$uri ' ,
81
- pingInterval: _websocketConnectTimeOut,
82
- );
81
+ if (kIsWeb) {
82
+ _webSocketChannel = WebSocketChannel .connect (uri);
83
+ } else {
84
+ _webSocketChannel = IOWebSocketChannel .connect (
85
+ '$uri ' ,
86
+ pingInterval: _websocketConnectTimeOut,
87
+ );
88
+ }
83
89
84
90
_webSocketListener = _webSocketChannel? .stream
85
91
.map <Map <String , dynamic >?>((Object ? result) => jsonDecode ('$result ' ))
0 commit comments