From 0933f2b626c3fcccc0306b3ac0d479071fb3d5a1 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Sun, 27 Dec 2020 00:23:18 +0800 Subject: [PATCH] update. --- CHANGELOG.md | 4 ++++ README.md | 16 +++++----------- example/lib/main.dart | 33 +++++++++++++++++++++++++++------ ios/Classes/CallKeep.m | 24 ++++++++++-------------- pubspec.yaml | 2 +- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5603f..c92fb11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 6614c5c..975f977 100644 --- a/README.md +++ b/README.md @@ -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, } ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index ec3d951..60f6598 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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 myBackgroundMessageHandler(Map 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); @@ -49,8 +69,9 @@ Future myBackgroundMessageHandler(Map 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(); /* diff --git a/ios/Classes/CallKeep.m b/ios/Classes/CallKeep.m index cd590d6..681a52c 100644 --- a/ios/Classes/CallKeep.m +++ b/ios/Classes/CallKeep.m @@ -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]; @@ -257,7 +253,7 @@ - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayloa hasVideo:hasVideo localizedCallerName:callerName fromPushKit:YES - payload:payload.dictionaryPayload + payload:dic withCompletionHandler:^(){}]; } diff --git a/pubspec.yaml b/pubspec.yaml index 37d7c59..0288f01 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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