From 5af1b90ccca175566c3bfad397dbd7b14e08cee7 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 13 Aug 2024 20:04:37 -0400 Subject: [PATCH] WIP --- lib/controller/play.dart | 6 ++ lib/controller/{ws.dart => stillbox.dart} | 39 +++++-- lib/main.dart | 8 +- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 101 ++++++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 10 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 lib/controller/play.dart rename lib/controller/{ws.dart => stillbox.dart} (55%) diff --git a/lib/controller/play.dart b/lib/controller/play.dart new file mode 100644 index 0000000..bf2ac3e --- /dev/null +++ b/lib/controller/play.dart @@ -0,0 +1,6 @@ +import 'package:audioplayers/audioplayers.dart'; + +class Player { + final player = AudioPlayer(); + Player(); +} diff --git a/lib/controller/ws.dart b/lib/controller/stillbox.dart similarity index 55% rename from lib/controller/ws.dart rename to lib/controller/stillbox.dart index 8f7212f..d34deda 100644 --- a/lib/controller/ws.dart +++ b/lib/controller/stillbox.dart @@ -1,12 +1,33 @@ import 'package:flutter/material.dart'; import 'package:web_socket_channel/io.dart'; import '../pb/stillbox.pb.dart'; +import 'play.dart'; -class Client extends ChangeNotifier { - late Uri _wsUri; +class Stillbox extends ChangeNotifier { + Player player = Player(); late IOWebSocketChannel channel; + bool connected = false; + late Uri _wsUri; + LiveState _state = LiveState.LS_LIVE; + Filter? currentFilter; + Call? _currentCall; + set state(LiveState newState) { + channel.sink.add(Live(state: newState, filter: currentFilter)); + _state = newState; + notifyListeners(); + } - Client() { + LiveState get state { + return _state; + } + + Call? get currentCall => _currentCall; + set currentCall(Call? call) { + _currentCall = call; + notifyListeners(); + } + + Stillbox() { String socketUrl = 'ws://xenon:3050/ws'; Uri baseUri = Uri.base; if (baseUri.scheme == 'http' || baseUri.scheme == 'https') { @@ -17,13 +38,15 @@ class Client extends ChangeNotifier { _wsUri = Uri.parse(socketUrl); } - bool isConnected() { - return false; - } - void connect() { channel = IOWebSocketChannel.connect(_wsUri); - channel.stream.listen((event) => _handleData(event)); + channel.stream.listen((event) => _handleData(event), onDone: () { + connected = false; + }, onError: (error) { + print(error); + }); + connected = true; + notifyListeners(); } void _handleData(dynamic event) { diff --git a/lib/main.dart b/lib/main.dart index 3555d07..8402b08 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,11 +2,11 @@ import 'package:flutter/material.dart'; import 'views/radio.dart'; import 'package:provider/provider.dart'; import 'views/login.dart'; -import 'controller/ws.dart'; +import 'controller/stillbox.dart'; void main() { runApp(ChangeNotifierProvider( - create: (context) => Client(), + create: (context) => Stillbox(), child: const CallsApp(), )); } @@ -39,8 +39,6 @@ class CallsHome extends StatefulWidget { } class CallsHomeState extends State { - final c = Client(); - @override void initState() { super.initState(); @@ -72,4 +70,4 @@ class CallsHomeState extends State { Widget build(BuildContext context) { return const MainRadio(title: 'Stillbox'); } -} \ No newline at end of file +} diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..1830e5c 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin"); + audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..e9abb91 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + audioplayers_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index e777c67..a9f2f23 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,10 @@ import FlutterMacOS import Foundation +import audioplayers_darwin import path_provider_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 70fc4c9..4932418 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,62 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + audioplayers: + dependency: "direct main" + description: + name: audioplayers + sha256: c05c6147124cd63e725e861335a8b4d57300b80e6e92cea7c145c739223bbaef + url: "https://pub.dev" + source: hosted + version: "5.2.1" + audioplayers_android: + dependency: transitive + description: + name: audioplayers_android + sha256: b00e1a0e11365d88576320ec2d8c192bc21f1afb6c0e5995d1c57ae63156acb5 + url: "https://pub.dev" + source: hosted + version: "4.0.3" + audioplayers_darwin: + dependency: transitive + description: + name: audioplayers_darwin + sha256: "3034e99a6df8d101da0f5082dcca0a2a99db62ab1d4ddb3277bed3f6f81afe08" + url: "https://pub.dev" + source: hosted + version: "5.0.2" + audioplayers_linux: + dependency: transitive + description: + name: audioplayers_linux + sha256: "60787e73fefc4d2e0b9c02c69885402177e818e4e27ef087074cf27c02246c9e" + url: "https://pub.dev" + source: hosted + version: "3.1.0" + audioplayers_platform_interface: + dependency: transitive + description: + name: audioplayers_platform_interface + sha256: "365c547f1bb9e77d94dd1687903a668d8f7ac3409e48e6e6a3668a1ac2982adb" + url: "https://pub.dev" + source: hosted + version: "6.1.0" + audioplayers_web: + dependency: transitive + description: + name: audioplayers_web + sha256: "22cd0173e54d92bd9b2c80b1204eb1eb159ece87475ab58c9788a70ec43c2a62" + url: "https://pub.dev" + source: hosted + version: "4.1.0" + audioplayers_windows: + dependency: transitive + description: + name: audioplayers_windows + sha256: "9536812c9103563644ada2ef45ae523806b0745f7a78e89d1b5fb1951de90e1a" + url: "https://pub.dev" + source: hosted + version: "3.1.0" boolean_selector: dependency: transitive description: @@ -73,6 +129,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" fixnum: dependency: "direct main" description: @@ -99,6 +163,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" google_fonts: dependency: "direct main" description: @@ -123,6 +192,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" leak_tracker: dependency: transitive description: @@ -288,6 +365,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -312,6 +397,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.0" + synchronized: + dependency: transitive + description: + name: synchronized + sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + url: "https://pub.dev" + source: hosted + version: "3.1.0+1" term_glyph: dependency: transitive description: @@ -336,6 +429,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + uuid: + dependency: transitive + description: + name: uuid + sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" + url: "https://pub.dev" + source: hosted + version: "4.4.2" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 218163a..69dd879 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: protobuf: ^3.1.0 web_socket_channel: ^3.0.1 provider: ^6.1.2 + audioplayers: ^5.2.1 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..09e8e2c 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + AudioplayersWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..375535c 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + audioplayers_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST