Try Jitsi on webview on iOS

This commit is contained in:
Diego Mello 2023-04-12 15:19:38 -03:00
parent 1d4d5ef29d
commit 365558eb6c
6 changed files with 27 additions and 97 deletions

View File

@ -11,3 +11,4 @@ export * from './messageTypeLoad';
export * from './notifications';
export * from './defaultSettings';
export * from './tablet';
export * from './userAgent';

View File

@ -0,0 +1,5 @@
import { isIOS } from '../methods/helpers';
export const userAgent = isIOS
? 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1'
: 'Mozilla/5.0 (Linux; Android 12; SM-A315G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Mobile Safari/537.36';

View File

@ -9,15 +9,12 @@ import { RouteProp } from '@react-navigation/core';
import { OutsideModalParamList } from '../stacks/types';
import StatusBar from '../containers/StatusBar';
import ActivityIndicator from '../containers/ActivityIndicator';
import { debounce, isIOS } from '../lib/methods/helpers';
import { userAgent } from '../lib/constants';
import { debounce } from '../lib/methods/helpers';
import * as HeaderButton from '../containers/HeaderButton';
import { Services } from '../lib/services';
import { IApplicationState, ICredentials } from '../definitions';
const userAgent = isIOS
? 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1'
: 'Mozilla/5.0 (Linux; Android 12; SM-A315G) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Mobile Safari/537.36';
// iframe uses a postMessage to send the token to the client
// We'll handle this sending the token to the hash of the window.location
// https://docs.rocket.chat/guides/developer-guides/iframe-integration/authentication#iframe-url

View File

@ -1,5 +0,0 @@
import React from 'react';
declare const JitsiMeetView: React.SFC<>;
export default JitsiMeetView;

View File

@ -1,75 +0,0 @@
// @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';
// import RCActivityIndicator from '../containers/ActivityIndicator';
// import { useAppSelector } from '../lib/hooks';
// import { events, logEvent } from '../lib/methods/helpers/log';
// import { getUserSelector } from '../selectors/login';
// import { ChatsStackParamList } from '../stacks/types';
// import { endVideoConfTimer, initVideoConfTimer } from '../lib/methods/videoConfTimer';
// const formatUrl = (url: string, baseUrl: string, uriSize: number, avatarAuthURLFragment: string) =>
// `${baseUrl}/avatar/${url}?format=png&width=${uriSize}&height=${uriSize}${avatarAuthURLFragment}`;
// const JitsiMeetView = (): React.ReactElement => {
// const { goBack } = useNavigation();
// const {
// params: { url, onlyAudio, videoConf, rid }
// } = useRoute<RouteProp<ChatsStackParamList, 'JitsiMeetView'>>();
// const user = useAppSelector(state => getUserSelector(state));
// const baseUrl = useAppSelector(state => state.server.server);
// useEffect(() => {
// initJitsi();
// }, []);
// const initJitsi = async () => {
// const audioOnly = onlyAudio ?? false;
// const { name, id: userId, token, username } = user;
// const avatarAuthURLFragment = `&rc_token=${token}&rc_uid=${userId}`;
// const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment);
// const userInfo = {
// displayName: name as string,
// avatar
// };
// const regex = /(?:\/.*\/)(.*)/;
// const urlWithoutServer = regex.exec(url)![1];
// const serverUrl = url.replace(`/${urlWithoutServer}`, '');
// 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;
// const conferenceOptions = {
// room,
// serverUrl,
// userInfo: {
// displayName: userInfo.displayName,
// avatar: userInfo.avatar
// },
// subject: room,
// audioOnly,
// audioMuted: false,
// videoMuted: audioOnly,
// token: jwtToken,
// featureFlags: {
// 'calendar.enabled': false
// },
// configOverrides: {
// 'breakoutRooms.hideAddRoomButton': false
// }
// };
// logEvent(videoConf ? events.LIVECHAT_VIDEOCONF_JOIN : events.JM_CONFERENCE_JOIN);
// if (!videoConf) initVideoConfTimer(rid);
// await JitsiMeet.launchJitsiMeetView(conferenceOptions);
// logEvent(videoConf ? events.LIVECHAT_VIDEOCONF_TERMINATE : events.JM_CONFERENCE_TERMINATE);
// if (!videoConf) endVideoConfTimer();
// goBack();
// };
// return <RCActivityIndicator absolute size='large' />;
// };
// export default JitsiMeetView;
export default () => null;

View File

@ -6,6 +6,8 @@ import WebView from 'react-native-webview';
import { WebViewMessage, WebViewNavigation } from 'react-native-webview/lib/WebViewTypes';
import { IBaseScreen } from '../definitions';
import { userAgent } from '../lib/constants';
import { isAndroid } from '../lib/methods/helpers';
import { events, logEvent } from '../lib/methods/helpers/log';
import { endVideoConfTimer, initVideoConfTimer } from '../lib/methods/videoConfTimer';
import { ChatsStackParamList } from '../stacks/types';
@ -30,18 +32,20 @@ class JitsiMeetView extends React.Component<TJitsiMeetViewProps> {
componentDidMount() {
const { route, navigation } = this.props;
isAppInstalled(JITSI_INTENT)
.then(function (isInstalled) {
if (isInstalled) {
const callUrl = route.params.url.replace(/^https?:\/\//, '').split('#')[0];
openAppWithUri(`intent://${callUrl}#Intent;scheme=${JITSI_INTENT};package=${JITSI_INTENT};end`)
.then(() => navigation.pop())
.catch(() => {});
}
})
.catch(() => {});
if (isAndroid) {
isAppInstalled(JITSI_INTENT)
.then(function (isInstalled) {
if (isInstalled) {
const callUrl = route.params.url.replace(/^https?:\/\//, '').split('#')[0];
openAppWithUri(`intent://${callUrl}#Intent;scheme=${JITSI_INTENT};package=${JITSI_INTENT};end`)
.then(() => navigation.pop())
.catch(() => {});
}
})
.catch(() => {});
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => true);
}
this.onConferenceJoined();
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => true);
activateKeepAwake();
}
@ -50,7 +54,9 @@ class JitsiMeetView extends React.Component<TJitsiMeetViewProps> {
if (!this.videoConf) {
endVideoConfTimer();
}
this.backHandler.remove();
if (this.backHandler) {
this.backHandler.remove();
}
deactivateKeepAwake();
}
@ -81,6 +87,7 @@ class JitsiMeetView extends React.Component<TJitsiMeetViewProps> {
onMessage={({ nativeEvent }) => this.onNavigationStateChange(nativeEvent)}
onNavigationStateChange={this.onNavigationStateChange}
style={{ flex: 1 }}
userAgent={userAgent}
javaScriptEnabled
domStorageEnabled
mediaPlaybackRequiresUserAction={false}