Skip to content

Commit

Permalink
Fix errors caused by window close handler for web. (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Dec 1, 2023
1 parent 0d015a2 commit 4012b53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_window_close/flutter_window_close.dart';
import 'package:livekit_client/livekit_client.dart';
import 'package:livekit_example/theme.dart';
import 'package:logging/logging.dart';
import 'package:intl/intl.dart';
Expand All @@ -16,10 +17,13 @@ void main() async {

WidgetsFlutterBinding.ensureInitialized();

FlutterWindowClose.setWindowShouldCloseHandler(() async {
await onWindowShouldClose?.call();
return true;
});
if (lkPlatformIsDesktop()) {
FlutterWindowClose.setWindowShouldCloseHandler(() async {
await onWindowShouldClose?.call();
return true;
});
}

runApp(const LiveKitExampleApp());
}

Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _RoomPageState extends State<RoomPage> {
Hardware.instance.setSpeakerphoneOn(true);
}

if (!lkPlatformIs(PlatformType.web) && !lkPlatformIsTest()) {
if (lkPlatformIsDesktop()) {
onWindowShouldClose = () async {
unawaited(widget.room.disconnect());
await _listener.waitFor<RoomDisconnectedEvent>(
Expand Down

0 comments on commit 4012b53

Please sign in to comment.