Skip to content

Commit 6d7e9b7

Browse files
Brazold3xvn
andauthored
feat(llc): add dispose to StreamVideo (#648)
* add dispose to StreamVideo * tweaked dispose --------- Co-authored-by: Deven Joshi <[email protected]>
1 parent 5e17f45 commit 6d7e9b7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/stream_video/lib/src/stream_video.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'coordinator/open_api/coordinator_client_open_api.dart';
1313
import 'coordinator/retry/coordinator_client_retry.dart';
1414
import 'core/client_state.dart';
1515
import 'core/connection_state.dart';
16+
import 'disposable.dart';
1617
import 'errors/video_error.dart';
1718
import 'errors/video_error_composer.dart';
1819
import 'internal/_instance_holder.dart';
@@ -67,7 +68,7 @@ typedef LogHandlerFunction = void Function(
6768
]);
6869

6970
/// The client responsible for handling config and maintaining calls
70-
class StreamVideo {
71+
class StreamVideo extends Disposable {
7172
/// Creates a new Stream Video client associated with the
7273
/// Stream Video singleton instance
7374
///
@@ -377,6 +378,21 @@ class StreamVideo {
377378
}
378379
}
379380

381+
@override
382+
Future<void> dispose() async {
383+
_logger.i(() => '[dispose]');
384+
385+
if (!_connectionState.isDisconnected) {
386+
await _client.disconnectUser();
387+
}
388+
389+
_subscriptions.cancelAll();
390+
await pushNotificationManager?.dispose();
391+
await _state.clear();
392+
393+
return super.dispose();
394+
}
395+
380396
void _onEvent(CoordinatorEvent event) {
381397
final currentUserId = _state.currentUser.id;
382398
_logger.v(() => '[onCoordinatorEvent] eventType: ${event.runtimeType}');

0 commit comments

Comments
 (0)