2017-08-18 10:54:05 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-03-20 13:51:51 +00:00
|
|
|
import { Alert } from 'react-native';
|
|
|
|
|
|
|
|
import { openSettings } from './functions';
|
2017-08-22 21:36:25 +00:00
|
|
|
|
|
|
|
import { isRoomValid } from '../../base/conference';
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
// TODO i18n
|
|
|
|
const deviceType = trackType === 'video' ? 'Camera' : 'Microphone';
|
|
|
|
|
2017-10-02 23:08:07 +00:00
|
|
|
/* eslint-disable indent */
|
|
|
|
|
|
|
|
const message
|
|
|
|
= `${deviceType
|
|
|
|
} permission is required to participate in conferences with ${
|
|
|
|
trackType}. Please grant it in Settings.`;
|
|
|
|
|
|
|
|
/* eslint-ensable indent */
|
|
|
|
|
2017-08-22 21:36:25 +00:00
|
|
|
Alert.alert(
|
|
|
|
'Permission required',
|
2017-10-02 23:08:07 +00:00
|
|
|
message,
|
2017-08-22 21:36:25 +00:00
|
|
|
[
|
|
|
|
{ text: 'Cancel' },
|
|
|
|
{
|
2018-03-20 13:51:51 +00:00
|
|
|
onPress: openSettings,
|
2017-08-22 21:36:25 +00:00
|
|
|
text: 'Settings'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{ cancelable: false });
|
|
|
|
}
|