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

Feature/showing connecting status on answering a call #45

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Initialise RNCallKit with options
- **hasVideo**: boolean (optional)
- false (default)
- **localizedCallerName**: string (optional)
- **showConnectionState**: boolean (optional)
- `false` by default, set it to `true` if you wish to show the user connecting state after hitting the answer button. Note that you will need to update the connection state using `updateConnectionState(connected: boolean)`.

Call when you receive incoming calls to display system UI

Expand Down Expand Up @@ -174,6 +176,14 @@ Checks if there are any active calls on the device and returns a promise with a

Checks if the device speaker is on and returns a promise with a boolean value (`true` if speaker is on, `false` otherwise).

### updateConnectionState

Note: you don't need to call this method if you didn't set `showConnectionState` to `true` while displaying a call.

Call this method when you establish or lose connection while answering. It transitions a call from `connecting` state to either `connected` or `failed`.

- **connected**: boolean (default value is `true`)

## Events

### - didReceiveStartCallAction
Expand All @@ -198,6 +208,8 @@ User answer the incoming call

Do your normal `Answering` actions here

Note: This is the place you might want to call `updateConnectionState` if you set `showConnectionState` to `true` on displaying a call.

**data**:

```javascript
Expand Down Expand Up @@ -288,6 +300,7 @@ class RNCallKitExample extends React.Component {
* Try to do your normal Answering actions here
*
* e.g. this.handleAnswerCall(data.callUUID);
*
*/
}

Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ export default class RNCallKit {
_RNCallKit.setup(options);
}

static displayIncomingCall(uuid, handle, handleType = 'number', hasVideo = false, localizedCallerName?: String) {
static displayIncomingCall(uuid, handle, handleType = 'number', hasVideo = false, localizedCallerName = '', showConnectionState = false) {
if (Platform.OS !== 'ios') return;
_RNCallKit.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName);
_RNCallKit.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName, showConnectionState);
}

static startCall(uuid, handle, handleType = 'number', hasVideo = false, contactIdentifier?: String) {
static startCall(uuid, handle, handleType = 'number', hasVideo = false, contactIdentifier) {
if (Platform.OS !== 'ios') return;
_RNCallKit.startCall(uuid, handle, handleType, hasVideo, contactIdentifier);
}
Expand Down Expand Up @@ -121,6 +121,11 @@ export default class RNCallKit {
: Promise.reject('RNCallKit.checkSpeaker was called from unsupported OS');
}

static updateConnectionState(connected = true) {
if (Platform.OS !== 'ios') return;
_RNCallKit.updateConnectionState(connected);
}

/*
static setHeldCall(uuid, onHold) {
if (Platform.OS !== 'ios') return;
Expand Down
29 changes: 26 additions & 3 deletions ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ @implementation RNCallKit
NSMutableDictionary *_settings;
NSOperatingSystemVersion _version;
BOOL _isStartCallActionEventListenerAdded;
CXAnswerCallAction *_answerCallAction;
BOOL _shouldShowConnectionState;
}

// should initialise in AppDelegate.m
Expand All @@ -46,6 +48,7 @@ - (instancetype)init
name:RNCallKitHandleStartCallNotification
object:nil];
_isStartCallActionEventListenerAdded = NO;
_shouldShowConnectionState = NO;
}
return self;
}
Expand Down Expand Up @@ -111,7 +114,8 @@ - (void)dealloc
handle:(NSString *)handle
handleType:(NSString *)handleType
hasVideo:(BOOL)hasVideo
localizedCallerName:(NSString * _Nullable)localizedCallerName)
localizedCallerName:(NSString *)localizedCallerName
showConnectionState:(BOOL)showConnectionState)
{
#ifdef DEBUG
NSLog(@"[RNCallKit][displayIncomingCall] uuidString = %@", uuidString);
Expand All @@ -126,7 +130,10 @@ - (void)dealloc
callUpdate.supportsGrouping = NO;
callUpdate.supportsUngrouping = NO;
callUpdate.hasVideo = hasVideo;
callUpdate.localizedCallerName = localizedCallerName;
if ([localizedCallerName length] > 0) {
callUpdate.localizedCallerName = localizedCallerName;
}
_shouldShowConnectionState = showConnectionState;

[self.callKitProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) {
[self sendEventWithName:RNCallKitDidDisplayIncomingCall body:@{ @"error": error ? error.localizedDescription : @"" }];
Expand Down Expand Up @@ -221,6 +228,18 @@ - (void)dealloc
[self requestTransaction:transaction];
}

RCT_EXPORT_METHOD(updateConnectionState:(BOOL )connected)
{
#ifdef DEBUG
NSLog(@"[RNCallKit][updateConnectionState]");
#endif
if (connected) {
[_answerCallAction fulfill];
} else {
[_answerCallAction fail];
}
}

- (void)requestTransaction:(CXTransaction *)transaction
{
#ifdef DEBUG
Expand Down Expand Up @@ -432,7 +451,11 @@ - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAct
}
NSString *callUUID = [self containsLowerCaseLetter:action.callUUID.UUIDString] ? action.callUUID.UUIDString : [action.callUUID.UUIDString lowercaseString];
[self sendEventWithName:RNCallKitPerformAnswerCallAction body:@{ @"callUUID": callUUID }];
[action fulfill];
if (_shouldShowConnectionState) {
_answerCallAction = action;
} else {
[action fullfill];
}
}

// Ending incoming call
Expand Down