-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hamed/refactor_connection_cubit #276
base: flutter-version-3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
# | ||
# NOTE: This podspec is NOT to be published. It is only used as a local source! | ||
# This is a generated file; do not edit or check into version control. | ||
# This podspec is NOT to be published. It is only used as a local source! | ||
# This is a generated file; do not edit or check into version control. | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'Flutter' | ||
s.version = '1.0.0' | ||
s.summary = 'High-performance, high-fidelity mobile apps.' | ||
s.homepage = 'https://flutter.io' | ||
s.license = { :type => 'MIT' } | ||
s.summary = 'A UI toolkit for beautiful and fast apps.' | ||
s.homepage = 'https://flutter.dev' | ||
s.license = { :type => 'BSD' } | ||
s.author = { 'Flutter Dev Team' => '[email protected]' } | ||
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } | ||
s.ios.deployment_target = '8.0' | ||
s.ios.deployment_target = '11.0' | ||
# Framework linking is handled by Flutter tooling, not CocoaPods. | ||
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. | ||
s.vendored_frameworks = 'path/to/nothing' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,34 @@ | ||
PODS: | ||
- connectivity (0.0.1): | ||
- Flutter | ||
- Reachability | ||
- device_info (0.0.1): | ||
- device_info_plus (0.0.1): | ||
- Flutter | ||
- Flutter (1.0.0) | ||
- flutter_deriv_api (0.0.1): | ||
- Flutter | ||
- package_info (0.0.1): | ||
- package_info_plus (0.4.5): | ||
- Flutter | ||
- Reachability (3.2) | ||
|
||
DEPENDENCIES: | ||
- connectivity (from `.symlinks/plugins/connectivity/ios`) | ||
- device_info (from `.symlinks/plugins/device_info/ios`) | ||
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) | ||
- Flutter (from `Flutter`) | ||
- flutter_deriv_api (from `.symlinks/plugins/flutter_deriv_api/ios`) | ||
- package_info (from `.symlinks/plugins/package_info/ios`) | ||
|
||
SPEC REPOS: | ||
trunk: | ||
- Reachability | ||
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) | ||
|
||
EXTERNAL SOURCES: | ||
connectivity: | ||
:path: ".symlinks/plugins/connectivity/ios" | ||
device_info: | ||
:path: ".symlinks/plugins/device_info/ios" | ||
device_info_plus: | ||
:path: ".symlinks/plugins/device_info_plus/ios" | ||
Flutter: | ||
:path: Flutter | ||
flutter_deriv_api: | ||
:path: ".symlinks/plugins/flutter_deriv_api/ios" | ||
package_info: | ||
:path: ".symlinks/plugins/package_info/ios" | ||
package_info_plus: | ||
:path: ".symlinks/plugins/package_info_plus/ios" | ||
|
||
SPEC CHECKSUMS: | ||
connectivity: c4130b2985d4ef6fd26f9702e886bd5260681467 | ||
device_info: d7d233b645a32c40dfdc212de5cf646ca482f175 | ||
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c | ||
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed | ||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 | ||
flutter_deriv_api: 9e29abd7cc5091b72303f9c8be549618415f1437 | ||
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62 | ||
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 | ||
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e | ||
|
||
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c | ||
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 | ||
|
||
COCOAPODS: 1.10.1 | ||
COCOAPODS: 1.12.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:developer' as dev; | ||
import 'dart:io'; | ||
import 'dart:io' as io; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:web_socket_channel/io.dart'; | ||
|
||
import 'package:deriv_web_socket_client/deriv_web_socket_client.dart' as ws; | ||
|
||
import 'package:flutter_deriv_api/api/models/enums.dart'; | ||
import 'package:flutter_deriv_api/basic_api/generated/forget_all_receive.dart'; | ||
|
@@ -27,12 +28,11 @@ class BinaryAPI extends BaseAPI { | |
: super(key: key ?? '${UniqueKey()}', enableDebug: enableDebug); | ||
|
||
static const Duration _disconnectTimeOut = Duration(seconds: 5); | ||
static const Duration _websocketConnectTimeOut = Duration(seconds: 10); | ||
|
||
/// Represents the active websocket connection. | ||
/// | ||
/// This is used to send and receive data from the websocket server. | ||
IOWebSocketChannel? _webSocketChannel; | ||
ws.WebSocket? _webSocket; | ||
|
||
/// Stream subscription to API data. | ||
StreamSubscription<Map<String, dynamic>?>? _webSocketListener; | ||
|
@@ -49,6 +49,9 @@ class BinaryAPI extends BaseAPI { | |
/// Gets API subscription history. | ||
CallHistory? get subscriptionHistory => _subscriptionManager?.callHistory; | ||
|
||
@override | ||
Stream<ws.ConnectionState> get connectionStatus => _webSocket!.connection; | ||
|
||
@override | ||
Future<void> connect( | ||
ConnectionInformation? connectionInformation, { | ||
|
@@ -76,12 +79,9 @@ class BinaryAPI extends BaseAPI { | |
await _setUserAgent(); | ||
|
||
// Initialize connection to websocket server. | ||
_webSocketChannel = IOWebSocketChannel.connect( | ||
'$uri', | ||
pingInterval: _websocketConnectTimeOut, | ||
); | ||
_webSocket = ws.WebSocket(uri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A quick question. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main reason behind decreasing the ping interval is to find out the device disconnection as soon as disconnection happened because we are only relying on this ping to update the connection status. |
||
|
||
_webSocketListener = _webSocketChannel?.stream | ||
_webSocketListener = _webSocket?.messages | ||
.map<Map<String, dynamic>?>((Object? result) => jsonDecode('$result')) | ||
.listen( | ||
(Map<String, dynamic>? message) { | ||
|
@@ -117,7 +117,7 @@ class BinaryAPI extends BaseAPI { | |
@override | ||
void addToChannel(Map<String, dynamic> request) { | ||
try { | ||
_webSocketChannel?.sink.add(utf8.encode(jsonEncode(request))); | ||
_webSocket?.send(utf8.encode(jsonEncode(request))); | ||
// ignore: avoid_catches_without_on_clauses | ||
} catch (error) { | ||
_logDebugInfo('error while adding to channel.', error: error); | ||
|
@@ -167,7 +167,7 @@ class BinaryAPI extends BaseAPI { | |
try { | ||
await _webSocketListener?.cancel(); | ||
|
||
await _webSocketChannel?.sink.close().timeout( | ||
await _webSocket?.close().timeout( | ||
_disconnectTimeOut, | ||
onTimeout: () => throw TimeoutException('Could not close sink.'), | ||
); | ||
|
@@ -176,7 +176,7 @@ class BinaryAPI extends BaseAPI { | |
_logDebugInfo('disconnect error.', error: e); | ||
} finally { | ||
_webSocketListener = null; | ||
_webSocketChannel = null; | ||
_webSocket = null; | ||
} | ||
} | ||
|
||
|
@@ -228,7 +228,7 @@ class BinaryAPI extends BaseAPI { | |
final String userAgent = await getUserAgent(); | ||
|
||
if (userAgent.isNotEmpty) { | ||
WebSocket.userAgent = userAgent; | ||
io.WebSocket.userAgent = userAgent; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been added automatically to
Info.plist
after the build and I suppose it is because ofMinimumOSVersion 11
.