Skip to content

Commit 3c5d9ce

Browse files
authored
fix: push notification cancelation (#554)
* fixes push notification cancelation * minor fixes for pub scoreing * tweaks
1 parent 59c58b3 commit 3c5d9ce

File tree

8 files changed

+63
-22
lines changed

8 files changed

+63
-22
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:stream_video/stream_video.dart';
3+
4+
Future<void> main() async {
5+
WidgetsFlutterBinding.ensureInitialized();
6+
7+
StreamVideo.create(
8+
'api_token',
9+
user: User.guest(userId: 'user_id'),
10+
);
11+
}

packages/stream_video/lib/src/stream_video.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,18 @@ class StreamVideo {
572572
final callCid = payload['call_cid'] as String?;
573573
if (callCid == null) return false;
574574

575-
final uuid = const Uuid().v4();
575+
var callId = const Uuid().v4();
576+
final splitCid = callCid.split(':');
577+
if (splitCid.length == 2) {
578+
callId = splitCid.last;
579+
}
580+
576581
final createdById = payload['created_by_id'] as String?;
577582
final createdByName = payload['created_by_display_name'] as String?;
578583

579584
unawaited(
580585
manager.showIncomingCall(
581-
uuid: uuid,
586+
uuid: callId,
582587
handle: createdById,
583588
nameCaller: createdByName,
584589
callCid: callCid,

packages/stream_video/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ environment:
1212

1313
dependencies:
1414
async: ^2.11.0
15-
collection: ^1.17.1
16-
connectivity_plus: ^4.0.2
15+
collection: ^1.18.0
16+
connectivity_plus: ^5.0.2
1717
dart_webrtc: ^1.1.3
1818
equatable: ^2.0.5
1919
fixnum: ^1.1.0
@@ -22,7 +22,7 @@ dependencies:
2222
flutter_webrtc: ^0.9.47
2323
http: ^1.1.0
2424
internet_connection_checker: ^1.0.0+1
25-
intl: ^0.18.1
25+
intl: ^0.19.0
2626
jose: ^0.3.4
2727
meta: ^1.9.1
2828
protobuf: ^3.1.0
@@ -31,7 +31,7 @@ dependencies:
3131
state_notifier: ^1.0.0
3232
synchronized: ^3.1.0
3333
tart: ^0.5.1
34-
uuid: ^3.0.7
34+
uuid: ^4.2.1
3535
web_socket_channel: ^2.4.0
3636
webrtc_interface: ^1.1.1
3737

packages/stream_video_flutter/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies:
2121
flutter_webrtc: ^0.9.47
2222
google_fonts: ^5.1.0
2323
http: ^1.1.0
24-
intl: ^0.18.1
24+
intl: ^0.19.0
2525
path_provider: ^2.1.0
2626
share_plus: ^7.1.0
2727
stream_video: ^0.3.1

packages/stream_video_flutter/lib/src/theme/call_content_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class StreamCallContentTheme extends InheritedWidget {
102102
static StreamCallContentThemeData incomingCallThemeOf(
103103
BuildContext context,
104104
) {
105-
final incomingOutgoingCallTheme = context
106-
.dependOnInheritedWidgetOfExactType<StreamCallContentTheme>();
105+
final incomingOutgoingCallTheme =
106+
context.dependOnInheritedWidgetOfExactType<StreamCallContentTheme>();
107107
return incomingOutgoingCallTheme?.data ??
108108
StreamVideoTheme.of(context).callContentTheme;
109109
}

packages/stream_video_push_notification/ios/Classes/StreamVideoPKDelegateManager.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
6767
let callCid = streamDict?["call_cid"] as? String ?? ""
6868
var createdByName = streamDict?["created_by_display_name"] as? String
6969
var createdById = streamDict?["created_by_id"] as? String
70+
71+
let splitCid = callCid.split(separator: ":", maxSplits: 1, omittingEmptySubsequences: true)
72+
var callId = UUID().uuidString;
73+
var callType = "";
74+
75+
if splitCid.count == 2 {
76+
let callType = String(splitCid[0])
77+
let callId = String(splitCid[1])
78+
}
7079

7180
let data: StreamVideoPushParams
7281
if let jsonData = self.defaultData {
@@ -75,7 +84,7 @@ public class StreamVideoPKDelegateManager: NSObject, PKPushRegistryDelegate {
7584
data = StreamVideoPushParams(args: [String: Any]())
7685
}
7786

78-
data.callKitData.uuid = UUID().uuidString
87+
data.callKitData.uuid = callId
7988
data.callKitData.nameCaller = createdByName ?? defaultCallText
8089
data.callKitData.handle = createdById ?? defaultCallText
8190
data.callKitData.type = 1 //video

packages/stream_video_push_notification/lib/src/stream_video_push_notification.dart

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import 'stream_video_push_params.dart';
1313
part 'stream_video_push_provider.dart';
1414

1515
const _idToken = 1;
16-
const _idCallIncoming = 2;
16+
const _idCallKitIncoming = 2;
1717
const _idCallEnded = 3;
18-
const _idCallAcceptDecline = 4;
18+
const _idCallAccepted = 4;
19+
const _idCallKitAcceptDecline = 5;
1920

2021
/// Implementation of [PushNotificationManager] for Stream Video.
2122
class StreamVideoPushNotificationManager implements PushNotificationManager {
@@ -54,14 +55,26 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
5455
this.callerCustomizationCallback,
5556
}) : _client = client {
5657
_subscriptions.add(
57-
_idCallIncoming,
58+
_idCallKitIncoming,
5859
onCallEvent.whereType<ActionCallIncoming>().listen(
5960
(_) {
6061
_subscriptions.add(
6162
_idCallEnded,
6263
client.events.on<CoordinatorCallEndedEvent>(
63-
(_) {
64-
endAllCalls();
64+
(event) {
65+
FlutterCallkitIncoming.endCall(event.callCid.id);
66+
},
67+
),
68+
);
69+
70+
_subscriptions.add(
71+
_idCallAccepted,
72+
client.events.on<CoordinatorCallAcceptedEvent>(
73+
(event) async {
74+
await FlutterCallkitIncoming.silenceEvents();
75+
await FlutterCallkitIncoming.endCall(event.callCid.id);
76+
await Future<void>.delayed(const Duration(milliseconds: 300));
77+
await FlutterCallkitIncoming.unsilenceEvents();
6578
},
6679
),
6780
);
@@ -70,10 +83,13 @@ class StreamVideoPushNotificationManager implements PushNotificationManager {
7083
);
7184

7285
_subscriptions.add(
73-
_idCallAcceptDecline,
74-
onCallEvent.whereType<ActionCallAccept>().map((_) => null).mergeWith(
75-
[onCallEvent.whereType<ActionCallDecline>().map((_) => null)]).listen(
86+
_idCallKitAcceptDecline,
87+
onCallEvent.whereType<ActionCallAccept>().map((_) => null).mergeWith([
88+
onCallEvent.whereType<ActionCallDecline>().map((_) => null),
89+
onCallEvent.whereType<ActionCallTimeout>().map((_) => null),
90+
]).listen(
7691
(_) {
92+
_subscriptions.cancel(_idCallAccepted);
7793
_subscriptions.cancel(_idCallEnded);
7894
},
7995
),

packages/stream_video_push_notification/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ dependencies:
1616
firebase_messaging: ^14.6.6
1717
flutter:
1818
sdk: flutter
19-
flutter_callkit_incoming: ^2.0.0+2
19+
flutter_callkit_incoming: ^2.0.1+1
20+
json_annotation: ^4.8.0
2021
meta: ^1.9.1
2122
plugin_platform_interface: ^2.1.6
2223
rxdart: ^0.27.7
2324
stream_video: ^0.3.1
24-
uuid: ^3.0.7
25-
json_annotation: ^4.8.0
25+
uuid: ^4.2.1
2626

2727
dev_dependencies:
2828
build_runner: ^2.4.4
2929
flutter_lints: ^2.0.2
3030
flutter_test:
3131
sdk: flutter
32-
mocktail: ^1.0.0
3332
json_serializable: ^6.6.1
33+
mocktail: ^1.0.0
3434

3535
flutter:
3636
# This section identifies this Flutter project as a plugin project.

0 commit comments

Comments
 (0)