Skip to content

Commit 0933f2b

Browse files
committed
update.
1 parent cfb8f3f commit 0933f2b

File tree

5 files changed

+47
-32
lines changed

5 files changed

+47
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33
-----------------------------------------------
4+
[0.2.2] - 2020.12.27
5+
6+
* Update json format for push payload.
7+
48
[0.2.1] - 2020.12.23
59

610
* Fix: Missing null check.

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@
77

88
```json
99
{
10-
"callkeep": {
11-
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
12-
"caller_id": "+8618612345678",
13-
"caller_name": "hello",
14-
"caller_id_type": "number",
15-
"has_video": false,
16-
},
17-
"extra": {
18-
"foo": "bar",
19-
"key": "value",
20-
}
10+
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
11+
"caller_id": "+8618612345678",
12+
"caller_name": "hello",
13+
"caller_id_type": "number",
14+
"has_video": false,
2115
}
2216
```

example/lib/main.dart

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,39 @@ import 'package:uuid/uuid.dart';
1111
final FlutterCallkeep _callKeep = FlutterCallkeep();
1212
bool _callKeepInited = false;
1313

14+
/*
15+
{
16+
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
17+
"caller_id": "+8618612345678",
18+
"caller_name": "hello",
19+
"caller_id_type": "number",
20+
"has_video": false,
21+
22+
"extra": {
23+
"foo": "bar",
24+
"key": "value",
25+
}
26+
}
27+
*/
28+
1429
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
1530
print('backgroundMessage: message => ${message.toString()}');
31+
var payload = message['data'];
32+
var callerId = payload['caller_id'] as String;
33+
var callerNmae = payload['caller_name'] as String;
34+
var uuid = payload['uuid'] as String;
35+
var hasVideo = payload['has_video'] == "true";
1636

17-
var number = message['data']['body'] as String;
18-
final callUUID = Uuid().v4();
37+
final callUUID = uuid ?? Uuid().v4();
1938
_callKeep.on(CallKeepPerformAnswerCallAction(),
2039
(CallKeepPerformAnswerCallAction event) {
2140
print(
2241
'backgroundMessage: CallKeepPerformAnswerCallAction ${event.callUUID}');
23-
_callKeep.startCall(event.callUUID, number, number);
42+
_callKeep.startCall(event.callUUID, callerId, callerNmae);
2443

2544
Timer(const Duration(seconds: 1), () {
26-
print('[setCurrentCallActive] $callUUID, number: $number');
45+
print(
46+
'[setCurrentCallActive] $callUUID, callerId: $callerId, callerName: $callerNmae');
2747
_callKeep.setCurrentCallActive(callUUID);
2848
});
2949
//_callKeep.endCall(event.callUUID);
@@ -49,8 +69,9 @@ Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
4969
_callKeepInited = true;
5070
}
5171

52-
print('backgroundMessage: displayIncomingCall ($number)');
53-
_callKeep.displayIncomingCall(callUUID, number);
72+
print('backgroundMessage: displayIncomingCall ($callerId)');
73+
_callKeep.displayIncomingCall(callUUID, callerId,
74+
localizedCallerName: callerNmae, hasVideo: hasVideo);
5475
_callKeep.backToForeground();
5576
/*
5677

ios/Classes/CallKeep.m

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,21 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
225225
NSLog(@"didReceiveIncomingPushWithPayload payload = %@", payload.type);
226226
/* payload example.
227227
{
228-
"callkeep": {
229-
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
230-
"caller_id": "+8618612345678",
231-
"caller_name": "hello",
232-
"caller_id_type": "number",
233-
"has_video": false,
234-
},
235-
"extra": {
236-
"foo": "bar",
237-
"key": "value",
238-
}
228+
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
229+
"caller_id": "+8618612345678",
230+
"caller_name": "hello",
231+
"caller_id_type": "number",
232+
"has_video": false,
239233
}
240234
*/
241-
NSDictionary *dic = payload.dictionaryPayload[@"callkeep"];
235+
NSDictionary *dic = payload.dictionaryPayload;
236+
237+
NSString *uuid = dic[@"uuid"];
242238
NSString *callerId = dic[@"caller_id"];
243239
NSString *callerName = dic[@"caller_name"];
244240
BOOL hasVideo = [dic[@"has_video"] boolValue];
245241
NSString *callerIdType = dic[@"caller_id_type"];
246-
NSString *uuid = dic[@"uuid"];
242+
247243

248244
if( uuid == nil) {
249245
uuid = [self createUUID];
@@ -257,7 +253,7 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
257253
hasVideo:hasVideo
258254
localizedCallerName:callerName
259255
fromPushKit:YES
260-
payload:payload.dictionaryPayload
256+
payload:dic
261257
withCompletionHandler:^(){}];
262258
}
263259

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: callkeep
22
description: iOS CallKit framework and Android ConnectionService for Flutter.
3-
version: 0.2.1
3+
version: 0.2.2
44
55
homepage: https://github.com/flutter-webrtc/callkeep
66

0 commit comments

Comments
 (0)