diff --git a/lib/pods/call.dart b/lib/pods/call.dart index 650cf205..94f6508b 100644 --- a/lib/pods/call.dart +++ b/lib/pods/call.dart @@ -9,6 +9,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:island/pods/network.dart'; import 'package:island/models/chat.dart'; +import 'package:wakelock_plus/wakelock_plus.dart'; part 'call.g.dart'; part 'call.freezed.dart'; @@ -277,14 +278,27 @@ class CallNotifier extends _$CallNotifier { // Listen for connection updates _room!.addListener(() { + final wasConnected = state.isConnected; + final isNowConnected = + _room!.connectionState == ConnectionState.connected; state = state.copyWith( - isConnected: _room!.connectionState == ConnectionState.connected, + isConnected: isNowConnected, isMicrophoneEnabled: _localParticipant!.isMicrophoneEnabled(), isCameraEnabled: _localParticipant!.isCameraEnabled(), isScreenSharing: _localParticipant!.isScreenShareEnabled(), ); + // Enable wakelock when call connects + if (!wasConnected && isNowConnected) { + WakelockPlus.enable(); + } + // Disable wakelock when call disconnects + else if (wasConnected && !isNowConnected) { + WakelockPlus.disable(); + } }); state = state.copyWith(isConnected: true); + // Enable wakelock when call connects + WakelockPlus.enable(); } else { state = state.copyWith(error: 'Failed to join room'); } @@ -344,6 +358,8 @@ class CallNotifier extends _$CallNotifier { isCameraEnabled: false, isScreenSharing: false, ); + // Disable wakelock when call disconnects + WakelockPlus.disable(); } } @@ -381,5 +397,7 @@ class CallNotifier extends _$CallNotifier { _durationTimer?.cancel(); _roomId = null; participantsVolumes = {}; + // Disable wakelock when disposing + WakelockPlus.disable(); } } diff --git a/pubspec.lock b/pubspec.lock index 23f05fe6..134e48a1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -2677,7 +2677,7 @@ packages: source: hosted version: "3.4.0" wakelock_plus: - dependency: transitive + dependency: "direct main" description: name: wakelock_plus sha256: a474e314c3e8fb5adef1f9ae2d247e57467ad557fa7483a2b895bc1b421c5678 diff --git a/pubspec.yaml b/pubspec.yaml index d8b1f951..dbdf4ac8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -141,6 +141,7 @@ dependencies: tray_manager: ^0.5.1 flutter_webrtc: ^1.1.0 flutter_local_notifications: ^19.4.1 + wakelock_plus: ^1.3.2 dev_dependencies: flutter_test: