✨ Call wakelock
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
|||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
import 'package:island/pods/network.dart';
|
import 'package:island/pods/network.dart';
|
||||||
import 'package:island/models/chat.dart';
|
import 'package:island/models/chat.dart';
|
||||||
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||||
|
|
||||||
part 'call.g.dart';
|
part 'call.g.dart';
|
||||||
part 'call.freezed.dart';
|
part 'call.freezed.dart';
|
||||||
@@ -277,14 +278,27 @@ class CallNotifier extends _$CallNotifier {
|
|||||||
|
|
||||||
// Listen for connection updates
|
// Listen for connection updates
|
||||||
_room!.addListener(() {
|
_room!.addListener(() {
|
||||||
|
final wasConnected = state.isConnected;
|
||||||
|
final isNowConnected =
|
||||||
|
_room!.connectionState == ConnectionState.connected;
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
isConnected: _room!.connectionState == ConnectionState.connected,
|
isConnected: isNowConnected,
|
||||||
isMicrophoneEnabled: _localParticipant!.isMicrophoneEnabled(),
|
isMicrophoneEnabled: _localParticipant!.isMicrophoneEnabled(),
|
||||||
isCameraEnabled: _localParticipant!.isCameraEnabled(),
|
isCameraEnabled: _localParticipant!.isCameraEnabled(),
|
||||||
isScreenSharing: _localParticipant!.isScreenShareEnabled(),
|
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);
|
state = state.copyWith(isConnected: true);
|
||||||
|
// Enable wakelock when call connects
|
||||||
|
WakelockPlus.enable();
|
||||||
} else {
|
} else {
|
||||||
state = state.copyWith(error: 'Failed to join room');
|
state = state.copyWith(error: 'Failed to join room');
|
||||||
}
|
}
|
||||||
@@ -344,6 +358,8 @@ class CallNotifier extends _$CallNotifier {
|
|||||||
isCameraEnabled: false,
|
isCameraEnabled: false,
|
||||||
isScreenSharing: false,
|
isScreenSharing: false,
|
||||||
);
|
);
|
||||||
|
// Disable wakelock when call disconnects
|
||||||
|
WakelockPlus.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,5 +397,7 @@ class CallNotifier extends _$CallNotifier {
|
|||||||
_durationTimer?.cancel();
|
_durationTimer?.cancel();
|
||||||
_roomId = null;
|
_roomId = null;
|
||||||
participantsVolumes = {};
|
participantsVolumes = {};
|
||||||
|
// Disable wakelock when disposing
|
||||||
|
WakelockPlus.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2677,7 +2677,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.4.0"
|
version: "3.4.0"
|
||||||
wakelock_plus:
|
wakelock_plus:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: wakelock_plus
|
name: wakelock_plus
|
||||||
sha256: a474e314c3e8fb5adef1f9ae2d247e57467ad557fa7483a2b895bc1b421c5678
|
sha256: a474e314c3e8fb5adef1f9ae2d247e57467ad557fa7483a2b895bc1b421c5678
|
||||||
|
@@ -141,6 +141,7 @@ dependencies:
|
|||||||
tray_manager: ^0.5.1
|
tray_manager: ^0.5.1
|
||||||
flutter_webrtc: ^1.1.0
|
flutter_webrtc: ^1.1.0
|
||||||
flutter_local_notifications: ^19.4.1
|
flutter_local_notifications: ^19.4.1
|
||||||
|
wakelock_plus: ^1.3.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user