Skip to content

Commit

Permalink
[NEW] Jitsi JWT added to URL (#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
djorkaeffalexandre authored Feb 18, 2020
1 parent 270ec79 commit aaca4ad
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default {
Jitsi_Domain: {
type: 'valueAsString'
},
Jitsi_Enabled_TokenAuth: {
type: 'valueAsBoolean'
},
Jitsi_URL_Room_Prefix: {
type: 'valueAsString'
},
Expand Down
19 changes: 17 additions & 2 deletions app/lib/methods/callJitsi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
39 changes: 34 additions & 5 deletions app/views/JitsiMeetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ios/Pods/Local Podspecs/react-native-jitsi-meet.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ios/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
version "0.9.1"
Expand Down

0 comments on commit aaca4ad

Please sign in to comment.