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 'package:audioplayers/audioplayers.dart';
|
||||||
|
import '../pb/stillbox.pb.dart';
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
final player = AudioPlayer();
|
final player = AudioPlayer();
|
||||||
Player();
|
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:flutter/material.dart';
|
||||||
import 'package:web_socket_channel/io.dart';
|
import 'package:web_socket_channel/io.dart';
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import '../pb/stillbox.pb.dart';
|
import '../pb/stillbox.pb.dart';
|
||||||
import 'play.dart';
|
import 'play.dart';
|
||||||
|
|
||||||
|
class BadAuthException implements Exception {}
|
||||||
|
|
||||||
class Stillbox extends ChangeNotifier {
|
class Stillbox extends ChangeNotifier {
|
||||||
|
final storage = FlutterSecureStorage();
|
||||||
Player player = Player();
|
Player player = Player();
|
||||||
late IOWebSocketChannel channel;
|
late IOWebSocketChannel channel;
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
@ -11,6 +15,8 @@ class Stillbox extends ChangeNotifier {
|
||||||
LiveState _state = LiveState.LS_LIVE;
|
LiveState _state = LiveState.LS_LIVE;
|
||||||
Filter? currentFilter;
|
Filter? currentFilter;
|
||||||
Call? _currentCall;
|
Call? _currentCall;
|
||||||
|
Map<String, String> headers = {};
|
||||||
|
|
||||||
set state(LiveState newState) {
|
set state(LiveState newState) {
|
||||||
channel.sink.add(Live(state: newState, filter: currentFilter));
|
channel.sink.add(Live(state: newState, filter: currentFilter));
|
||||||
_state = newState;
|
_state = newState;
|
||||||
|
@ -38,8 +44,9 @@ class Stillbox extends ChangeNotifier {
|
||||||
_wsUri = Uri.parse(socketUrl);
|
_wsUri = Uri.parse(socketUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connect() {
|
Future<void> connect() async {
|
||||||
channel = IOWebSocketChannel.connect(_wsUri);
|
await setBearer();
|
||||||
|
channel = IOWebSocketChannel.connect(_wsUri, headers: headers);
|
||||||
channel.stream.listen((event) => _handleData(event), onDone: () {
|
channel.stream.listen((event) => _handleData(event), onDone: () {
|
||||||
connected = false;
|
connected = false;
|
||||||
}, onError: (error) {
|
}, onError: (error) {
|
||||||
|
@ -49,10 +56,18 @@ class Stillbox extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setBearer() async {
|
||||||
|
String? storedToken = await storage.read(key: 'token');
|
||||||
|
if (storedToken == null) {
|
||||||
|
throw (BadAuthException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _handleData(dynamic event) {
|
void _handleData(dynamic event) {
|
||||||
final msg = Message.fromBuffer(event);
|
final msg = Message.fromBuffer(event);
|
||||||
switch (msg.whichToClientMessage()) {
|
switch (msg.whichToClientMessage()) {
|
||||||
case Message_ToClientMessage.call:
|
case Message_ToClientMessage.call:
|
||||||
|
player.play(msg.call);
|
||||||
case Message_ToClientMessage.notification:
|
case Message_ToClientMessage.notification:
|
||||||
case Message_ToClientMessage.popup:
|
case Message_ToClientMessage.popup:
|
||||||
case Message_ToClientMessage.error:
|
case Message_ToClientMessage.error:
|
||||||
|
|
|
@ -48,21 +48,24 @@ class CallsHomeState extends State<CallsHome> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadData() async {
|
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
|
// Ensure the navigation happens in the context of this widget's subtree
|
||||||
if (mounted) {
|
try {
|
||||||
Navigator.pushReplacement(
|
await Provider.of<Stillbox>(context, listen: false).connect();
|
||||||
context,
|
} catch (e) {
|
||||||
PageRouteBuilder(
|
if (mounted) {
|
||||||
pageBuilder: (context, animation, secondaryAnimation) =>
|
Navigator.pushReplacement(
|
||||||
const Login(),
|
context,
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
PageRouteBuilder(
|
||||||
return child;
|
pageBuilder: (context, animation, secondaryAnimation) =>
|
||||||
},
|
const Login(),
|
||||||
transitionDuration: const Duration(milliseconds: 0),
|
transitionsBuilder:
|
||||||
),
|
(context, animation, secondaryAnimation, child) {
|
||||||
);
|
return child;
|
||||||
|
},
|
||||||
|
transitionDuration: const Duration(milliseconds: 0),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../views/lcd.dart';
|
import '../../views/lcd.dart';
|
||||||
import '../../views/keypad.dart';
|
import '../../views/keypad.dart';
|
||||||
import '../controller/ws.dart';
|
|
||||||
|
|
||||||
class MainRadio extends StatefulWidget {
|
class MainRadio extends StatefulWidget {
|
||||||
const MainRadio({super.key, required this.title});
|
const MainRadio({super.key, required this.title});
|
||||||
|
|
|
@ -7,9 +7,13 @@
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <audioplayers_linux/audioplayers_linux_plugin.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) {
|
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||||
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
|
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
|
||||||
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
|
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
|
||||||
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
|
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
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
audioplayers_linux
|
audioplayers_linux
|
||||||
|
flutter_secure_storage_linux
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|
|
@ -6,9 +6,11 @@ import FlutterMacOS
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
import audioplayers_darwin
|
import audioplayers_darwin
|
||||||
|
import flutter_secure_storage_macos
|
||||||
import path_provider_foundation
|
import path_provider_foundation
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
|
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
|
||||||
|
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
|
||||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||||
}
|
}
|
||||||
|
|
56
pubspec.lock
56
pubspec.lock
|
@ -158,6 +158,54 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
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:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -477,6 +525,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.1"
|
version: "3.0.1"
|
||||||
|
win32:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32
|
||||||
|
sha256: "68d1e89a91ed61ad9c370f9f8b6effed9ae5e0ede22a270bdfa6daf79fc2290a"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.5.4"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -41,6 +41,7 @@ dependencies:
|
||||||
web_socket_channel: ^3.0.1
|
web_socket_channel: ^3.0.1
|
||||||
provider: ^6.1.2
|
provider: ^6.1.2
|
||||||
audioplayers: ^5.2.1
|
audioplayers: ^5.2.1
|
||||||
|
flutter_secure_storage: ^9.2.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
@ -7,8 +7,11 @@
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
#include <audioplayers_windows/audioplayers_windows_plugin.h>
|
#include <audioplayers_windows/audioplayers_windows_plugin.h>
|
||||||
|
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
AudioplayersWindowsPluginRegisterWithRegistrar(
|
AudioplayersWindowsPluginRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
|
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
|
||||||
|
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
audioplayers_windows
|
audioplayers_windows
|
||||||
|
flutter_secure_storage_windows
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|
Loading…
Reference in a new issue