Add wake lock and device keepalive for reliable mobile calls
Prevents screen sleep during calls and auto-reconnects the Twilio device after app backgrounding. JS handles Screen Wake Lock API and 30s keepalive polling; Flutter coordinates via WakelockPlus and synthetic visibilitychange events on app resume. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import 'package:webview_flutter_android/webview_flutter_android.dart';
|
||||
import '../services/push_notification_service.dart';
|
||||
@@ -52,10 +53,27 @@ class _PhoneScreenState extends State<PhoneScreen> with WidgetsBindingObserver {
|
||||
}
|
||||
_initWebView();
|
||||
_initPush();
|
||||
WakelockPlus.enable();
|
||||
debugPrint('TWP: Wake lock enabled');
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
debugPrint('TWP: App resumed — re-enabling wake lock');
|
||||
WakelockPlus.enable();
|
||||
// Dispatch synthetic visibilitychange to trigger JS-side recovery
|
||||
_controller.runJavaScript(
|
||||
'document.dispatchEvent(new Event("visibilitychange"));'
|
||||
'Object.defineProperty(document, "hidden", {value: false, configurable: true});',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WakelockPlus.disable();
|
||||
debugPrint('TWP: Wake lock disabled');
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user