1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 22:39:22 +00:00

Lock device awake during calls

This commit is contained in:
Pierre HUBERT 2020-04-23 17:37:12 +02:00
parent 0ebccf1075
commit 7768e36c62
4 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import 'package:comunic/models/conversation.dart';
import 'package:comunic/ui/routes/main_route.dart'; import 'package:comunic/ui/routes/main_route.dart';
import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/device_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart'; import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -147,6 +148,9 @@ class _CallScreenState extends SafeState<CallScreen> {
await this._memberReady(peer.userID); await this._memberReady(peer.userID);
setState(() {}); setState(() {});
// Lock device await
await setWakeLock(true);
} catch (e, stack) { } catch (e, stack) {
print("Could not initialize call! $e\n$stack"); print("Could not initialize call! $e\n$stack");
setState(() => _error = true); setState(() => _error = true);
@ -156,6 +160,8 @@ class _CallScreenState extends SafeState<CallScreen> {
/// Do clean up operations when call screen is destroyed /// Do clean up operations when call screen is destroyed
void _endCall() async { void _endCall() async {
try { try {
await setWakeLock(false);
// Close all ready members // Close all ready members
for (final member in _membersList.readyPeers) for (final member in _membersList.readyPeers)
await _removeMember(member.userID); await _removeMember(member.userID);

View File

@ -0,0 +1,9 @@
import 'package:wakelock/wakelock.dart';
/// Device utilities
///
/// @author Pierre Hubert
/// Interface for requesting device wake locking
Future<void> setWakeLock(bool enabled) async =>
await Wakelock.toggle(on: enabled);

View File

@ -455,6 +455,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.0.8"
wakelock:
dependency: "direct main"
description:
name: wakelock
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4+1"
web_socket_channel: web_socket_channel:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -78,6 +78,9 @@ dependencies:
# WebRTC calls # WebRTC calls
flutter_webrtc: ^0.2.7 flutter_webrtc: ^0.2.7
# Prevent phone from auto-locking during calls
wakelock: ^0.1.4+1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter