Skip to content
This repository was archived by the owner on May 26, 2019. It is now read-only.
Merged
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ Call when you make an outgoing call

Call when you finish an incoming/outgoing call

### setMutedCall

- **uuid**: string
- **muted**: boolean

Switch the mic on/off

## Events

### - didReceiveStartCallAction
Expand Down Expand Up @@ -217,6 +224,12 @@ Callback for `RNCallKit.displayIncomingCall`

**error**: string (optional)

### - didPerformSetMutedCallAction

A call was muted by the system or the user:

**muted**: boolean

## Usage

```javascript
Expand Down Expand Up @@ -246,6 +259,7 @@ class RNCallKitExample extends React.Component {
RNCallKit.addEventListener('endCall', this.onRNCallKitPerformEndCallAction);
RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession);
RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall);
RNCallKit.addEventListener('didPerformSetMutedCallAction', this.onRNCallKitDidPerformSetMutedCallAction);
}

onRNCallKitDidReceiveStartCallAction(data) {
Expand Down Expand Up @@ -292,6 +306,12 @@ class RNCallKitExample extends React.Component {
*/
}

onRNCallKitDidPerformSetMutedCallAction(muted) {
/* You will get this event after the system or the user mutes a call
* You can use it to toggle the mic on your custom call UI
*/
}

// This is a fake function where you can receive incoming call notifications
onIncomingCall() {
// Store the generated uuid somewhere
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction';
const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction';
const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession';
const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall';
const RNCallKitDidPerformSetMutedCallAction = 'RNCallKitDidPerformSetMutedCallAction';

export default class RNCallKit {
static addEventListener(type, handler) {
Expand Down Expand Up @@ -47,6 +48,11 @@ export default class RNCallKit {
RNCallKitDidDisplayIncomingCall,
(data) => { handler(data.error); }
);
} else if (type === 'didPerformSetMutedCallAction') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidPerformSetMutedCallAction,
(data) => { handler(data.muted); }
);
}

_callkitEventHandlers.set(handler, listener);
Expand Down Expand Up @@ -98,6 +104,11 @@ export default class RNCallKit {
_RNCallKit.endAllCalls();
}

static setMutedCAll(uuid, muted) {
if (Platform.OS !== 'ios') return;
_RNCallKit.setMutedCall(uuid, muted);
}

/*
static setHeldCall(uuid, onHold) {
if (Platform.OS !== 'ios') return;
Expand Down
25 changes: 24 additions & 1 deletion ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
static NSString *const RNCallKitPerformEndCallAction = @"RNCallKitPerformEndCallAction";
static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession";
static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall";
static NSString *const RNCallKitDidPerformSetMutedCallAction = @"RNCallKitDidPerformSetMutedCallAction";

@implementation RNCallKit
{
Expand Down Expand Up @@ -65,7 +66,8 @@ - (void)dealloc
RNCallKitPerformAnswerCallAction,
RNCallKitPerformEndCallAction,
RNCallKitDidActivateAudioSession,
RNCallKitDidDisplayIncomingCall
RNCallKitDidDisplayIncomingCall,
RNCallKitDidPerformSetMutedCallAction
];
}

Expand Down Expand Up @@ -185,6 +187,18 @@ - (void)dealloc
[self.callKitProvider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]];
}

RCT_EXPORT_METHOD(setMutedCall:(NSString *)uuidString muted:(BOOL)muted)
{
#ifdef DEBUG
NSLog(@"[RNCallKit][setMutedCall] muted = %i", muted);
#endif
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
CXSetMutedCallAction *setMutedAction = [[CXSetMutedCallAction alloc] initWithCallUUID:uuid muted:muted];
CXTransaction *transaction = [[CXTransaction alloc] init];
[transaction addAction:setMutedAction];

[self requestTransaction:transaction];
}

- (void)requestTransaction:(CXTransaction *)transaction
{
Expand Down Expand Up @@ -440,4 +454,13 @@ - (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSessio
#endif
}

-(void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action
{
#ifdef DEBUG
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction]");
#endif
[self sendEventWithName:RNCallKitDidPerformSetMutedCallAction body:@{ @"muted": @(action.muted) }];
[action fulfill];
}

@end