fix: Disconnect from room before app closes. (#218)
* fix: Disconnect from room before app closes. * chore: add app state listener. * Remove unused import. * fix `flutter test`. * singleton.
This commit is contained in:
@@ -8,6 +8,7 @@ import Foundation
|
||||
import connectivity_plus_macos
|
||||
import device_info_plus_macos
|
||||
import flutter_webrtc
|
||||
import flutter_window_close
|
||||
import livekit_client
|
||||
import path_provider_macos
|
||||
import shared_preferences_macos
|
||||
@@ -16,6 +17,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
|
||||
FlutterWindowClosePlugin.register(with: registry.registrar(forPlugin: "FlutterWindowClosePlugin"))
|
||||
LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
|
||||
@@ -7,6 +7,8 @@ PODS:
|
||||
- flutter_webrtc (0.9.13):
|
||||
- FlutterMacOS
|
||||
- WebRTC-SDK (= 104.5112.06)
|
||||
- flutter_window_close (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- livekit_client (1.1.1):
|
||||
- FlutterMacOS
|
||||
@@ -22,6 +24,7 @@ DEPENDENCIES:
|
||||
- connectivity_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus_macos/macos`)
|
||||
- device_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos`)
|
||||
- flutter_webrtc (from `Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos`)
|
||||
- flutter_window_close (from `Flutter/ephemeral/.symlinks/plugins/flutter_window_close/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- livekit_client (from `Flutter/ephemeral/.symlinks/plugins/livekit_client/macos`)
|
||||
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
||||
@@ -39,6 +42,8 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/device_info_plus_macos/macos
|
||||
flutter_webrtc:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_webrtc/macos
|
||||
flutter_window_close:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_window_close/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
livekit_client:
|
||||
@@ -52,6 +57,7 @@ SPEC CHECKSUMS:
|
||||
connectivity_plus_macos: f6e86fd000e971d361e54b5afcadc8c8fa773308
|
||||
device_info_plus_macos: 1ad388a1ef433505c4038e7dd9605aadd1e2e9c7
|
||||
flutter_webrtc: 4bb537cadddcfb5e5b24c96cbd6ff56f064b8faf
|
||||
flutter_window_close: ee4a6b81ca6fafe93b7cba48b0a18976e3f48e39
|
||||
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
||||
livekit_client: b438747d15f01e3baaefa8036dd2feec5539387e
|
||||
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
|
||||
|
||||
+10
-3
@@ -226,6 +226,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.17"
|
||||
flutter_window_close:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_window_close
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
google_fonts:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -351,7 +358,7 @@ packages:
|
||||
name: path_provider_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.21"
|
||||
version: "2.0.22"
|
||||
path_provider_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -552,7 +559,7 @@ packages:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.6"
|
||||
version: "3.0.7"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -573,7 +580,7 @@ packages:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
version: "3.1.2"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
||||
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
|
||||
#include <flutter_window_close/flutter_window_close_plugin.h>
|
||||
#include <livekit_client/live_kit_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
@@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
||||
FlutterWebRTCPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterWebRTCPlugin"));
|
||||
FlutterWindowClosePluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterWindowClosePlugin"));
|
||||
LiveKitPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("LiveKitPlugin"));
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
connectivity_plus_windows
|
||||
flutter_webrtc
|
||||
flutter_window_close
|
||||
livekit_client
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:livekit_client/src/support/app_state.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../core/signal_client.dart';
|
||||
@@ -14,6 +17,7 @@ import '../participant/remote.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../proto/livekit_rtc.pb.dart' as lk_rtc;
|
||||
import '../support/disposable.dart';
|
||||
import '../support/platform.dart';
|
||||
import '../track/local/audio.dart';
|
||||
import '../track/local/video.dart';
|
||||
import '../track/track.dart';
|
||||
@@ -76,6 +80,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
//
|
||||
late EventsListener<SignalEvent> _signalListener;
|
||||
|
||||
StreamSubscription<String>? _appCloseSubscription;
|
||||
|
||||
Room({
|
||||
ConnectOptions connectOptions = const ConnectOptions(),
|
||||
RoomOptions roomOptions = const RoomOptions(),
|
||||
@@ -89,6 +95,13 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
_engineListener = this.engine.createListener();
|
||||
_setUpEngineListeners();
|
||||
|
||||
if (!lkPlatformIsTest()) {
|
||||
_appCloseSubscription =
|
||||
AppStateListener.instance.onWindowShouldClose.stream.listen((event) {
|
||||
disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
_signalListener = this.engine.signalClient.createListener();
|
||||
_setUpSignalListeners();
|
||||
|
||||
@@ -111,6 +124,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
await _engineListener.dispose();
|
||||
// dispose the engine
|
||||
await this.engine.dispose();
|
||||
// dispose the app state listener
|
||||
await _appCloseSubscription?.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_window_close/flutter_window_close.dart';
|
||||
|
||||
class AppStateListener {
|
||||
AppStateListener._internal() {
|
||||
FlutterWindowClose.setWindowShouldCloseHandler(() async {
|
||||
onWindowShouldClose.add('close');
|
||||
return true;
|
||||
});
|
||||
}
|
||||
static final AppStateListener instance = AppStateListener._internal();
|
||||
final StreamController<String> onWindowShouldClose =
|
||||
StreamController.broadcast(sync: true);
|
||||
}
|
||||
@@ -24,6 +24,7 @@ dependencies:
|
||||
synchronized: ^3.0.0+3
|
||||
protobuf: ^2.1.0
|
||||
flutter_webrtc: 0.9.17
|
||||
flutter_window_close: ^0.2.2
|
||||
dart_webrtc: 1.0.11
|
||||
device_info_plus: ^6.0.0
|
||||
webrtc_interface: 1.0.10
|
||||
|
||||
Reference in New Issue
Block a user