Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Dec 26, 2020
1 parent cfb8f3f commit 0933f2b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

-----------------------------------------------
[0.2.2] - 2020.12.27

* Update json format for push payload.

[0.2.1] - 2020.12.23

* Fix: Missing null check.
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

```json
{
"callkeep": {
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
"caller_id": "+8618612345678",
"caller_name": "hello",
"caller_id_type": "number",
"has_video": false,
},
"extra": {
"foo": "bar",
"key": "value",
}
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
"caller_id": "+8618612345678",
"caller_name": "hello",
"caller_id_type": "number",
"has_video": false,
}
```
33 changes: 27 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,39 @@ import 'package:uuid/uuid.dart';
final FlutterCallkeep _callKeep = FlutterCallkeep();
bool _callKeepInited = false;

/*
{
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
"caller_id": "+8618612345678",
"caller_name": "hello",
"caller_id_type": "number",
"has_video": false,
"extra": {
"foo": "bar",
"key": "value",
}
}
*/

Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
print('backgroundMessage: message => ${message.toString()}');
var payload = message['data'];
var callerId = payload['caller_id'] as String;
var callerNmae = payload['caller_name'] as String;
var uuid = payload['uuid'] as String;
var hasVideo = payload['has_video'] == "true";

var number = message['data']['body'] as String;
final callUUID = Uuid().v4();
final callUUID = uuid ?? Uuid().v4();
_callKeep.on(CallKeepPerformAnswerCallAction(),
(CallKeepPerformAnswerCallAction event) {
print(
'backgroundMessage: CallKeepPerformAnswerCallAction ${event.callUUID}');
_callKeep.startCall(event.callUUID, number, number);
_callKeep.startCall(event.callUUID, callerId, callerNmae);

Timer(const Duration(seconds: 1), () {
print('[setCurrentCallActive] $callUUID, number: $number');
print(
'[setCurrentCallActive] $callUUID, callerId: $callerId, callerName: $callerNmae');
_callKeep.setCurrentCallActive(callUUID);
});
//_callKeep.endCall(event.callUUID);
Expand All @@ -49,8 +69,9 @@ Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
_callKeepInited = true;
}

print('backgroundMessage: displayIncomingCall ($number)');
_callKeep.displayIncomingCall(callUUID, number);
print('backgroundMessage: displayIncomingCall ($callerId)');
_callKeep.displayIncomingCall(callUUID, callerId,
localizedCallerName: callerNmae, hasVideo: hasVideo);
_callKeep.backToForeground();
/*
Expand Down
24 changes: 10 additions & 14 deletions ios/Classes/CallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,21 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
NSLog(@"didReceiveIncomingPushWithPayload payload = %@", payload.type);
/* payload example.
{
"callkeep": {
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
"caller_id": "+8618612345678",
"caller_name": "hello",
"caller_id_type": "number",
"has_video": false,
},
"extra": {
"foo": "bar",
"key": "value",
}
"uuid": "xxxxx-xxxxx-xxxxx-xxxxx",
"caller_id": "+8618612345678",
"caller_name": "hello",
"caller_id_type": "number",
"has_video": false,
}
*/
NSDictionary *dic = payload.dictionaryPayload[@"callkeep"];
NSDictionary *dic = payload.dictionaryPayload;

NSString *uuid = dic[@"uuid"];
NSString *callerId = dic[@"caller_id"];
NSString *callerName = dic[@"caller_name"];
BOOL hasVideo = [dic[@"has_video"] boolValue];
NSString *callerIdType = dic[@"caller_id_type"];
NSString *uuid = dic[@"uuid"];


if( uuid == nil) {
uuid = [self createUUID];
Expand All @@ -257,7 +253,7 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa
hasVideo:hasVideo
localizedCallerName:callerName
fromPushKit:YES
payload:payload.dictionaryPayload
payload:dic
withCompletionHandler:^(){}];
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: callkeep
description: iOS CallKit framework and Android ConnectionService for Flutter.
version: 0.2.1
version: 0.2.2
author: duanweiwei1982@gmail.com
homepage: https://github.com/flutter-webrtc/callkeep

Expand Down

0 comments on commit 0933f2b

Please sign in to comment.