Call wakelock

This commit is contained in:
2025-09-07 01:11:40 +08:00
parent 28fda3d0c7
commit 9c75eafdb3
3 changed files with 21 additions and 2 deletions

View File

@@ -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();
}
}

View File

@@ -2677,7 +2677,7 @@ packages:
source: hosted
version: "3.4.0"
wakelock_plus:
dependency: transitive
dependency: "direct main"
description:
name: wakelock_plus
sha256: a474e314c3e8fb5adef1f9ae2d247e57467ad557fa7483a2b895bc1b421c5678

View File

@@ -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: