Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/blocs/call_view_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CallViewBloc extends Bloc<CallEvent, CallState> {
username: home.username ?? "",
password: home.password ?? "",
);
this.client = client;
} on mqtt.NoConnectionException catch (exception) {
emit(CallCancelState(exception.toString()));
return;
Expand Down Expand Up @@ -197,11 +198,9 @@ class CallViewBloc extends Bloc<CallEvent, CallState> {
await rtcclient?.dispose();
rtcclient = null;

client?.publish(
await client?.publish(
path.normalize("./${home.uri.path}/rtc/connections/close/$uuid"),
jsonEncode(
Request("GET", ""),
),
Request("GET", "").toJsonString(),
);
candidateSub?.cancel();
candidateSub = null;
Expand Down
10 changes: 1 addition & 9 deletions lib/blocs/home_add_view_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,10 @@ class HomeAddViewBloc extends Bloc<HomeAddEvent, HomeAddState> {
"Please enter a channel prefix within format 'com.dieklingel/main/prefix/'";
}

String? signError;
RegExp signRegex = RegExp(
r'^[A-Za-z]+$',
);
if (!signRegex.hasMatch(event.sign)) {
signError = "Please enter a sign within the format 'mysign'";
}

HomeAddFormErrorState errorState = HomeAddFormErrorState(
nameError: nameError,
serverError: serverError,
channelError: channelError,
signError: signError,
);
if (errorState.hasError) {
emit(errorState);
Expand All @@ -71,6 +62,7 @@ class HomeAddViewBloc extends Bloc<HomeAddEvent, HomeAddState> {
home.uri = uri;
home.username = event.username;
home.password = event.password;
home.passcode = event.passcode;

emit(HomeAddLoadingState());
final client = MqttClient(home.uri);
Expand Down
31 changes: 31 additions & 0 deletions lib/blocs/home_view_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import 'dart:async';

import 'package:dieklingel_app/models/hive_home.dart';
import 'package:dieklingel_app/models/request.dart';
import 'package:dieklingel_app/repositories/home_repository.dart';
import 'package:dieklingel_app/states/home_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mqtt/mqtt.dart';
import 'package:path/path.dart' as path;

class HomeViewBloc extends Bloc<HomeEvent, HomeState> {
final HomeRepository homeRepository;

HomeViewBloc(this.homeRepository) : super(HomeState()) {
on<HomeSelected>(_onSelected);
on<HomeRefresh>(_onRefresh);
on<HomeUnlock>(_onUnlock);

add(HomeRefresh());
}
Expand Down Expand Up @@ -39,4 +43,31 @@ class HomeViewBloc extends Bloc<HomeEvent, HomeState> {
);
}
}

Future<void> _onUnlock(HomeUnlock event, Emitter<HomeState> emit) async {
HiveHome? home = homeRepository.selected;
if (home == null) {
return;
}

MqttClient client = MqttClient(home.uri);
try {
await client.connect(
username: home.username ?? "",
password: home.password ?? "",
);
} catch (e) {
print("error ${e.toString()}");
return;
}

await client.publish(
path.normalize("./${home.uri.path}/actions/execute"),
Request.withJsonBody("GET", {
"pattern": "unlock",
"environment": {
"PASSCODE": home.passcode,
}
}).toJsonString());
}
}
13 changes: 10 additions & 3 deletions lib/models/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ class Home {
Uri uri;
String? username;
String? password;
String? passcode;

Home({
required this.name,
required this.uri,
this.username,
this.password,
this.passcode,
});

factory Home.fromMap(Map<String, dynamic> map) {
Expand All @@ -24,6 +26,7 @@ class Home {
uri: Uri.parse(map["uri"]),
username: map["username"],
password: map["password"],
passcode: map["passcode"],
);
}

Expand All @@ -33,6 +36,7 @@ class Home {
"uri": uri.toString(),
"username": username,
"password": password,
"passcode": passcode,
};
}

Expand All @@ -45,12 +49,14 @@ class Home {
Uri? uri,
String? username,
String? password,
String? passcode,
}) =>
Home(
name: name ?? this.name,
uri: uri ?? this.uri,
username: username ?? this.username,
password: this.password,
password: password ?? this.password,
passcode: passcode ?? this.passcode,
);

@override
Expand All @@ -61,11 +67,12 @@ class Home {
return name == other.name &&
uri == other.uri &&
username == other.username &&
password == other.password;
password == other.password &&
passcode == other.passcode;
}

@override
int get hashCode => Object.hash(name, uri, username, password);
int get hashCode => Object.hash(name, uri, username, password, passcode);

@override
String toString() {
Expand Down
11 changes: 5 additions & 6 deletions lib/states/home_add_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class HomeAddInitialState extends HomeAddState {
final String password;
final String channel;
final String sign;
final String passcode;

HomeAddInitialState({
required this.name,
Expand All @@ -17,6 +18,7 @@ class HomeAddInitialState extends HomeAddState {
required this.password,
required this.channel,
required this.sign,
required this.passcode,
});
}

Expand All @@ -32,20 +34,15 @@ class HomeAddFormErrorState extends HomeAddState {
final String? nameError;
final String? serverError;
final String? channelError;
final String? signError;

bool get hasError {
return nameError != null ||
serverError != null ||
channelError != null ||
signError != null;
return nameError != null || serverError != null || channelError != null;
}

HomeAddFormErrorState({
this.nameError,
this.serverError,
this.channelError,
this.signError,
});
}

Expand Down Expand Up @@ -109,6 +106,7 @@ class HomeAddSubmit extends HomeAddEvent {
final String password;
final String channel;
final String sign;
final String passcode;

HomeAddSubmit({
required this.name,
Expand All @@ -117,6 +115,7 @@ class HomeAddSubmit extends HomeAddEvent {
required this.password,
required this.channel,
required this.sign,
required this.passcode,
this.home,
});
}
2 changes: 2 additions & 0 deletions lib/states/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ class HomeSelected extends HomeEvent {
}

class HomeRefresh extends HomeEvent {}

class HomeUnlock extends HomeEvent {}
6 changes: 5 additions & 1 deletion lib/utils/media_ressource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class MediaRessource {
'audio': audio,
'video': video,
};
_stream = await navigator.mediaDevices.getUserMedia(constraints);
try {
_stream = await navigator.mediaDevices.getUserMedia(constraints);
} catch (e) {
// TODO: noting stream is empty
}
return _stream;
}

Expand Down
25 changes: 23 additions & 2 deletions lib/views/call_view.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:dieklingel_app/blocs/call_view_bloc.dart';
import 'package:dieklingel_app/blocs/home_view_bloc.dart';
import 'package:dieklingel_app/components/icon_builder.dart';
import 'package:dieklingel_app/components/map_builder.dart';
import 'package:dieklingel_app/states/call_state.dart';
import 'package:dieklingel_app/states/home_state.dart';
import 'package:dieklingel_app/utils/microphone_state.dart';
import 'package:dieklingel_app/utils/speaker_state.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -127,13 +129,32 @@ class _Toolbar extends StatelessWidget {
}
: null,
),
const _ToolbarButton(
icon: Icon(
_ToolbarButton(
icon: const Icon(
CupertinoIcons.lock_fill,
color: Colors.white,
size: 30,
),
color: Colors.amber,
onPressed: () {
context.read<HomeViewBloc>().add(HomeUnlock());
showCupertinoDialog(
context: context,
builder: (BuildContext context) {
Future.delayed(const Duration(milliseconds: 600), () {
Navigator.of(context).pop();
});

return Center(
child: Icon(
CupertinoIcons.lock_open_fill,
size: 150,
color: Colors.green.shade400,
),
);
},
);
},
),
];
}
Expand Down
16 changes: 12 additions & 4 deletions lib/views/home_add_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _HomeAddView extends State<HomeAddView> {
: path.normalize("./${widget.home!.uri.path}"),
);
late final _sign = TextEditingController(text: widget.home?.uri.fragment);
late final _passcode = TextEditingController(text: widget.home?.passcode);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -81,6 +82,7 @@ class _HomeAddView extends State<HomeAddView> {
password: _password.text,
channel: _channel.text,
sign: _sign.text,
passcode: _passcode.text,
),
);
},
Expand Down Expand Up @@ -140,13 +142,19 @@ class _HomeAddView extends State<HomeAddView> {
),
CupertinoTextFormFieldRow(
prefix: const Text("Sign"),
validator: (value) => state is HomeAddFormErrorState
? state.signError
: null,
autovalidateMode: AutovalidateMode.always,
controller: _sign,
)
],
),
CupertinoFormSection.insetGrouped(
header: const Text("Doorunit"),
children: [
CupertinoTextFormFieldRow(
prefix: const Text("Passcode"),
obscureText: true,
controller: _passcode,
),
],
)
],
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.2+1
version: 1.2.3+1

environment:
sdk: ">=2.18.6 <3.7.11"
Expand Down