From 03b9b639043db2f5b397373fe1205093f42404bb Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 29 Sep 2024 15:34:53 -0400 Subject: [PATCH] Connect after handlers have been setup Note that everything is broken now. just_audio is throwing an exception. --- lib/controller/stillbox.dart | 16 +++++++---- lib/views/login.dart | 1 - lib/views/radio.dart | 18 ++++++++++++- pubspec.lock | 52 ++++++++++++++++++------------------ pubspec.yaml | 8 +++--- 5 files changed, 58 insertions(+), 37 deletions(-) diff --git a/lib/controller/stillbox.dart b/lib/controller/stillbox.dart index 4029bc9..9111270 100644 --- a/lib/controller/stillbox.dart +++ b/lib/controller/stillbox.dart @@ -85,12 +85,12 @@ class Stillbox extends ChangeNotifier { if (connected == true) { return; } + channel.stream.listen((event) => _handleData(event), + onDone: () { + connected = false; + }, + onError: (error) => _handleError(error)); channel.connect(_wsUri); - channel.stream.listen((event) => _handleData(event), onDone: () { - connected = false; - }, onError: (error) { - print(error); - }); connected = true; tgCache = TalkgroupCache(channel); notifyListeners(); @@ -115,6 +115,12 @@ class Stillbox extends ChangeNotifier { callQStream.add(1); } + void _handleError(dynamic error) { + connected = false; + print(error); + callStream.addError(error); + } + void _handleData(dynamic event) { final msg = Message.fromBuffer(event); switch (msg.whichToClientMessage()) { diff --git a/lib/views/login.dart b/lib/views/login.dart index 9f51c07..7495cea 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -98,7 +98,6 @@ class _LoginState extends State { uriController.text, userController.text, passwordController.text); - print("result is $result"); if (context.mounted && result == true) { Navigator.pushReplacement( context, diff --git a/lib/views/radio.dart b/lib/views/radio.dart index 622d8e4..c321cbe 100644 --- a/lib/views/radio.dart +++ b/lib/views/radio.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:just_audio/just_audio.dart'; import '../../views/lcd.dart'; import '../../views/keypad.dart'; +import '../../views/login.dart'; import '../controller/stillbox.dart'; import 'play.dart'; @@ -53,8 +54,23 @@ class _MainRadioState extends State { _callLoop(sb); } + void _handleSocketError(dynamic error) { + Navigator.pushReplacement( + context, + PageRouteBuilder( + pageBuilder: (context, animation, secondaryAnimation) => const Login(), + transitionsBuilder: (context, animation, secondaryAnimation, child) { + return child; + }, + transitionDuration: const Duration(milliseconds: 0), + ), + ); + } + void _callLoop(Stillbox sb) async { - await for (final call in sb.callStream.stream) { + var streamWithoutErrors = + sb.callStream.stream.handleError((error) => _handleSocketError(error)); + await for (final call in streamWithoutErrors) { lcdOn(); setState(() { _call = call; diff --git a/pubspec.lock b/pubspec.lock index 8f7ca63..a04f270 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: transitive description: name: crypto - sha256: "1dceb0cf05cb63a7852c11560060e53ec2f182079a16ced6f4395c5b0875baf8" + sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27 url: "https://pub.dev" source: hosted - version: "3.0.4" + version: "3.0.5" cupertino_icons: dependency: "direct main" description: @@ -106,10 +106,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c" + sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.0.0" flutter_secure_storage: dependency: "direct main" description: @@ -220,10 +220,10 @@ packages: dependency: "direct main" description: name: just_audio - sha256: ee50602364ba83fa6308f5512dd560c713ec3e1f2bc75f0db43618f0d82ef71a + sha256: b41646a8241688f1d99c2e69c4da2bb26aa4b3a99795f6ff205c2a165e033fda url: "https://pub.dev" source: hosted - version: "0.9.39" + version: "0.9.41" just_audio_media_kit: dependency: "direct main" description: @@ -244,10 +244,10 @@ packages: dependency: transitive description: name: just_audio_web - sha256: "0edb481ad4aa1ff38f8c40f1a3576013c3420bf6669b686fe661627d49bc606c" + sha256: "9a98035b8b24b40749507687520ec5ab404e291d2b0937823ff45d92cb18d448" url: "https://pub.dev" source: hosted - version: "0.4.11" + version: "0.4.13" leak_tracker: dependency: transitive description: @@ -276,10 +276,10 @@ packages: dependency: transitive description: name: lints - sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235" + sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "5.0.0" logging: dependency: transitive description: @@ -308,10 +308,10 @@ packages: dependency: transitive description: name: media_kit - sha256: "3289062540e3b8b9746e5c50d95bd78a9289826b7227e253dff806d002b9e67a" + sha256: "1f1deee148533d75129a6f38251ff8388e33ee05fc2d20a6a80e57d6051b7b62" url: "https://pub.dev" source: hosted - version: "1.1.10+1" + version: "1.1.11" media_kit_libs_android_audio: dependency: transitive description: @@ -324,10 +324,10 @@ packages: dependency: "direct main" description: name: media_kit_libs_audio - sha256: f3f91df69848005363b3ae0ef7971a90edbd80a9365195684ef26c9a6ac8833f + sha256: be40e17c4cb7bd4e14114dce24a36e645f2ac5989dda543deaba2e7873901ba0 url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" media_kit_libs_ios_audio: dependency: transitive description: @@ -364,10 +364,10 @@ packages: dependency: "direct main" description: name: media_kit_native_event_loop - sha256: a605cf185499d14d58935b8784955a92a4bf0ff4e19a23de3d17a9106303930e + sha256: "7d82e3b3e9ded5c35c3146c5ba1da3118d1dd8ac3435bac7f29f458181471b40" url: "https://pub.dev" source: hosted - version: "1.0.8" + version: "1.0.9" meta: dependency: transitive description: @@ -553,10 +553,10 @@ packages: dependency: transitive description: name: synchronized - sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255 + sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225" url: "https://pub.dev" source: hosted - version: "3.2.0" + version: "3.3.0+3" term_glyph: dependency: transitive description: @@ -601,10 +601,10 @@ packages: dependency: transitive description: name: uuid - sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" + sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff url: "https://pub.dev" source: hosted - version: "4.4.2" + version: "4.5.1" vector_math: dependency: transitive description: @@ -625,10 +625,10 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.1.0" web_socket: dependency: transitive description: @@ -649,18 +649,18 @@ packages: dependency: transitive description: name: win32 - sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a" + sha256: "4d45dc9069dba4619dc0ebd93c7cec5e66d8482cb625a370ac806dcc8165f2ec" url: "https://pub.dev" source: hosted - version: "5.5.4" + version: "5.5.5" xdg_directories: dependency: transitive description: name: xdg_directories - sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.1.0" xml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9cad697..c9c515f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,12 +42,12 @@ dependencies: provider: ^6.1.2 flutter_secure_storage: ^9.2.2 http: ^1.2.2 - just_audio: ^0.9.37 + just_audio: ^0.9.41 just_audio_media_kit: ^2.0.5 - media_kit_libs_audio: ^1.0.4 + media_kit_libs_audio: ^1.0.5 patch_package: ^0.0.8 media_kit_libs_linux: ^1.1.3 - media_kit_native_event_loop: ^1.0.8 + media_kit_native_event_loop: ^1.0.9 media_kit_libs_windows_audio: ^1.0.9 intl: ^0.19.0 @@ -60,7 +60,7 @@ dev_dependencies: # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. - flutter_lints: ^4.0.0 + flutter_lints: ^5.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec