Skip to content

Commit c15c147

Browse files
aarkalykianlin
authored andcommitted
Feature/method and callback for mic toggle (#40)
* setMute method and event handler added. * version bumped. * back to Brittish :) * rolled back to 1.3.3
1 parent af8dd00 commit c15c147

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ Call when you make an outgoing call
159159

160160
Call when you finish an incoming/outgoing call
161161

162+
### setMutedCall
163+
164+
- **uuid**: string
165+
- **muted**: boolean
166+
167+
Switch the mic on/off
168+
162169
## Events
163170

164171
### - didReceiveStartCallAction
@@ -217,6 +224,12 @@ Callback for `RNCallKit.displayIncomingCall`
217224

218225
**error**: string (optional)
219226

227+
### - didPerformSetMutedCallAction
228+
229+
A call was muted by the system or the user:
230+
231+
**muted**: boolean
232+
220233
## Usage
221234

222235
```javascript
@@ -246,6 +259,7 @@ class RNCallKitExample extends React.Component {
246259
RNCallKit.addEventListener('endCall', this.onRNCallKitPerformEndCallAction);
247260
RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession);
248261
RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall);
262+
RNCallKit.addEventListener('didPerformSetMutedCallAction', this.onRNCallKitDidPerformSetMutedCallAction);
249263
}
250264

251265
onRNCallKitDidReceiveStartCallAction(data) {
@@ -292,6 +306,12 @@ class RNCallKitExample extends React.Component {
292306
*/
293307
}
294308

309+
onRNCallKitDidPerformSetMutedCallAction(muted) {
310+
/* You will get this event after the system or the user mutes a call
311+
* You can use it to toggle the mic on your custom call UI
312+
*/
313+
}
314+
295315
// This is a fake function where you can receive incoming call notifications
296316
onIncomingCall() {
297317
// Store the generated uuid somewhere

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction';
1616
const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction';
1717
const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession';
1818
const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall';
19+
const RNCallKitDidPerformSetMutedCallAction = 'RNCallKitDidPerformSetMutedCallAction';
1920

2021
export default class RNCallKit {
2122
static addEventListener(type, handler) {
@@ -47,6 +48,11 @@ export default class RNCallKit {
4748
RNCallKitDidDisplayIncomingCall,
4849
(data) => { handler(data.error); }
4950
);
51+
} else if (type === 'didPerformSetMutedCallAction') {
52+
listener = _RNCallKitEmitter.addListener(
53+
RNCallKitDidPerformSetMutedCallAction,
54+
(data) => { handler(data.muted); }
55+
);
5056
}
5157

5258
_callkitEventHandlers.set(handler, listener);
@@ -98,6 +104,11 @@ export default class RNCallKit {
98104
_RNCallKit.endAllCalls();
99105
}
100106

107+
static setMutedCAll(uuid, muted) {
108+
if (Platform.OS !== 'ios') return;
109+
_RNCallKit.setMutedCall(uuid, muted);
110+
}
111+
101112
/*
102113
static setHeldCall(uuid, onHold) {
103114
if (Platform.OS !== 'ios') return;

ios/RNCallKit/RNCallKit.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
static NSString *const RNCallKitPerformEndCallAction = @"RNCallKitPerformEndCallAction";
2424
static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession";
2525
static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall";
26+
static NSString *const RNCallKitDidPerformSetMutedCallAction = @"RNCallKitDidPerformSetMutedCallAction";
2627

2728
@implementation RNCallKit
2829
{
@@ -65,7 +66,8 @@ - (void)dealloc
6566
RNCallKitPerformAnswerCallAction,
6667
RNCallKitPerformEndCallAction,
6768
RNCallKitDidActivateAudioSession,
68-
RNCallKitDidDisplayIncomingCall
69+
RNCallKitDidDisplayIncomingCall,
70+
RNCallKitDidPerformSetMutedCallAction
6971
];
7072
}
7173

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

190+
RCT_EXPORT_METHOD(setMutedCall:(NSString *)uuidString muted:(BOOL)muted)
191+
{
192+
#ifdef DEBUG
193+
NSLog(@"[RNCallKit][setMutedCall] muted = %i", muted);
194+
#endif
195+
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
196+
CXSetMutedCallAction *setMutedAction = [[CXSetMutedCallAction alloc] initWithCallUUID:uuid muted:muted];
197+
CXTransaction *transaction = [[CXTransaction alloc] init];
198+
[transaction addAction:setMutedAction];
199+
200+
[self requestTransaction:transaction];
201+
}
188202

189203
- (void)requestTransaction:(CXTransaction *)transaction
190204
{
@@ -440,4 +454,13 @@ - (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSessio
440454
#endif
441455
}
442456

457+
-(void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action
458+
{
459+
#ifdef DEBUG
460+
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction]");
461+
#endif
462+
[self sendEventWithName:RNCallKitDidPerformSetMutedCallAction body:@{ @"muted": @(action.muted) }];
463+
[action fulfill];
464+
}
465+
443466
@end

0 commit comments

Comments
 (0)