Rocket.Chat.ReactNative/app/lib/hooks/useVideoConf/StartACallActionSheet.tsx

107 lines
3.1 KiB
TypeScript
Raw Normal View History

feat: Add caller and ringer to video conf calls (#5046) * add expo camera and use camera on call init action sheet * fix permissions * set colors when calling * update @react-native-community/hooks lib * move to useWindowDimensions * create action to handle video-conf calls * create videoConf reducer * add typed-redux-saga lib * fix return * change videoConf saga to TS * fix TS target * update action and types * create actionSheetRef * add notifyUser api * export video conf types * add action prop * use new reducer prop * add videoConferenceCancel and add allowRinging to videoConferenceStart * temp-patch * add locales * add handler to videoconf message * fix rest types * add message types * path to remove component from dom * remove notification when is videoconf * create sound hook * create dots loader * update call translation * the end is near * move to confirmed * better code reading * fix call type * fix tests * update podfile * wip * fix call order * move colors * move to jsx * fix colors * add pt-br * remove patch and point * fix colors * fix expo camera * move to style * remove unused styles * update types and style * wip * rename IncomingCallComponent * add custom notification * wip * fix naming * fix styles * fix import * fix styles * change colors * fixa ringing * fix import * organize * fix sizes * use realName * fix spacing * fix icon size * fix header gap * changeColor * fix safeArea * set calling only on direct calls * change ringer to be a component * cancel call on swipe * remove join on direct calls * add props * update package
2023-07-04 00:03:39 +00:00
import { Camera, CameraType } from 'expo-camera';
import React, { useState } from 'react';
import { StyleSheet, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useDispatch } from 'react-redux';
import { useAppSelector } from '..';
import { cancelCall, initVideoCall } from '../../../actions/videoConf';
import AvatarContainer from '../../../containers/Avatar';
import Button from '../../../containers/Button';
import { CallHeader } from '../../../containers/CallHeader';
import Ringer, { ERingerSounds } from '../../../containers/Ringer';
import i18n from '../../../i18n';
import { getUserSelector } from '../../../selectors/login';
import { useTheme } from '../../../theme';
import { isIOS } from '../../methods/helpers';
import useUserData from '../useUserData';
export default function StartACallActionSheet({ rid }: { rid: string }): React.ReactElement {
const { colors } = useTheme();
const [mic, setMic] = useState(true);
const [cam, setCam] = useState(false);
const [containerWidth, setContainerWidth] = useState(0);
const username = useAppSelector(state => getUserSelector(state).username);
const calling = useAppSelector(state => state.videoConf.calling);
const dispatch = useDispatch();
const user = useUserData(rid);
// fix safe area bottom padding on iOS
const insets = useSafeAreaInsets();
const paddingBottom = isIOS && insets.bottom ? 8 : 0;
React.useEffect(
() => () => {
if (calling) {
dispatch(cancelCall({}));
}
},
[calling, dispatch]
);
return (
<View
style={[style.actionSheetContainer, { paddingBottom }]}
onLayout={e => setContainerWidth(e.nativeEvent.layout.width / 2)}
>
{calling ? <Ringer ringer={ERingerSounds.DIALTONE} /> : null}
<CallHeader
title={calling && user.direct ? i18n.t('Calling') : i18n.t('Start_a_call')}
cam={cam}
mic={mic}
setCam={setCam}
setMic={setMic}
avatar={user.avatar}
name={user.username}
uid={user.uid}
direct={user.direct}
/>
<View
style={[
style.actionSheetPhotoContainer,
{ backgroundColor: cam ? undefined : colors.conferenceCallPhotoBackground, width: containerWidth }
]}
>
{cam ? (
<Camera style={[style.cameraContainer, { width: containerWidth }]} type={CameraType.front} />
) : (
<AvatarContainer size={62} text={username} rid={rid} type={user.type} />
)}
</View>
<Button
backgroundColor={calling ? colors.conferenceCallCallBackButton : colors.actionTintColor}
color={calling ? colors.gray300 : colors.conferenceCallEnabledIcon}
onPress={() => {
if (calling) {
dispatch(cancelCall({}));
} else {
dispatch(initVideoCall({ cam, mic, direct: user.direct, rid, uid: user.uid }));
}
}}
title={calling ? i18n.t('Cancel') : i18n.t('Call')}
/>
</View>
);
}
const style = StyleSheet.create({
actionSheetContainer: {
paddingHorizontal: 24,
flex: 1
},
actionSheetPhotoContainer: {
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
flex: 1,
marginVertical: 8,
borderRadius: 8,
overflow: 'hidden'
},
cameraContainer: {
flex: 1
}
});