mirror of https://github.com/jitsi/jitsi-meet
parent
9bca0e3b3d
commit
26f0f7f89c
@ -0,0 +1,44 @@ |
||||
/** |
||||
* Adapted from |
||||
* {@link https://github.com/Aleksandern/react-native-android-settings-library}.
|
||||
*/ |
||||
|
||||
package org.jitsi.meet.sdk; |
||||
|
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.net.Uri; |
||||
import android.provider.Settings; |
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext; |
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule; |
||||
import com.facebook.react.bridge.ReactMethod; |
||||
|
||||
class AndroidSettingsModule extends ReactContextBaseJavaModule { |
||||
/** |
||||
* React Native module name. |
||||
*/ |
||||
private static final String MODULE_NAME = "AndroidSettings"; |
||||
|
||||
public AndroidSettingsModule(ReactApplicationContext reactContext) { |
||||
super(reactContext); |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return MODULE_NAME; |
||||
} |
||||
|
||||
@ReactMethod |
||||
public void open() { |
||||
Context context = getReactApplicationContext(); |
||||
Intent intent = new Intent(); |
||||
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
||||
intent.setData( |
||||
Uri.fromParts("package", context.getPackageName(), null)); |
||||
|
||||
context.startActivity(intent); |
||||
} |
||||
} |
@ -0,0 +1,47 @@ |
||||
import { Alert, Linking, NativeModules } from 'react-native'; |
||||
|
||||
import { Platform } from '../../base/react'; |
||||
|
||||
/** |
||||
* 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. |
||||
* |
||||
* FIXME: translate. |
||||
* |
||||
* @param {string} trackType - Type of track that failed with a permission |
||||
* error. |
||||
* @returns {void} |
||||
*/ |
||||
export function alertPermissionErrorWithSettings(trackType) { |
||||
const type = trackType === 'video' ? 'Camera' : 'Microphone'; |
||||
|
||||
Alert.alert( |
||||
'Permissions Error', |
||||
`${type} permission is required, please enable it in Settings.`, |
||||
[ |
||||
{ text: 'Cancel' }, |
||||
{ |
||||
onPress: _openSettings, |
||||
text: 'Settings' |
||||
} |
||||
], |
||||
{ cancelable: false }); |
||||
} |
||||
|
||||
/** |
||||
* Opens the settings panel for the current platform. |
||||
* |
||||
* @private |
||||
* @returns {void} |
||||
*/ |
||||
function _openSettings() { |
||||
switch (Platform.OS) { |
||||
case 'android': |
||||
NativeModules.AndroidSettings.open(); |
||||
break; |
||||
|
||||
case 'ios': |
||||
Linking.openURL('app-settings:'); |
||||
break; |
||||
} |
||||
} |
@ -0,0 +1 @@ |
||||
import './middleware'; |
@ -0,0 +1,25 @@ |
||||
/* @flow */ |
||||
|
||||
import { MiddlewareRegistry } from '../../base/redux'; |
||||
import { TRACK_PERMISSION_ERROR } from '../../base/tracks'; |
||||
|
||||
import { alertPermissionErrorWithSettings } from './functions'; |
||||
|
||||
/** |
||||
* 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} |
||||
*/ |
||||
MiddlewareRegistry.register(() => next => action => { |
||||
const result = next(action); |
||||
|
||||
switch (action.type) { |
||||
case TRACK_PERMISSION_ERROR: |
||||
alertPermissionErrorWithSettings(action.trackType); |
||||
break; |
||||
} |
||||
|
||||
return result; |
||||
}); |
Loading…
Reference in new issue