This commit is contained in:
Daniel Ponte 2024-08-14 08:28:26 -04:00
parent 0d150d73d8
commit c776d37765
9 changed files with 39 additions and 31 deletions

View file

@ -6,7 +6,7 @@ plugins {
}
android {
namespace = "com.example.calls"
namespace = "me.dynatron.calls"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
@ -21,7 +21,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.calls"
applicationId = "me.dynatron.calls"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion

View file

@ -1,4 +1,4 @@
package com.example.calls
package me.dynatron.calls
import io.flutter.embedding.android.FlutterActivity

View file

@ -369,7 +369,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
@ -385,7 +385,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -402,7 +402,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
@ -417,7 +417,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
@ -549,7 +549,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -572,7 +572,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;

View file

@ -7,6 +7,8 @@ class Player {
final player = AudioPlayer();
Player();
Future<void> play(Call call) {
return player.play(BytesSource(Uint8List.fromList(call.audio)));
print('play!');
return Future.delayed(const Duration(seconds: 1));
// return player.play(BytesSource(Uint8List.fromList(call.audio)));
}
}

View file

@ -8,7 +8,7 @@ import 'play.dart';
class BadAuthException implements Exception {}
class Stillbox extends ChangeNotifier {
final storage = FlutterSecureStorage();
final storage = const FlutterSecureStorage();
Player player = Player();
late IOWebSocketChannel channel;
bool connected = false;
@ -40,7 +40,8 @@ class Stillbox extends ChangeNotifier {
}
void setUris() {
if (baseUri != null && (baseUri!.scheme == 'http' || baseUri!.scheme == 'https')) {
if (baseUri != null &&
(baseUri!.scheme == 'http' || baseUri!.scheme == 'https')) {
String socketUrl;
final port = (baseUri!.hasPort ? ':${baseUri!.port}' : '');
socketUrl =
@ -52,20 +53,20 @@ class Stillbox extends ChangeNotifier {
}
void updateCookie(http.Response response) {
String? rawCookie = response.headers['set-cookie'];
if (rawCookie != null) {
int index = rawCookie.indexOf(';');
headers['cookie'] =
(index == -1) ? rawCookie : rawCookie.substring(0, index);
}
}
String? rawCookie = response.headers['set-cookie'];
if (rawCookie != null) {
int index = rawCookie.indexOf(';');
headers['cookie'] =
(index == -1) ? rawCookie : rawCookie.substring(0, index);
}
}
Future<bool> doLogin(String uri, String username, String password) async {
if(baseUri == null) {
if (baseUri == null) {
baseUri = Uri.parse(uri);
setUris();
}
Uri loginUri = Uri.parse(baseUri!.toString() + '/login');
Uri loginUri = Uri.parse('${baseUri!}/login');
final form = <String, dynamic>{};
form['username'] = username;
form['password'] = password;
@ -73,9 +74,10 @@ class Stillbox extends ChangeNotifier {
loginUri,
body: form,
);
if(response.statusCode == 200) {
if (response.statusCode == 200) {
updateCookie(response);
await storage.write(key: 'token', value: headers['cookie']);
await storage.write(key: 'baseURL', value: uri);
await connect();
return true;
}
@ -83,7 +85,7 @@ class Stillbox extends ChangeNotifier {
}
Future<void> connect() async {
if (connected = true) {
if (connected == true) {
return;
}
channel = IOWebSocketChannel.connect(_wsUri, headers: headers);
@ -96,11 +98,15 @@ class Stillbox extends ChangeNotifier {
notifyListeners();
}
Future<void> setBearer() async {
Future<void> getBearer() async {
String? storedToken = await storage.read(key: 'token');
if (storedToken == null) {
String? storedUri = await storage.read(key: 'baseURL');
if (storedToken == null || storedUri == null) {
throw (BadAuthException);
}
headers['cookie'] = storedToken;
baseUri = Uri.parse(storedUri);
setUris();
}
void _handleData(dynamic event) {

View file

@ -51,7 +51,7 @@ class CallsHomeState extends State<CallsHome> {
// Ensure the navigation happens in the context of this widget's subtree
try {
final sb = Provider.of<Stillbox>(context, listen: false);
await sb.setBearer();
await sb.getBearer();
await sb.connect();
} catch (e) {
if (mounted) {

View file

@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "calls")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.calls")
set(APPLICATION_ID "me.dynatron.calls")
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.

View file

@ -478,7 +478,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calls.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calls";
@ -493,7 +493,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calls.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calls";
@ -508,7 +508,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calls.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calls";

View file

@ -8,7 +8,7 @@
PRODUCT_NAME = calls
// The application's bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = com.example.calls
PRODUCT_BUNDLE_IDENTIFIER = me.dynatron.calls
// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved.