feat: add user authentication cookies to JitsiMeetView (#5458)

* feat: add user authentication cookies to JitsiMeetView

* Update app/views/JitsiMeetView/index.tsx
This commit is contained in:
Gleidson Daniel Silva 2024-01-19 17:29:17 -03:00 committed by GitHub
parent 0f901686c6
commit a9abf322c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 64 additions and 14 deletions

View File

@ -1,14 +1,17 @@
import CookieManager from '@react-native-cookies/cookies';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake'; import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { BackHandler, Linking, SafeAreaView } from 'react-native'; import { ActivityIndicator, BackHandler, Linking, SafeAreaView, StyleSheet, View } from 'react-native';
import WebView from 'react-native-webview'; import WebView from 'react-native-webview';
import { userAgent } from '../../lib/constants'; import { userAgent } from '../../lib/constants';
import { useAppSelector } from '../../lib/hooks';
import { isIOS } from '../../lib/methods/helpers'; import { isIOS } from '../../lib/methods/helpers';
import { getRoomIdFromJitsiCallUrl } from '../../lib/methods/helpers/getRoomIdFromJitsiCall'; import { getRoomIdFromJitsiCallUrl } from '../../lib/methods/helpers/getRoomIdFromJitsiCall';
import { events, logEvent } from '../../lib/methods/helpers/log'; import { events, logEvent } from '../../lib/methods/helpers/log';
import { endVideoConfTimer, initVideoConfTimer } from '../../lib/methods/videoConfTimer'; import { endVideoConfTimer, initVideoConfTimer } from '../../lib/methods/videoConfTimer';
import { getUserSelector } from '../../selectors/login';
import { ChatsStackParamList } from '../../stacks/types'; import { ChatsStackParamList } from '../../stacks/types';
import JitsiAuthModal from './JitsiAuthModal'; import JitsiAuthModal from './JitsiAuthModal';
@ -17,8 +20,31 @@ const JitsiMeetView = (): React.ReactElement => {
params: { rid, url, videoConf } params: { rid, url, videoConf }
} = useRoute<RouteProp<ChatsStackParamList, 'JitsiMeetView'>>(); } = useRoute<RouteProp<ChatsStackParamList, 'JitsiMeetView'>>();
const { goBack } = useNavigation(); const { goBack } = useNavigation();
const user = useAppSelector(state => getUserSelector(state));
const serverUrl = useAppSelector(state => state.server.server);
const [authModal, setAuthModal] = useState(false); const [authModal, setAuthModal] = useState(false);
const [cookiesSet, setCookiesSet] = useState(false);
const setCookies = async () => {
const date = new Date();
date.setDate(date.getDate() + 1);
const expires = date.toISOString();
const domain = serverUrl.replace(/^https?:\/\//, '');
const ck = { domain, version: '1', expires };
await CookieManager.set(serverUrl, {
name: 'rc_uid',
value: user.id,
...ck
});
await CookieManager.set(serverUrl, {
name: 'rc_token',
value: user.token,
...ck
});
setCookiesSet(true);
};
const handleJitsiApp = useCallback(async () => { const handleJitsiApp = useCallback(async () => {
const callUrl = url.replace(/^https?:\/\//, ''); const callUrl = url.replace(/^https?:\/\//, '');
@ -71,25 +97,49 @@ const JitsiMeetView = (): React.ReactElement => {
}; };
}, [handleJitsiApp, onConferenceJoined, videoConf]); }, [handleJitsiApp, onConferenceJoined, videoConf]);
useEffect(() => {
setCookies();
}, []);
const callUrl = `${url}${url.includes('#config') ? '&' : '#'}config.disableDeepLinking=true`; const callUrl = `${url}${url.includes('#config') ? '&' : '#'}config.disableDeepLinking=true`;
return ( return (
<SafeAreaView style={{ flex: 1 }}> <SafeAreaView style={styles.container}>
{authModal && <JitsiAuthModal setAuthModal={setAuthModal} callUrl={callUrl} />} {authModal && <JitsiAuthModal setAuthModal={setAuthModal} callUrl={callUrl} />}
<WebView {cookiesSet ? (
source={{ uri: callUrl.replace(/"/g, "'") }} <WebView
onNavigationStateChange={onNavigationStateChange} source={{
onShouldStartLoadWithRequest={onNavigationStateChange} uri: callUrl.replace(/"/g, "'"),
style={{ flex: 1, backgroundColor: 'rgb(62,62,62)' }} headers: {
userAgent={userAgent} Cookie: `rc_uid=${user.id}; rc_token=${user.token}`
javaScriptEnabled }
domStorageEnabled }}
allowsInlineMediaPlayback onNavigationStateChange={onNavigationStateChange}
mediaCapturePermissionGrantType={'grant'} onShouldStartLoadWithRequest={onNavigationStateChange}
mediaPlaybackRequiresUserAction={isIOS} style={styles.webviewContainer}
/> userAgent={userAgent}
javaScriptEnabled
domStorageEnabled
allowsInlineMediaPlayback
mediaCapturePermissionGrantType={'grant'}
mediaPlaybackRequiresUserAction={isIOS}
sharedCookiesEnabled
/>
) : (
<View style={[styles.webviewContainer, styles.loading]}>
<ActivityIndicator />
</View>
)}
</SafeAreaView> </SafeAreaView>
); );
}; };
const styles = StyleSheet.create({
container: {
flex: 1
},
webviewContainer: { flex: 1, backgroundColor: 'rgb(62,62,62)' },
loading: { alignItems: 'center', justifyContent: 'center' }
});
export default JitsiMeetView; export default JitsiMeetView;