Up until now we relied on implicit loading of middlewares and reducers, through having imports in each feature's index.js. This leads to many complex import cycles which result in (sometimes) hard to fix bugs in addition to (often) breaking mobile because a web-only feature gets imported on mobile too, thanks to the implicit loading. This PR changes that to make the process explicit. Both middlewares and reducers are imported in a single place, the app entrypoint. They have been divided into 3 categories: any, web and native, which represent each of the platforms respectively. Ideally no feature should have an index.js exporting actions, action types and components, but that's a larger ordeal, so this is just the first step in getting there. In order to both set example and avoid large cycles the app feature has been refactored to not have an idex.js itself.
67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
|
|
import { getName } from '../../app/functions';
|
|
|
|
/**
|
|
* 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:
|
|
* - 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.
|
|
*
|
|
* All events get a `data` object with a `callUUID` property, unless stated
|
|
* otherwise.
|
|
*/
|
|
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,
|
|
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)
|
|
];
|
|
}
|
|
};
|
|
}
|
|
|
|
export default CallKit;
|