2023-01-16 13:17:52 +00:00
|
|
|
import { PermissionsAndroid, Permission } from 'react-native';
|
|
|
|
import DeviceInfo from 'react-native-device-info';
|
2022-12-01 17:20:22 +00:00
|
|
|
|
|
|
|
import i18n from '../../i18n';
|
2022-06-27 18:04:20 +00:00
|
|
|
import navigation from '../navigation/appNavigation';
|
|
|
|
import { Services } from '../services';
|
2022-12-01 17:20:22 +00:00
|
|
|
import { isAndroid, showErrorAlert } from './helpers';
|
2022-06-27 18:04:20 +00:00
|
|
|
import log from './helpers/log';
|
2022-12-01 17:20:22 +00:00
|
|
|
import openLink from './helpers/openLink';
|
2022-06-27 18:04:20 +00:00
|
|
|
|
2023-01-16 13:17:52 +00:00
|
|
|
const handleBltPermission = async (): Promise<Permission[]> => {
|
|
|
|
const systemVersion = await DeviceInfo.getApiLevel();
|
|
|
|
if (systemVersion <= 28) {
|
|
|
|
return [PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT, PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN];
|
|
|
|
}
|
|
|
|
if (systemVersion === 29) {
|
|
|
|
return [PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION];
|
|
|
|
}
|
|
|
|
return [PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION];
|
|
|
|
};
|
|
|
|
|
2023-07-04 00:03:39 +00:00
|
|
|
export const handleAndroidBltPermission = async (): Promise<void> => {
|
|
|
|
if (isAndroid) {
|
|
|
|
const bltPermission = await handleBltPermission();
|
|
|
|
await PermissionsAndroid.requestMultiple(bltPermission);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-24 12:46:58 +00:00
|
|
|
export const videoConfJoin = async (callId: string, cam?: boolean, mic?: boolean, fromPush?: boolean): Promise<void> => {
|
2022-06-27 18:04:20 +00:00
|
|
|
try {
|
2023-03-01 18:26:56 +00:00
|
|
|
const result = await Services.videoConferenceJoin(callId, cam, mic);
|
2022-06-27 18:04:20 +00:00
|
|
|
if (result.success) {
|
|
|
|
const { url, providerName } = result;
|
|
|
|
if (providerName === 'jitsi') {
|
|
|
|
navigation.navigate('JitsiMeetView', { url, onlyAudio: !cam, videoConf: true });
|
|
|
|
} else {
|
|
|
|
openLink(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-11-24 12:46:58 +00:00
|
|
|
if (fromPush) {
|
|
|
|
showErrorAlert(i18n.t('Missed_call'));
|
|
|
|
} else {
|
|
|
|
showErrorAlert(i18n.t('error-init-video-conf'));
|
|
|
|
}
|
2022-06-27 18:04:20 +00:00
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|