From 90592c9a7fee57ce91a6db3c5a29312fa45d03cb Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 10 Dec 2023 16:40:50 +0100 Subject: [PATCH] Connection timeout parameter --- CHANGELOG.md | 4 ++++ analysis_options.yaml | 2 +- lib/src/battle_net.dart | 23 +++++++++++++------ pubspec.lock | 18 +++++++++++---- pubspec.yaml | 8 +++---- ...nnected_realm_search_integration_test.dart | 4 ++-- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8adc994..85a3b45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.3+2 + +* Connection timeout parameter +* ## 0.1.3+1 * battle_net_scope.dart exported diff --git a/analysis_options.yaml b/analysis_options.yaml index 04f0b92..6de9eb7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -38,7 +38,7 @@ analyzer: # Ignore analyzer hints for updating pubspecs when using Future or # Stream and not importing dart:async # Please see https://github.com/flutter/flutter/pull/24528 for details. - sdk_version_async_exported_from_core: ignore + # sdk_version_async_exported_from_core: ignore exclude: - "bin/cache/**" # the following two are relative to the stocks example and the flutter package respectively diff --git a/lib/src/battle_net.dart b/lib/src/battle_net.dart index 3ace99a..7e018f9 100644 --- a/lib/src/battle_net.dart +++ b/lib/src/battle_net.dart @@ -23,12 +23,14 @@ import 'models/token/token_index_response.dart'; class BattleNet { final String _auth; final String _clientId; + final int connectionTimeout; BattleNet({ required String clientId, required String clientSecret, LogLevel logLevel = LogLevel.BASIC, bool enableReleaseLogging = false, + this.connectionTimeout = 10000, }) : _clientId = clientId, _auth = base64.encode(utf8.encode('$clientId:$clientSecret')) { Logger.init(logLevel: logLevel, enableReleaseLogging: enableReleaseLogging); @@ -48,7 +50,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -101,7 +104,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -131,7 +135,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -158,7 +163,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -192,7 +198,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -225,7 +232,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); @@ -264,7 +272,8 @@ class BattleNet { Logger.logRequest(request: request); - final http.StreamedResponse response = await request.send(); + final http.StreamedResponse response = + await request.send().timeout(Duration(milliseconds: connectionTimeout)); if (response.statusCode == 200) { final String body = await response.stream.bytesToString(); diff --git a/pubspec.lock b/pubspec.lock index 09dcc75..2386638 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -101,10 +101,10 @@ packages: dependency: "direct main" description: name: http - sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" + sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139 url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.2" http_multi_server: dependency: transitive description: @@ -157,10 +157,10 @@ packages: dependency: "direct main" description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" mime: dependency: transitive description: @@ -345,6 +345,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa + url: "https://pub.dev" + source: hosted + version: "0.4.0" web_socket_channel: dependency: transitive description: @@ -370,4 +378,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0 <4.0.0" + dart: ">=3.2.0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 245ac59..5dedf2a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: battle_net description: Dart wrapper client for Battle.Net API https://develop.battle.net/documentation -version: 0.1.3+1 +version: 0.1.3+2 repository: https://github.com/vmpay/battle_net_dart issue_tracker: https://github.com/vmpay/battle_net_dart/issues @@ -8,9 +8,9 @@ environment: sdk: '>=3.1.0 <4.0.0' dependencies: - http: ^1.1.0 - meta: ^1.9.1 - collection: ^1.17.2 + http: ^1.1.2 + meta: ^1.10.0 + collection: ^1.18.0 dev_dependencies: test: ^1.22.2 \ No newline at end of file diff --git a/test/integration/get_connected_realm_search_integration_test.dart b/test/integration/get_connected_realm_search_integration_test.dart index 2ec6c59..ed0e0d8 100644 --- a/test/integration/get_connected_realm_search_integration_test.dart +++ b/test/integration/get_connected_realm_search_integration_test.dart @@ -160,7 +160,7 @@ void main() { realmsIsTournament: false, )); expect(result.page, 1); - expect(result.results.first.data.id, 4474); + expect(result.results.first.data.id, 4467); }); test('get connected realm search eu', () async { @@ -252,7 +252,7 @@ void main() { realmsIsTournament: false, )); expect(result.page, 1); - expect(result.results.first.data.id, 4485); + expect(result.results.first.data.id, 4488); }); test('get connected realm tw', () async {