From aaca4ad2685183205ef006489f5fbc3c398e21d5 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 18 Feb 2020 11:06:14 -0300 Subject: [PATCH] [NEW] Jitsi JWT added to URL (#1746) --- app/constants/settings.js | 3 ++ app/lib/methods/callJitsi.js | 19 ++++++++- app/views/JitsiMeetView.js | 39 ++++++++++++++++--- ios/Podfile.lock | 4 +- .../react-native-jitsi-meet.podspec.json | 4 +- ios/Pods/Manifest.lock | 4 +- yarn.lock | 4 +- 7 files changed, 62 insertions(+), 15 deletions(-) diff --git a/app/constants/settings.js b/app/constants/settings.js index f812c5c6d..424317ad9 100644 --- a/app/constants/settings.js +++ b/app/constants/settings.js @@ -35,6 +35,9 @@ export default { Jitsi_Domain: { type: 'valueAsString' }, + Jitsi_Enabled_TokenAuth: { + type: 'valueAsBoolean' + }, Jitsi_URL_Room_Prefix: { type: 'valueAsString' }, diff --git a/app/lib/methods/callJitsi.js b/app/lib/methods/callJitsi.js index c7118d0e2..7e5d4cde5 100644 --- a/app/lib/methods/callJitsi.js +++ b/app/lib/methods/callJitsi.js @@ -17,10 +17,25 @@ const jitsiBaseUrl = ({ return `${ urlProtocol }${ urlDomain }${ prefix }${ uniqueIdentifier }`; }; -function callJitsi(rid, onlyAudio = false) { +async function callJitsi(rid, onlyAudio = false) { + let accessToken; + let queryString = ''; const { settings } = reduxStore.getState(); + const { Jitsi_Enabled_TokenAuth } = settings; - Navigation.navigate('JitsiMeetView', { url: `${ jitsiBaseUrl(settings) }${ rid }`, onlyAudio, rid }); + if (Jitsi_Enabled_TokenAuth) { + try { + accessToken = await this.sdk.methodCall('jitsi:generateAccessToken', rid); + } catch (e) { + // do nothing + } + } + + if (accessToken) { + queryString = `?jwt=${ accessToken }`; + } + + Navigation.navigate('JitsiMeetView', { url: `${ jitsiBaseUrl(settings) }${ rid }${ queryString }`, onlyAudio, rid }); } export default callJitsi; diff --git a/app/views/JitsiMeetView.js b/app/views/JitsiMeetView.js index 7dec8ebfc..c4fd3eaae 100644 --- a/app/views/JitsiMeetView.js +++ b/app/views/JitsiMeetView.js @@ -2,14 +2,27 @@ import React from 'react'; import PropTypes from 'prop-types'; import JitsiMeet, { JitsiMeetView as RNJitsiMeetView } from 'react-native-jitsi-meet'; import BackgroundTimer from 'react-native-background-timer'; +import { connect } from 'react-redux'; import RocketChat from '../lib/rocketchat'; +import { getUserSelector } from '../selectors/login'; import sharedStyles from './Styles'; +const formatUrl = (url, baseUrl, uriSize, avatarAuthURLFragment) => ( + `${ baseUrl }/avatar/${ url }?format=png&width=${ uriSize }&height=${ uriSize }${ avatarAuthURLFragment }` +); + class JitsiMeetView extends React.Component { static propTypes = { - navigation: PropTypes.object + navigation: PropTypes.object, + baseUrl: PropTypes.string, + user: PropTypes.shape({ + id: PropTypes.string, + username: PropTypes.string, + name: PropTypes.string, + token: PropTypes.string + }) } constructor(props) { @@ -21,14 +34,25 @@ class JitsiMeetView extends React.Component { } componentDidMount() { - const { navigation } = this.props; + const { navigation, user, baseUrl } = this.props; + const { + name: displayName, id: userId, token, username + } = user; + + const avatarAuthURLFragment = `&rc_token=${ token }&rc_uid=${ userId }`; + const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment); + setTimeout(() => { + const userInfo = { + displayName, + avatar + }; const url = navigation.getParam('url'); const onlyAudio = navigation.getParam('onlyAudio', false); if (onlyAudio) { - JitsiMeet.audioCall(url); + JitsiMeet.audioCall(url, userInfo); } else { - JitsiMeet.call(url); + JitsiMeet.call(url, userInfo); } }, 1000); } @@ -71,4 +95,9 @@ class JitsiMeetView extends React.Component { } } -export default JitsiMeetView; +const mapStateToProps = state => ({ + user: getUserSelector(state), + baseUrl: state.server.server +}); + +export default connect(mapStateToProps)(JitsiMeetView); diff --git a/ios/Podfile.lock b/ios/Podfile.lock index c0bec2f56..945ba9f5a 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -296,7 +296,7 @@ PODS: - React - react-native-document-picker (3.2.4): - React - - react-native-jitsi-meet (2.0.4): + - react-native-jitsi-meet (2.1.0): - JitsiMeetSDK - React - react-native-keyboard-input (5.3.1): @@ -753,7 +753,7 @@ SPEC CHECKSUMS: react-native-background-timer: 1b6e6b4e10f1b74c367a1fdc3c72b67c619b222b react-native-cameraroll: 463aff54e37cff27ea76eb792e6f1fa43b876320 react-native-document-picker: c36bf5f067a581657ecaf7124dcd921a8be19061 - react-native-jitsi-meet: 5bc06e8b65a7d04fd3705d5720f3b2ec66e49a29 + react-native-jitsi-meet: 04ccc47303c62ba2b7e7407a113f5f46241ebd75 react-native-keyboard-input: 2a01e0aceac330592bbe9b3101761bb9d8e6d1fb react-native-keyboard-tracking-view: 4bb67b89ccd327c7d9eab87f722880d2103a25a8 react-native-notifications: 163ddedac6fcc8d850ea15b06abdadcacdff00f1 diff --git a/ios/Pods/Local Podspecs/react-native-jitsi-meet.podspec.json b/ios/Pods/Local Podspecs/react-native-jitsi-meet.podspec.json index 271c00e8d..14e722514 100644 --- a/ios/Pods/Local Podspecs/react-native-jitsi-meet.podspec.json +++ b/ios/Pods/Local Podspecs/react-native-jitsi-meet.podspec.json @@ -1,6 +1,6 @@ { "name": "react-native-jitsi-meet", - "version": "2.0.4", + "version": "2.1.0", "summary": "Jitsi Meet SDK wrapper for React Native.", "license": "Apache-2.0", "authors": { @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/skrafft/react-native-jitsi-meet.git", - "tag": "v2.0.4" + "tag": "v2.1.0" }, "source_files": "ios/**/*.{h,m}", "dependencies": { diff --git a/ios/Pods/Manifest.lock b/ios/Pods/Manifest.lock index c0bec2f56..945ba9f5a 100644 --- a/ios/Pods/Manifest.lock +++ b/ios/Pods/Manifest.lock @@ -296,7 +296,7 @@ PODS: - React - react-native-document-picker (3.2.4): - React - - react-native-jitsi-meet (2.0.4): + - react-native-jitsi-meet (2.1.0): - JitsiMeetSDK - React - react-native-keyboard-input (5.3.1): @@ -753,7 +753,7 @@ SPEC CHECKSUMS: react-native-background-timer: 1b6e6b4e10f1b74c367a1fdc3c72b67c619b222b react-native-cameraroll: 463aff54e37cff27ea76eb792e6f1fa43b876320 react-native-document-picker: c36bf5f067a581657ecaf7124dcd921a8be19061 - react-native-jitsi-meet: 5bc06e8b65a7d04fd3705d5720f3b2ec66e49a29 + react-native-jitsi-meet: 04ccc47303c62ba2b7e7407a113f5f46241ebd75 react-native-keyboard-input: 2a01e0aceac330592bbe9b3101761bb9d8e6d1fb react-native-keyboard-tracking-view: 4bb67b89ccd327c7d9eab87f722880d2103a25a8 react-native-notifications: 163ddedac6fcc8d850ea15b06abdadcacdff00f1 diff --git a/yarn.lock b/yarn.lock index eedb4bd28..5891687ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9493,8 +9493,8 @@ react-native-iphone-x-helper@^1.0.3: integrity sha512-xIeTo4s77wwKgBZLVRIZC9tM9/PkXS46Ul76NXmvmixEb3ZwqGdQesR3zRiLMOoIdfOURB6N9bba9po7+x9Bag== react-native-jitsi-meet@RocketChat/react-native-jitsi-meet: - version "2.0.4" - resolved "https://codeload.github.com/RocketChat/react-native-jitsi-meet/tar.gz/5f535b301d18a26860e2e04ca5b164a564184b48" + version "2.1.0" + resolved "https://codeload.github.com/RocketChat/react-native-jitsi-meet/tar.gz/351789a80ba5c05f27b702e69d3354f0e3651a49" react-native-keyboard-aware-scroll-view@0.9.1: version "0.9.1"