Skip to content

Commit dac0bd7

Browse files
authored
Merge pull request #14 from wazo-pbx/add_hold_action
Add hold action
2 parents 753d2ba + 54d2b31 commit dac0bd7

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

README.md

Lines changed: 18 additions & 1 deletion
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
@@ -387,9 +401,12 @@ class RNCallKeepExample extends React.Component {
387401
render() {
388402
}
389403
}
390-
391404
```
392405

406+
## Notes
407+
408+
- On iOS, you should call `setup` each time you want to use callKeep.
409+
393410
## Contributing
394411

395412
Any pull request, issue report and suggestion are highly welcome!

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);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ public void onAbort() {
155155
@Override
156156
public void onHold() {
157157
super.onHold();
158+
connection.setOnHold();
158159

159160
sendCallRequestToActivity(ACTION_HOLD_CALL, null);
160161
}
161162

162163
@Override
163164
public void onUnhold() {
164165
super.onUnhold();
166+
connection.setActive();
165167

166168
sendCallRequestToActivity(ACTION_UNHOLD_CALL, null);
167169
}

ios/RNCallKeep/RNCallKeep.m

Lines changed: 17 additions & 12 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,11 +125,10 @@ - (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.supportsGrouping = NO;
129-
callUpdate.supportsUngrouping = NO;
130-
callUpdate.hasVideo = hasVideo;
128+
callUpdate.supportsHolding = YES;
129+
callUpdate.supportsGrouping = YES;
130+
callUpdate.supportsUngrouping = YES;
131+
callUpdate.hasVideo = NO;
131132
callUpdate.localizedCallerName = localizedCallerName;
132133

133134
[self.callKeepProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
@@ -243,9 +244,9 @@ - (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.supportsGrouping = NO;
248-
callUpdate.supportsUngrouping = NO;
247+
callUpdate.supportsHolding = YES;
248+
callUpdate.supportsGrouping = YES;
249+
callUpdate.supportsUngrouping = YES;
249250
callUpdate.hasVideo = NO;
250251
[self.callKeepProvider reportCallWithUUID:startCallAction.callUUID updated:callUpdate];
251252
}
@@ -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,16 +449,20 @@ - (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
454455
NSLog(@"[RNCallKeep][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 {
459464
#ifdef DEBUG
460-
NSLog(@"[RNCallKit][CXProviderDelegate][provider:performPlayDTMFCallAction]");
465+
NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performPlayDTMFCallAction]");
461466
#endif
462467
NSString *callUUID = [self containsLowerCaseLetter:action.callUUID.UUIDString] ? action.callUUID.UUIDString : [action.callUUID.UUIDString lowercaseString];
463468
[self sendEventWithName:RNCallKeepPerformPlayDTMFCallAction body:@{ @"digits": action.digits, @"callUUID": callUUID }];

0 commit comments

Comments
 (0)