Skip to content

Commit cf4b2e5

Browse files
committed
Listen to hold button during call
1 parent 753d2ba commit cf4b2e5

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ RNCallKeep.addEventListener('didPerformSetMutedCallAction', (muted) => {
287287
});
288288

289289
```
290+
### - didToggleHoldCallAction
291+
292+
A call was held or unheld by the current user
293+
294+
```js
295+
RNCallKeep.addEventListener('didToggleHoldCallAction', ({ hold, callUUID }) => {
296+
297+
});
298+
```
299+
300+
- `hold` (boolean)
301+
- `callUUID` (string)
302+
- The UUID of the call that is to be answered (iOS only).
303+
290304
### - didPerformDTMFAction
291305

292306
Used type a number on his dialer

actions.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const RNCallKeepPerformEndCallAction = 'RNCallKeepPerformEndCallAction';
99
const RNCallKeepDidActivateAudioSession = 'RNCallKeepDidActivateAudioSession';
1010
const RNCallKeepDidDisplayIncomingCall = 'RNCallKeepDidDisplayIncomingCall';
1111
const RNCallKeepDidPerformSetMutedCallAction = 'RNCallKeepDidPerformSetMutedCallAction';
12-
const RNCallKeepDidPerformHoldAction = 'RNCallKeepDidPerformHoldAction';
13-
const RNCallKeepDidPerformUnHoldAction = 'RNCallKeepDidPerformUnHoldAction';
12+
const RNCallKeepDidToggleHoldAction = 'RNCallKeepDidToggleHoldAction';
1413
const RNCallKeepDidPerformDTMFAction = 'RNCallKeepDidPerformDTMFAction';
1514
const isIOS = Platform.OS === 'ios';
1615

@@ -43,6 +42,9 @@ const didDisplayIncomingCall = handler =>
4342
const didPerformSetMutedCallAction = handler =>
4443
eventEmitter.addListener(RNCallKeepDidPerformSetMutedCallAction, (data) => handler(data.muted));
4544

45+
const didToggleHoldCallAction = handler =>
46+
eventEmitter.addListener(RNCallKeepDidToggleHoldAction, handler);
47+
4648
const didPerformDTMFAction = handler =>
4749
eventEmitter.addListener(RNCallKeepDidPerformDTMFAction, (data) => {
4850
const payload = isIOS ? { dtmf: data.digits, callUUID: data.callUUID } : data;
@@ -57,6 +59,7 @@ export const listeners = {
5759
didActivateAudioSession,
5860
didDisplayIncomingCall,
5961
didPerformSetMutedCallAction,
62+
didToggleHoldCallAction,
6063
didPerformDTMFAction,
6164
};
6265

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ public void onReceive(Context context, Intent intent) {
308308
sendEventToJS("RNCallKeepPerformAnswerCallAction", null);
309309
break;
310310
case ACTION_HOLD_CALL:
311-
sendEventToJS("RNCallKeepDidPerformHoldAction", null);
311+
args.putBoolean("hold", true);
312+
sendEventToJS("RNCallKeepDidToggleHoldAction", args);
312313
break;
313314
case ACTION_UNHOLD_CALL:
314-
sendEventToJS("RNCallKeepDidPerformUnHoldAction", null);
315+
args.putBoolean("hold", false);
316+
sendEventToJS("RNCallKeepDidToggleHoldAction", args);
315317
break;
316318
case ACTION_MUTE_CALL:
317319
args.putBoolean("muted", true);

ios/RNCallKeep/RNCallKeep.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
static NSString *const RNCallKeepDidDisplayIncomingCall = @"RNCallKeepDidDisplayIncomingCall";
2626
static NSString *const RNCallKeepDidPerformSetMutedCallAction = @"RNCallKeepDidPerformSetMutedCallAction";
2727
static NSString *const RNCallKeepPerformPlayDTMFCallAction = @"RNCallKeepDidPerformDTMFAction";
28+
static NSString *const RNCallKeepDidToggleHoldAction = @"RNCallKeepDidToggleHoldAction";
2829

2930
@implementation RNCallKeep
3031
{
@@ -69,7 +70,8 @@ - (void)dealloc
6970
RNCallKeepDidActivateAudioSession,
7071
RNCallKeepDidDisplayIncomingCall,
7172
RNCallKeepDidPerformSetMutedCallAction,
72-
RNCallKeepPerformPlayDTMFCallAction
73+
RNCallKeepPerformPlayDTMFCallAction,
74+
RNCallKeepDidToggleHoldAction
7375
];
7476
}
7577

@@ -123,8 +125,7 @@ - (void)dealloc
123125
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
124126
callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle];
125127
callUpdate.supportsDTMF = YES;
126-
// TODO: Holding
127-
callUpdate.supportsHolding = NO;
128+
callUpdate.supportsHolding = YES;
128129
callUpdate.supportsGrouping = NO;
129130
callUpdate.supportsUngrouping = NO;
130131
callUpdate.hasVideo = hasVideo;
@@ -243,7 +244,7 @@ - (void)requestTransaction:(CXTransaction *)transaction
243244
CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init];
244245
callUpdate.remoteHandle = startCallAction.handle;
245246
callUpdate.supportsDTMF = YES;
246-
callUpdate.supportsHolding = NO;
247+
callUpdate.supportsHolding = YES;
247248
callUpdate.supportsGrouping = NO;
248249
callUpdate.supportsUngrouping = NO;
249250
callUpdate.hasVideo = NO;
@@ -292,7 +293,7 @@ - (CXProviderConfiguration *)getProviderConfiguration
292293
#endif
293294
CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc] initWithLocalizedName:_settings[@"appName"]];
294295
providerConfiguration.supportsVideo = YES;
295-
providerConfiguration.maximumCallGroups = 1;
296+
providerConfiguration.maximumCallGroups = 3;
296297
providerConfiguration.maximumCallsPerCallGroup = 1;
297298
providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], [NSNumber numberWithInteger:CXHandleTypeEmailAddress], [NSNumber numberWithInteger:CXHandleTypeGeneric], nil];
298299
if (_settings[@"imageName"]) {
@@ -448,11 +449,15 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)
448449
[action fulfill];
449450
}
450451

451-
- (void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action
452+
-(void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action
452453
{
453454
#ifdef DEBUG
454-
NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performSetHeldCallAction]");
455+
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetHeldCallAction]");
455456
#endif
457+
NSString *callUUID = [self containsLowerCaseLetter:action.callUUID.UUIDString] ? action.callUUID.UUIDString : [action.callUUID.UUIDString lowercaseString];
458+
459+
[self sendEventWithName:RNCallKeepDidToggleHoldAction body:@{ @"hold": @(action.onHold), @"callUUID": callUUID }];
460+
[action fulfill];
456461
}
457462

458463
- (void)provider:(CXProvider *)provider performPlayDTMFCallAction:(CXPlayDTMFCallAction *)action {

0 commit comments

Comments
 (0)