diff --git a/app/lib/constants/index.ts b/app/lib/constants/index.ts index 1d8d67b30..32fb814f9 100644 --- a/app/lib/constants/index.ts +++ b/app/lib/constants/index.ts @@ -11,3 +11,4 @@ export * from './messageTypeLoad'; export * from './notifications'; export * from './defaultSettings'; export * from './tablet'; +export * from './userAgent'; diff --git a/app/lib/constants/userAgent.ts b/app/lib/constants/userAgent.ts new file mode 100644 index 000000000..f550b8948 --- /dev/null +++ b/app/lib/constants/userAgent.ts @@ -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'; diff --git a/app/views/AuthenticationWebView.tsx b/app/views/AuthenticationWebView.tsx index 30b8ff190..69fb2cd72 100644 --- a/app/views/AuthenticationWebView.tsx +++ b/app/views/AuthenticationWebView.tsx @@ -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 diff --git a/app/views/JitsiMeetView.d.ts b/app/views/JitsiMeetView.d.ts deleted file mode 100644 index c1ad42e90..000000000 --- a/app/views/JitsiMeetView.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react'; - -declare const JitsiMeetView: React.SFC<>; - -export default JitsiMeetView; diff --git a/app/views/JitsiMeetView.ios.tsx b/app/views/JitsiMeetView.ios.tsx deleted file mode 100644 index 39b18ec7f..000000000 --- a/app/views/JitsiMeetView.ios.tsx +++ /dev/null @@ -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>(); -// 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 ; -// }; - -// export default JitsiMeetView; -export default () => null; diff --git a/app/views/JitsiMeetView.android.tsx b/app/views/JitsiMeetView.tsx similarity index 79% rename from app/views/JitsiMeetView.android.tsx rename to app/views/JitsiMeetView.tsx index 45265494d..54ec76278 100644 --- a/app/views/JitsiMeetView.android.tsx +++ b/app/views/JitsiMeetView.tsx @@ -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 { 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 { if (!this.videoConf) { endVideoConfTimer(); } - this.backHandler.remove(); + if (this.backHandler) { + this.backHandler.remove(); + } deactivateKeepAwake(); } @@ -81,6 +87,7 @@ class JitsiMeetView extends React.Component { onMessage={({ nativeEvent }) => this.onNavigationStateChange(nativeEvent)} onNavigationStateChange={this.onNavigationStateChange} style={{ flex: 1 }} + userAgent={userAgent} javaScriptEnabled domStorageEnabled mediaPlaybackRequiresUserAction={false}