Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
package io.livekit.example

import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
}
class MainActivity : FlutterActivity() {

private val CHANNEL = "livekit_incall"

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)

MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
CHANNEL
).setMethodCallHandler { call, result ->
when (call.method) {
"enableInCall" -> {
setInCallScreenFlags()
result.success(null)
}
"disableInCall" -> {
clearInCallScreenFlags()
result.success(null)
}
else -> result.notImplemented()
}
}
}

private fun setInCallScreenFlags() {
val window = window

// Keep screen on during call
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

private fun clearInCallScreenFlags() {
val window = window

// Remove keep screen on
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}
19 changes: 19 additions & 0 deletions example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:livekit_client/livekit_client.dart';

import '../exts.dart';
Expand Down Expand Up @@ -34,6 +35,11 @@ class _RoomPageState extends State<RoomPage> {
@override
void initState() {
super.initState();

if (lkPlatformIs(PlatformType.android)) {
unawaited(enableInCallFlags());
}

// add callback for a `RoomEvent` as opposed to a `ParticipantEvent`
widget.room.addListener(_onRoomDidUpdate);
// add callbacks for finer grained events
Expand Down Expand Up @@ -63,6 +69,9 @@ class _RoomPageState extends State<RoomPage> {
widget.room.removeListener(_onRoomDidUpdate);
unawaited(_disposeRoomAsync());
onWindowShouldClose = null;
if (lkPlatformIs(PlatformType.android)) {
unawaited(disableInCallFlags());
}
super.dispose();
}

Expand All @@ -71,6 +80,16 @@ class _RoomPageState extends State<RoomPage> {
await widget.room.dispose();
}

static const platform = MethodChannel('livekit_incall');

Future<void> enableInCallFlags() async {
await platform.invokeMethod('enableInCall');
}

Future<void> disableInCallFlags() async {
await platform.invokeMethod('disableInCall');
}

/// for more information, see [event types](https://docs.livekit.io/client/events/#events)
void _setUpListeners() => _listener
..on<RoomDisconnectedEvent>((event) async {
Expand Down
Loading