mirror of
https://github.com/amigan/calls.git
synced 2025-01-31 05:22:37 -05:00
big wip
This commit is contained in:
parent
5af1b90ccc
commit
db99eeb43a
11 changed files with 108 additions and 17 deletions
|
@ -1,6 +1,12 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import '../pb/stillbox.pb.dart';
|
||||
|
||||
class Player {
|
||||
final player = AudioPlayer();
|
||||
Player();
|
||||
Future<void> play(Call call) {
|
||||
return player.play(BytesSource(Uint8List.fromList(call.audio)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import '../pb/stillbox.pb.dart';
|
||||
import 'play.dart';
|
||||
|
||||
class BadAuthException implements Exception {}
|
||||
|
||||
class Stillbox extends ChangeNotifier {
|
||||
final storage = FlutterSecureStorage();
|
||||
Player player = Player();
|
||||
late IOWebSocketChannel channel;
|
||||
bool connected = false;
|
||||
|
@ -11,6 +15,8 @@ class Stillbox extends ChangeNotifier {
|
|||
LiveState _state = LiveState.LS_LIVE;
|
||||
Filter? currentFilter;
|
||||
Call? _currentCall;
|
||||
Map<String, String> headers = {};
|
||||
|
||||
set state(LiveState newState) {
|
||||
channel.sink.add(Live(state: newState, filter: currentFilter));
|
||||
_state = newState;
|
||||
|
@ -38,8 +44,9 @@ class Stillbox extends ChangeNotifier {
|
|||
_wsUri = Uri.parse(socketUrl);
|
||||
}
|
||||
|
||||
void connect() {
|
||||
channel = IOWebSocketChannel.connect(_wsUri);
|
||||
Future<void> connect() async {
|
||||
await setBearer();
|
||||
channel = IOWebSocketChannel.connect(_wsUri, headers: headers);
|
||||
channel.stream.listen((event) => _handleData(event), onDone: () {
|
||||
connected = false;
|
||||
}, onError: (error) {
|
||||
|
@ -49,10 +56,18 @@ class Stillbox extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> setBearer() async {
|
||||
String? storedToken = await storage.read(key: 'token');
|
||||
if (storedToken == null) {
|
||||
throw (BadAuthException);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleData(dynamic event) {
|
||||
final msg = Message.fromBuffer(event);
|
||||
switch (msg.whichToClientMessage()) {
|
||||
case Message_ToClientMessage.call:
|
||||
player.play(msg.call);
|
||||
case Message_ToClientMessage.notification:
|
||||
case Message_ToClientMessage.popup:
|
||||
case Message_ToClientMessage.error:
|
||||
|
|
|
@ -48,16 +48,18 @@ class CallsHomeState extends State<CallsHome> {
|
|||
}
|
||||
|
||||
Future<void> loadData() async {
|
||||
await Future.delayed(const Duration(seconds: 1)); // Simulate some delay
|
||||
|
||||
// Ensure the navigation happens in the context of this widget's subtree
|
||||
try {
|
||||
await Provider.of<Stillbox>(context, listen: false).connect();
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation, secondaryAnimation) =>
|
||||
const Login(),
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||
transitionsBuilder:
|
||||
(context, animation, secondaryAnimation, child) {
|
||||
return child;
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 0),
|
||||
|
@ -65,6 +67,7 @@ class CallsHomeState extends State<CallsHome> {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import '../../views/lcd.dart';
|
||||
import '../../views/keypad.dart';
|
||||
import '../controller/ws.dart';
|
||||
|
||||
class MainRadio extends StatefulWidget {
|
||||
const MainRadio({super.key, required this.title});
|
||||
|
|
|
@ -7,9 +7,13 @@
|
|||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <audioplayers_linux/audioplayers_linux_plugin.h>
|
||||
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
|
||||
|
||||
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);
|
||||
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
|
||||
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
audioplayers_linux
|
||||
flutter_secure_storage_linux
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
|
@ -6,9 +6,11 @@ import FlutterMacOS
|
|||
import Foundation
|
||||
|
||||
import audioplayers_darwin
|
||||
import flutter_secure_storage_macos
|
||||
import path_provider_foundation
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
|
||||
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
}
|
||||
|
|
56
pubspec.lock
56
pubspec.lock
|
@ -158,6 +158,54 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
flutter_secure_storage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_secure_storage
|
||||
sha256: "165164745e6afb5c0e3e3fcc72a012fb9e58496fb26ffb92cf22e16a821e85d0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "9.2.2"
|
||||
flutter_secure_storage_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_secure_storage_linux
|
||||
sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
flutter_secure_storage_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_secure_storage_macos
|
||||
sha256: "1693ab11121a5f925bbea0be725abfcfbbcf36c1e29e571f84a0c0f436147a81"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
flutter_secure_storage_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_secure_storage_platform_interface
|
||||
sha256: cf91ad32ce5adef6fba4d736a542baca9daf3beac4db2d04be350b87f69ac4a8
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
flutter_secure_storage_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_secure_storage_web
|
||||
sha256: f4ebff989b4f07b2656fb16b47852c0aab9fed9b4ec1c70103368337bc1886a9
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
flutter_secure_storage_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_secure_storage_windows
|
||||
sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
@ -477,6 +525,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.5.4"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -41,6 +41,7 @@ dependencies:
|
|||
web_socket_channel: ^3.0.1
|
||||
provider: ^6.1.2
|
||||
audioplayers: ^5.2.1
|
||||
flutter_secure_storage: ^9.2.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -7,8 +7,11 @@
|
|||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <audioplayers_windows/audioplayers_windows_plugin.h>
|
||||
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
AudioplayersWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
|
||||
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
audioplayers_windows
|
||||
flutter_secure_storage_windows
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
Loading…
Reference in a new issue