jiti-meet/react/features/mobile/call-integration/CallKit.js

67 lines
2.5 KiB
JavaScript
Raw Normal View History

import { NativeEventEmitter, NativeModules } from 'react-native';
import { getName } from '../../app/functions';
android: add ConnectionService * feat(Android): implement ConnectionService Adds basic integration with Android's ConnectionService by implementing the outgoing call scenario. * ref(callkit): rename _SET_CALLKIT_SUBSCRIPTIONS * ref(callkit): move feature to call-integration directory * feat(ConnectionService): synchronize video state * ref(AudioMode): use ConnectionService on API >= 26 Not ready yet - few details left mentioned in the FIXMEs * feat(ConnectionService): add debug logs Adds logs to trace the calls. * fix(ConnectionService): leaking ConnectionImpl instances Turns out there is no callback fired back from the JavaScript side after the disconnect or abort event is sent from the native. The connection must be marked as disconnected and removed immediately. * feat(ConnectionService): handle onCreateOutgoingConnectionFailed * ref(ConnectionService): merge classes and move to the sdk package * feat(CallIntegration): show Alert if outgoing call fails * fix(ConnectionService): alternatively get call UUID from the account Some Android flavours (or versions ?) do copy over extras to the onCreateOutgoingConnectionFailed callback. But the call UUID is also set as the PhoneAccount's label, so eventually it should be available there. * ref(ConnectionService): use call UUID as PhoneAccount ID. The extra is not reliable on some custom Android flavours. It also makes sense to use unique id for the account instead of the URL given that it's created on the per call basis. * fix(ConnectionService): abort the call when hold is requested Turns out Android P can sometimes request HOLD even though there's no HOLD capability added to the connection (what!?), so just abort the call in that case. * fix(ConnectionService): unregister account on call failure Unregister the PhoneAccount onCreateOutgoingConnectionFailed. That's before the ConnectionImpl instance is created which is normally responsible for doing that. * fix(AudioModeModule): make package private and run on the audio thread * address other review comments
2019-01-31 16:20:54 +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.
*
* 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,
android: add ConnectionService * feat(Android): implement ConnectionService Adds basic integration with Android's ConnectionService by implementing the outgoing call scenario. * ref(callkit): rename _SET_CALLKIT_SUBSCRIPTIONS * ref(callkit): move feature to call-integration directory * feat(ConnectionService): synchronize video state * ref(AudioMode): use ConnectionService on API >= 26 Not ready yet - few details left mentioned in the FIXMEs * feat(ConnectionService): add debug logs Adds logs to trace the calls. * fix(ConnectionService): leaking ConnectionImpl instances Turns out there is no callback fired back from the JavaScript side after the disconnect or abort event is sent from the native. The connection must be marked as disconnected and removed immediately. * feat(ConnectionService): handle onCreateOutgoingConnectionFailed * ref(ConnectionService): merge classes and move to the sdk package * feat(CallIntegration): show Alert if outgoing call fails * fix(ConnectionService): alternatively get call UUID from the account Some Android flavours (or versions ?) do copy over extras to the onCreateOutgoingConnectionFailed callback. But the call UUID is also set as the PhoneAccount's label, so eventually it should be available there. * ref(ConnectionService): use call UUID as PhoneAccount ID. The extra is not reliable on some custom Android flavours. It also makes sense to use unique id for the account instead of the URL given that it's created on the per call basis. * fix(ConnectionService): abort the call when hold is requested Turns out Android P can sometimes request HOLD even though there's no HOLD capability added to the connection (what!?), so just abort the call in that case. * fix(ConnectionService): unregister account on call failure Unregister the PhoneAccount onCreateOutgoingConnectionFailed. That's before the ConnectionImpl instance is created which is normally responsible for doing that. * fix(AudioModeModule): make package private and run on the audio thread * address other review comments
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-28 21:25:04 +00:00
export default CallKit;