From 6dea651a970308507cb8c3f8795c45fbd03834a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Bra=C5=BCewicz?= Date: Thu, 19 Oct 2023 17:22:15 +0200 Subject: [PATCH] end CallKit call on call ending (#504) --- packages/stream_video/lib/src/stream_video.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/stream_video/lib/src/stream_video.dart b/packages/stream_video/lib/src/stream_video.dart index 4d63b9922..1dbcd38b7 100644 --- a/packages/stream_video/lib/src/stream_video.dart +++ b/packages/stream_video/lib/src/stream_video.dart @@ -51,6 +51,7 @@ const _tag = 'SV:Client'; const _idEvents = 1; const _idAppState = 2; const _idConnect = 3; +const _idActiveCall = 4; const _defaultCoordinatorRpcUrl = 'https://video.stream-io-api.com/video'; const _defaultCoordinatorWsUrl = 'wss://video.stream-io-api.com/video/connect'; @@ -322,6 +323,13 @@ class StreamVideo { // Register device with push notification manager. pushNotificationManager?.registerDevice(); + if (pushNotificationManager != null) { + _subscriptions.add( + _idActiveCall, + _state.activeCall.listen(_onActiveCall), + ); + } + return Result.success(tokenResult.data); } catch (e, stk) { _logger.e(() => '[connect] failed(${user.id}): $e'); @@ -421,6 +429,12 @@ class StreamVideo { } } + Future _onActiveCall(Call? activeCall) async { + if (activeCall == null) { + await pushNotificationManager?.endAllCalls(); + } + } + StreamSubscription listenActiveCall( void Function(Call? value)? onActiveCall, ) {