Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

Add didReceiveDTMFCallAction #74

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
82 changes: 45 additions & 37 deletions actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
NativeModules,
NativeEventEmitter,
import {
NativeModules,
NativeEventEmitter,
} from 'react-native';

const _RNCallKit = NativeModules.RNCallKit;
Expand All @@ -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
};
15 changes: 14 additions & 1 deletion ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -67,7 +68,8 @@ - (void)dealloc
RNCallKitPerformEndCallAction,
RNCallKitDidActivateAudioSession,
RNCallKitDidDisplayIncomingCall,
RNCallKitDidPerformSetMutedCallAction
RNCallKitDidPerformSetMutedCallAction,
RNCallKitDidReceiveDTMFCallAction
];
}

Expand Down Expand Up @@ -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