2017-09-28 21:25:04 +00:00
|
|
|
import { NativeModules, NativeEventEmitter } from 'react-native';
|
2017-09-08 09:28:44 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import { getName } from '../../app/functions';
|
2019-01-31 16:20:54 +00:00
|
|
|
|
2017-09-08 09:28:44 +00:00
|
|
|
/**
|
|
|
|
* Thin wrapper around Apple's CallKit functionality.
|
|
|
|
*
|
|
|
|
* In CallKit requests are performed via actions (either user or system started)
|
|
|
|
* and async events are reported via dedicated methods. This class exposes that
|
|
|
|
* functionality in the form of methods and events. One important thing to note
|
|
|
|
* is that even if an action is started by the system (because the user pressed
|
|
|
|
* the "end call" button in the CallKit view, for example) the event will be
|
|
|
|
* emitted in the same way as it would if the action originated from calling
|
|
|
|
* the "endCall" method in this class, for example.
|
|
|
|
*
|
|
|
|
* Emitted events:
|
2017-09-28 21:25:04 +00:00
|
|
|
* - performAnswerCallAction: The user pressed the answer button.
|
|
|
|
* - performEndCallAction: The call should be ended.
|
|
|
|
* - performSetMutedCallAction: The call muted state should change. The
|
|
|
|
* ancillary `data` object contains a `muted` attribute.
|
|
|
|
* - providerDidReset: The system has reset, all calls should be terminated.
|
|
|
|
* This event gets no associated data.
|
2017-09-08 09:28:44 +00:00
|
|
|
*
|
|
|
|
* All events get a `data` object with a `callUUID` property, unless stated
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2017-09-28 21:25:04 +00:00
|
|
|
let CallKit = NativeModules.RNCallKit;
|
|
|
|
|
|
|
|
// XXX Rather than wrapping RNCallKit in a new class and forwarding the many
|
|
|
|
// methods of the latter to the former, add the one additional method that we
|
|
|
|
// need to RNCallKit.
|
|
|
|
if (CallKit) {
|
|
|
|
const eventEmitter = new NativeEventEmitter(CallKit);
|
|
|
|
|
|
|
|
CallKit = {
|
|
|
|
...CallKit,
|
2019-01-31 16:20:54 +00:00
|
|
|
addListener: eventEmitter.addListener.bind(eventEmitter),
|
|
|
|
registerSubscriptions(context, delegate) {
|
|
|
|
CallKit.setProviderConfiguration({
|
|
|
|
iconTemplateImageName: 'CallKitIcon',
|
|
|
|
localizedName: getName()
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
CallKit.addListener(
|
|
|
|
'performEndCallAction',
|
|
|
|
delegate._onPerformEndCallAction,
|
|
|
|
context),
|
|
|
|
CallKit.addListener(
|
|
|
|
'performSetMutedCallAction',
|
|
|
|
delegate._onPerformSetMutedCallAction,
|
|
|
|
context),
|
|
|
|
|
|
|
|
// According to CallKit's documentation, when the system resets
|
|
|
|
// we should terminate all calls. Hence, providerDidReset is
|
|
|
|
// the same to us as performEndCallAction.
|
|
|
|
CallKit.addListener(
|
|
|
|
'providerDidReset',
|
|
|
|
delegate._onPerformEndCallAction,
|
|
|
|
context)
|
|
|
|
];
|
|
|
|
}
|
2017-09-28 21:25:04 +00:00
|
|
|
};
|
2017-09-08 09:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-28 21:25:04 +00:00
|
|
|
export default CallKit;
|