From a85d2ac16af52797781ff1df60f7d0c42578b1c7 Mon Sep 17 00:00:00 2001 From: jakubdrynkowski Date: Thu, 7 Feb 2019 11:14:31 +0100 Subject: [PATCH 1/2] [WIP] Add action for DTMF tones Co-authored-by: MarcinWalendowski --- actions.js | 82 +++++++++++++++++++++------------------ ios/RNCallKit/RNCallKit.m | 15 ++++++- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/actions.js b/actions.js index 7a1b234..831f906 100644 --- a/actions.js +++ b/actions.js @@ -1,6 +1,6 @@ -import { - NativeModules, - NativeEventEmitter, +import { + NativeModules, + NativeEventEmitter, } from 'react-native'; const _RNCallKit = NativeModules.RNCallKit; @@ -12,57 +12,65 @@ const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction'; const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession'; const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall'; const RNCallKitDidPerformSetMutedCallAction = 'RNCallKitDidPerformSetMutedCallAction'; +const RNCallKitDidReceiveDTMFCallAction = 'RNCallKitDidReceiveDTMFCallAction'; didReceiveStartCallAction = handler => { - const listener = _RNCallKitEmitter.addListener( - RNCallKitDidReceiveStartCallAction, - (data) => { handler(data);} - ); - _RNCallKit._startCallActionEventListenerAdded(); - return listener; + const listener = _RNCallKitEmitter.addListener( + RNCallKitDidReceiveStartCallAction, + (data) => { handler(data);} + ); + _RNCallKit._startCallActionEventListenerAdded(); + return listener; } answerCall = handler => ( - _RNCallKitEmitter.addListener( - RNCallKitPerformAnswerCallAction, - (data) => { handler(data);} - ) + _RNCallKitEmitter.addListener( + RNCallKitPerformAnswerCallAction, + (data) => { handler(data);} + ) ) endCall = handler => ( - _RNCallKitEmitter.addListener( - RNCallKitPerformEndCallAction, - (data) => { handler(data); } - ) + _RNCallKitEmitter.addListener( + RNCallKitPerformEndCallAction, + (data) => { handler(data); } + ) ) didActivateAudioSession = handler => ( - _RNCallKitEmitter.addListener( - RNCallKitDidActivateAudioSession, - () => { handler(); } - ) + _RNCallKitEmitter.addListener( + RNCallKitDidActivateAudioSession, + () => { handler(); } + ) ) didDisplayIncomingCall = handler => ( - _RNCallKitEmitter.addListener( - RNCallKitDidDisplayIncomingCall, - (data) => { handler(data.error); } - ) + _RNCallKitEmitter.addListener( + RNCallKitDidDisplayIncomingCall, + (data) => { handler(data.error); } + ) ) didPerformSetMutedCallAction = handler => ( - _RNCallKitEmitter.addListener( - RNCallKitDidPerformSetMutedCallAction, - (data) => { handler(data.muted); } - ) + _RNCallKitEmitter.addListener( + RNCallKitDidPerformSetMutedCallAction, + (data) => { handler(data.muted); } + ) ) -export const listeners = { - didReceiveStartCallAction, - answerCall, - endCall, - didActivateAudioSession, - didDisplayIncomingCall, - didPerformSetMutedCallAction, -}; +didReceiveDTMFCallAction = handler => ( + _RNCallKitEmitter.addListener( + RNCallKitDidReceiveDTMFCallAction, + (data) => { handler(data.digits); } + ) +) +export const listeners = { + didReceiveStartCallAction, + answerCall, + endCall, + didActivateAudioSession, + didDisplayIncomingCall, + didPerformSetMutedCallAction, + didReceiveDTMFCallAction +}; \ No newline at end of file diff --git a/ios/RNCallKit/RNCallKit.m b/ios/RNCallKit/RNCallKit.m index fc3439f..0fdee81 100644 --- a/ios/RNCallKit/RNCallKit.m +++ b/ios/RNCallKit/RNCallKit.m @@ -24,6 +24,7 @@ static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession"; static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall"; static NSString *const RNCallKitDidPerformSetMutedCallAction = @"RNCallKitDidPerformSetMutedCallAction"; +static NSString *const RNCallKitDidReceiveDTMFCallAction = @"RNCallKitDidReceiveDTMFCallAction"; @implementation RNCallKit { @@ -67,7 +68,8 @@ - (void)dealloc RNCallKitPerformEndCallAction, RNCallKitDidActivateAudioSession, RNCallKitDidDisplayIncomingCall, - RNCallKitDidPerformSetMutedCallAction + RNCallKitDidPerformSetMutedCallAction, + RNCallKitDidReceiveDTMFCallAction ]; } @@ -484,4 +486,15 @@ -(void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCall [action fulfill]; } +-(void)provider:(CXProvider *)provider performPlayDTMFCallAction:(CXPlayDTMFCallAction *)action +{ + +#ifdef DEBUG + NSLog(@"[RNCallKit][CXProviderDelegate][provider:performPlayDTMFCallAction]"); +#endif + NSLog(@"%@", action); + [self sendEventWithName:RNCallKitDidReceiveDTMFCallAction body:@{ @"digits": action.digits }]; + [action fulfill]; +} + @end From 78a4f81e582e05ee2b3a56baba85b85f1113cfe3 Mon Sep 17 00:00:00 2001 From: jakubdrynkowski Date: Sun, 10 Feb 2019 12:22:55 +0100 Subject: [PATCH 2/2] [FEATURE] Update README add didReceiveDTMFCallAction. Co-authored-by: MarcinWalendowski --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index b574fef..15850ce 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,12 @@ A call was muted by the system or the user: **muted**: boolean +### - didReceiveDTMFCallAction + +User is interacting with a number pad. He pressed a key. + +**digit**: string + ## Usage ```javascript @@ -268,6 +274,7 @@ class RNCallKitExample extends React.Component { RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession); RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall); RNCallKit.addEventListener('didPerformSetMutedCallAction', this.onRNCallKitDidPerformSetMutedCallAction); + RNCallKit.addEventListener('didReceiveDTMFCallAction', this.onRNCallKitDidReceiveDTMFCallAction) } onRNCallKitDidReceiveStartCallAction(data) { @@ -319,6 +326,12 @@ class RNCallKitExample extends React.Component { * You can use it to toggle the mic on your custom call UI */ } + + onRNCallKitDidReceiveDTMFCallAction(digit) { + /* You will get this event when user is interacting with a number pad + * "digit" is the key number that user pressed + */ + } // This is a fake function where you can receive incoming call notifications onIncomingCall() {