2023-01-20 16:55:53 +00:00
|
|
|
// @ts-ignore
|
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
|
|
import JitsiMeet from '@socialcode-rob1/react-native-jitsimeet-custom';
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2022-12-01 17:20:22 +00:00
|
|
|
import RCActivityIndicator from '../containers/ActivityIndicator';
|
2023-01-20 16:55:53 +00:00
|
|
|
import { useAppSelector } from '../lib/hooks';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { events, logEvent } from '../lib/methods/helpers/log';
|
2022-12-01 17:20:22 +00:00
|
|
|
import { getUserSelector } from '../selectors/login';
|
|
|
|
import { ChatsStackParamList } from '../stacks/types';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2021-11-17 20:13:06 +00:00
|
|
|
const formatUrl = (url: string, baseUrl: string, uriSize: number, avatarAuthURLFragment: string) =>
|
2021-09-13 20:41:05 +00:00
|
|
|
`${baseUrl}/avatar/${url}?format=png&width=${uriSize}&height=${uriSize}${avatarAuthURLFragment}`;
|
2021-11-17 20:13:06 +00:00
|
|
|
|
2023-01-20 16:55:53 +00:00
|
|
|
const JitsiMeetView = (): React.ReactElement => {
|
|
|
|
const { goBack } = useNavigation();
|
|
|
|
const {
|
|
|
|
params: { url, onlyAudio, videoConf }
|
|
|
|
} = useRoute<RouteProp<ChatsStackParamList, 'JitsiMeetView'>>();
|
|
|
|
const user = useAppSelector(state => getUserSelector(state));
|
|
|
|
const baseUrl = useAppSelector(state => state.server.server);
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2023-01-20 16:55:53 +00:00
|
|
|
useEffect(() => {
|
|
|
|
initJitsi();
|
|
|
|
}, []);
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2023-01-20 16:55:53 +00:00
|
|
|
const initJitsi = async () => {
|
|
|
|
const audioOnly = onlyAudio ?? false;
|
2022-04-07 16:27:45 +00:00
|
|
|
const { name, id: userId, token, username } = user;
|
2021-09-13 20:41:05 +00:00
|
|
|
const avatarAuthURLFragment = `&rc_token=${token}&rc_uid=${userId}`;
|
2020-02-18 14:06:14 +00:00
|
|
|
const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment);
|
2023-01-20 16:55:53 +00:00
|
|
|
|
|
|
|
const userInfo = {
|
|
|
|
displayName: name as string,
|
|
|
|
avatar
|
|
|
|
};
|
|
|
|
const regex = /(?:\/.*\/)(.*)/;
|
|
|
|
const urlWithoutServer = regex.exec(url)![1];
|
|
|
|
const serverUrl = url.replace(`/${urlWithoutServer}`, '');
|
2023-01-30 16:56:39 +00:00
|
|
|
const room = (url.includes('jwt=') ? urlWithoutServer.split('jwt=')[0] : urlWithoutServer.split('#')[0]).replace('?', '');
|
|
|
|
const jwtToken = url.includes('jwt=') ? url.substring(url.indexOf('jwt=') + 4, url.lastIndexOf('#config')) : undefined;
|
2023-01-20 16:55:53 +00:00
|
|
|
const conferenceOptions = {
|
|
|
|
room,
|
|
|
|
serverUrl,
|
2021-08-30 14:27:02 +00:00
|
|
|
userInfo: {
|
2023-01-20 16:55:53 +00:00
|
|
|
displayName: userInfo.displayName,
|
|
|
|
avatar: userInfo.avatar
|
2021-08-30 14:27:02 +00:00
|
|
|
},
|
2023-01-20 16:55:53 +00:00
|
|
|
subject: room,
|
|
|
|
audioOnly,
|
|
|
|
audioMuted: false,
|
|
|
|
videoMuted: audioOnly,
|
2023-01-30 16:56:39 +00:00
|
|
|
token: jwtToken,
|
2023-01-20 16:55:53 +00:00
|
|
|
featureFlags: {
|
2023-01-30 16:56:39 +00:00
|
|
|
'calendar.enabled': false
|
2023-01-20 16:55:53 +00:00
|
|
|
},
|
|
|
|
configOverrides: {
|
2023-01-30 16:56:39 +00:00
|
|
|
'breakoutRooms.hideAddRoomButton': false
|
2021-11-16 16:04:33 +00:00
|
|
|
}
|
2023-01-20 16:55:53 +00:00
|
|
|
};
|
|
|
|
logEvent(videoConf ? events.LIVECHAT_VIDEOCONF_JOIN : events.JM_CONFERENCE_JOIN);
|
|
|
|
await JitsiMeet.launchJitsiMeetView(conferenceOptions);
|
|
|
|
logEvent(videoConf ? events.LIVECHAT_VIDEOCONF_TERMINATE : events.JM_CONFERENCE_TERMINATE);
|
|
|
|
goBack();
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2023-01-20 16:55:53 +00:00
|
|
|
return <RCActivityIndicator absolute size='large' />;
|
|
|
|
};
|
2020-02-18 14:06:14 +00:00
|
|
|
|
2023-01-20 16:55:53 +00:00
|
|
|
export default JitsiMeetView;
|