2017-08-18 10:54:05 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-03-20 13:51:51 +00:00
|
|
|
import { Alert } from 'react-native';
|
|
|
|
|
2017-08-22 21:36:25 +00:00
|
|
|
import { isRoomValid } from '../../base/conference';
|
2021-06-28 12:11:12 +00:00
|
|
|
import { i18next } from '../../base/i18n';
|
2017-08-18 10:54:05 +00:00
|
|
|
import { MiddlewareRegistry } from '../../base/redux';
|
2017-11-09 21:59:31 +00:00
|
|
|
import { TRACK_CREATE_ERROR } from '../../base/tracks';
|
2017-08-18 10:54:05 +00:00
|
|
|
|
2020-05-20 10:57:03 +00:00
|
|
|
import { openSettings } from './functions';
|
|
|
|
|
2017-08-18 10:54:05 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures track permission errors and alerts the user so they
|
|
|
|
* can enable the permission themselves.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2017-08-22 21:36:25 +00:00
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2017-08-18 10:54:05 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2017-11-09 21:59:31 +00:00
|
|
|
case TRACK_CREATE_ERROR:
|
2017-08-22 21:36:25 +00:00
|
|
|
// XXX We do not currently have user interface outside of a conference
|
|
|
|
// which the user may tap and cause a permission-related error. If we
|
|
|
|
// alert whenever we (intend to) ask for a permission, the scenario of
|
|
|
|
// entering the WelcomePage, being asked for the camera permission, me
|
|
|
|
// denying it, and being alerted that there is an error is overwhelming
|
|
|
|
// me.
|
2017-11-09 21:59:31 +00:00
|
|
|
if (action.permissionDenied
|
|
|
|
&& isRoomValid(
|
|
|
|
store.getState()['features/base/conference'].room)) {
|
2017-08-22 21:36:25 +00:00
|
|
|
_alertPermissionErrorWithSettings(action.trackType);
|
|
|
|
}
|
2017-08-18 10:54:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
2017-08-22 21:36:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows an alert panel which tells the user they have to manually grant some
|
|
|
|
* permissions by opening Settings. A button which opens Settings is provided.
|
|
|
|
*
|
|
|
|
* @param {string} trackType - Type of track that failed with a permission
|
|
|
|
* error.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _alertPermissionErrorWithSettings(trackType) {
|
2017-10-02 23:08:07 +00:00
|
|
|
/* eslint-disable indent */
|
2021-06-28 12:11:12 +00:00
|
|
|
const message = trackType === 'video'
|
|
|
|
? i18next.t('dialog.permissionCameraRequiredError')
|
|
|
|
: i18next.t('dialog.permissionMicRequiredError');
|
2017-10-02 23:08:07 +00:00
|
|
|
/* eslint-ensable indent */
|
|
|
|
|
2017-08-22 21:36:25 +00:00
|
|
|
Alert.alert(
|
2021-06-28 12:11:12 +00:00
|
|
|
i18next.t('dialog.permissionErrorTitle'),
|
2017-10-02 23:08:07 +00:00
|
|
|
message,
|
2017-08-22 21:36:25 +00:00
|
|
|
[
|
2021-06-28 12:11:12 +00:00
|
|
|
{ text: i18next.t('dialog.Cancel') },
|
2017-08-22 21:36:25 +00:00
|
|
|
{
|
2018-03-20 13:51:51 +00:00
|
|
|
onPress: openSettings,
|
2021-06-28 12:11:12 +00:00
|
|
|
text: i18next.t('settings.title')
|
2017-08-22 21:36:25 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
{ cancelable: false });
|
|
|
|
}
|