2023-08-18 17:48:33 +00:00
|
|
|
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
2022-12-01 17:20:22 +00:00
|
|
|
import React from 'react';
|
2023-05-08 13:45:46 +00:00
|
|
|
import { BackHandler, Linking, NativeEventSubscription, SafeAreaView } from 'react-native';
|
2022-12-01 17:20:22 +00:00
|
|
|
import WebView from 'react-native-webview';
|
2023-05-08 13:45:46 +00:00
|
|
|
import { WebViewNavigation } from 'react-native-webview/lib/WebViewTypes';
|
2022-12-01 17:20:22 +00:00
|
|
|
|
|
|
|
import { IBaseScreen } from '../definitions';
|
2023-05-08 13:45:46 +00:00
|
|
|
import { userAgent } from '../lib/constants';
|
|
|
|
import { isIOS } from '../lib/methods/helpers';
|
2023-06-06 21:53:48 +00:00
|
|
|
import { getRoomIdFromJitsiCallUrl } from '../lib/methods/helpers/getRoomIdFromJitsiCall';
|
2022-12-01 17:20:22 +00:00
|
|
|
import { events, logEvent } from '../lib/methods/helpers/log';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { endVideoConfTimer, initVideoConfTimer } from '../lib/methods/videoConfTimer';
|
2022-12-01 17:20:22 +00:00
|
|
|
import { ChatsStackParamList } from '../stacks/types';
|
|
|
|
import { withTheme } from '../theme';
|
|
|
|
|
|
|
|
type TJitsiMeetViewProps = IBaseScreen<ChatsStackParamList, 'JitsiMeetView'>;
|
|
|
|
|
|
|
|
class JitsiMeetView extends React.Component<TJitsiMeetViewProps> {
|
|
|
|
private rid: string;
|
|
|
|
private url: string;
|
|
|
|
private videoConf: boolean;
|
|
|
|
private backHandler!: NativeEventSubscription;
|
|
|
|
|
|
|
|
constructor(props: TJitsiMeetViewProps) {
|
|
|
|
super(props);
|
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.url = props.route.params?.url;
|
|
|
|
this.videoConf = !!props.route.params?.videoConf;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2023-05-08 13:45:46 +00:00
|
|
|
this.handleJitsiApp();
|
2022-12-01 17:20:22 +00:00
|
|
|
this.onConferenceJoined();
|
2023-08-18 17:48:33 +00:00
|
|
|
activateKeepAwake();
|
2022-12-01 17:20:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
logEvent(this.videoConf ? events.LIVECHAT_VIDEOCONF_TERMINATE : events.JM_CONFERENCE_TERMINATE);
|
2023-03-01 18:26:56 +00:00
|
|
|
if (!this.videoConf) {
|
|
|
|
endVideoConfTimer();
|
2022-12-01 17:20:22 +00:00
|
|
|
}
|
2023-05-08 13:45:46 +00:00
|
|
|
if (this.backHandler) {
|
|
|
|
this.backHandler.remove();
|
|
|
|
}
|
2023-01-09 13:29:58 +00:00
|
|
|
deactivateKeepAwake();
|
2022-12-01 17:20:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-08 13:45:46 +00:00
|
|
|
handleJitsiApp = async () => {
|
|
|
|
const { route, navigation } = this.props;
|
|
|
|
const callUrl = route.params.url.replace(/^https?:\/\//, '');
|
|
|
|
try {
|
|
|
|
await Linking.openURL(`org.jitsi.meet://${callUrl}`);
|
|
|
|
navigation.pop();
|
|
|
|
} catch (error) {
|
|
|
|
// As the jitsi app was not opened disable the backhandler on android
|
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-01 17:20:22 +00:00
|
|
|
// Jitsi Update Timeout needs to be called every 10 seconds to make sure
|
|
|
|
// call is not ended and is available to web users.
|
|
|
|
onConferenceJoined = () => {
|
|
|
|
logEvent(this.videoConf ? events.LIVECHAT_VIDEOCONF_JOIN : events.JM_CONFERENCE_JOIN);
|
|
|
|
if (this.rid && !this.videoConf) {
|
2023-03-01 18:26:56 +00:00
|
|
|
initVideoConfTimer(this.rid);
|
2022-12-01 17:20:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-08 13:45:46 +00:00
|
|
|
onNavigationStateChange = (webViewState: WebViewNavigation) => {
|
2022-12-01 17:20:22 +00:00
|
|
|
const { navigation, route } = this.props;
|
2023-06-06 21:53:48 +00:00
|
|
|
|
|
|
|
const roomId = getRoomIdFromJitsiCallUrl(route.params.url);
|
|
|
|
|
|
|
|
if ((roomId && !webViewState.url.includes(roomId)) || webViewState.url.includes('close')) {
|
2023-05-08 13:45:46 +00:00
|
|
|
if (isIOS) {
|
|
|
|
if (webViewState.navigationType) {
|
|
|
|
navigation.pop();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
navigation.pop();
|
|
|
|
}
|
2022-12-01 17:20:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2023-06-06 21:53:48 +00:00
|
|
|
const uri = `${this.url}${this.url.includes('#config') ? '&' : '#'}config.disableDeepLinking=true`;
|
2022-12-01 17:20:22 +00:00
|
|
|
return (
|
2023-05-08 13:45:46 +00:00
|
|
|
<SafeAreaView style={{ flex: 1 }}>
|
|
|
|
<WebView
|
2023-06-06 21:53:48 +00:00
|
|
|
source={{ uri: uri.replace(/"/g, "'") }}
|
2023-05-08 13:45:46 +00:00
|
|
|
onNavigationStateChange={this.onNavigationStateChange}
|
2023-06-06 21:53:48 +00:00
|
|
|
// Jitsi default background color
|
|
|
|
style={{ flex: 1, backgroundColor: 'rgb(62,62,62)' }}
|
2023-05-08 13:45:46 +00:00
|
|
|
userAgent={userAgent}
|
|
|
|
javaScriptEnabled
|
|
|
|
domStorageEnabled
|
2023-07-17 16:22:29 +00:00
|
|
|
allowsInlineMediaPlayback
|
2023-06-06 21:53:48 +00:00
|
|
|
mediaCapturePermissionGrantType={'grant'}
|
2023-05-08 13:45:46 +00:00
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
2022-12-01 17:20:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withTheme(JitsiMeetView);
|