Skip to content

Commit 224aee1

Browse files
committed
support flutter web
1 parent c3a2a71 commit 224aee1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/services/connection/api_manager/binary_api.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'dart:convert';
33
import 'dart:developer' as dev;
44
import 'dart:io';
55

6-
import 'package:flutter/widgets.dart';
6+
import 'package:flutter/foundation.dart';
77
import 'package:web_socket_channel/io.dart';
88

99
import 'package:flutter_deriv_api/api/models/enums.dart';
@@ -19,6 +19,7 @@ import 'package:flutter_deriv_api/services/connection/call_manager/call_history.
1919
import 'package:flutter_deriv_api/services/connection/call_manager/call_manager.dart';
2020
import 'package:flutter_deriv_api/services/connection/call_manager/exceptions/call_manager_exception.dart';
2121
import 'package:flutter_deriv_api/services/connection/call_manager/subscription_manager.dart';
22+
import 'package:web_socket_channel/web_socket_channel.dart';
2223

2324
/// This class is for handling Binary API connection and calling Binary APIs.
2425
class BinaryAPI extends BaseAPI {
@@ -32,7 +33,7 @@ class BinaryAPI extends BaseAPI {
3233
/// Represents the active websocket connection.
3334
///
3435
/// This is used to send and receive data from the websocket server.
35-
IOWebSocketChannel? _webSocketChannel;
36+
WebSocketChannel? _webSocketChannel;
3637

3738
/// Stream subscription to API data.
3839
StreamSubscription<Map<String, dynamic>?>? _webSocketListener;
@@ -73,13 +74,18 @@ class BinaryAPI extends BaseAPI {
7374

7475
_logDebugInfo('connecting to $uri.');
7576

76-
await _setUserAgent();
77-
77+
if (!kIsWeb) {
78+
await _setUserAgent();
79+
}
7880
// 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+
}
8389

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

0 commit comments

Comments
 (0)