2019-10-07 20:56:30 +00:00
|
|
|
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';
|
2020-02-19 19:43:47 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-10-07 20:56:30 +00:00
|
|
|
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2020-02-19 19:43:47 +00:00
|
|
|
import { getUserSelector } from '../selectors/login';
|
2019-10-07 20:56:30 +00:00
|
|
|
|
|
|
|
import sharedStyles from './Styles';
|
|
|
|
|
2020-02-19 19:43:47 +00:00
|
|
|
const formatUrl = (url, baseUrl, uriSize, avatarAuthURLFragment) => (
|
|
|
|
`${ baseUrl }/avatar/${ url }?format=png&width=${ uriSize }&height=${ uriSize }${ avatarAuthURLFragment }`
|
|
|
|
);
|
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
class JitsiMeetView extends React.Component {
|
|
|
|
static propTypes = {
|
2020-02-19 19:43:47 +00:00
|
|
|
navigation: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
token: PropTypes.string
|
|
|
|
})
|
2019-10-07 20:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.rid = props.navigation.getParam('rid');
|
|
|
|
this.onConferenceTerminated = this.onConferenceTerminated.bind(this);
|
|
|
|
this.onConferenceJoined = this.onConferenceJoined.bind(this);
|
|
|
|
this.jitsiTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-02-19 19:43:47 +00:00
|
|
|
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);
|
|
|
|
|
2019-10-07 20:56:30 +00:00
|
|
|
setTimeout(() => {
|
2020-02-19 19:43:47 +00:00
|
|
|
const userInfo = {
|
|
|
|
displayName,
|
|
|
|
avatar
|
|
|
|
};
|
2019-10-07 20:56:30 +00:00
|
|
|
const url = navigation.getParam('url');
|
|
|
|
const onlyAudio = navigation.getParam('onlyAudio', false);
|
|
|
|
if (onlyAudio) {
|
2020-02-19 19:43:47 +00:00
|
|
|
JitsiMeet.audioCall(url, userInfo);
|
2019-10-07 20:56:30 +00:00
|
|
|
} else {
|
2020-02-19 19:43:47 +00:00
|
|
|
JitsiMeet.call(url, userInfo);
|
2019-10-07 20:56:30 +00:00
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2019-12-11 23:01:12 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
}
|
|
|
|
JitsiMeet.endCall();
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:56:30 +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 = () => {
|
|
|
|
RocketChat.updateJitsiTimeout(this.rid).catch(e => console.log(e));
|
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
}
|
|
|
|
this.jitsiTimeout = BackgroundTimer.setInterval(() => {
|
|
|
|
RocketChat.updateJitsiTimeout(this.rid).catch(e => console.log(e));
|
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
onConferenceTerminated = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
}
|
|
|
|
navigation.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<RNJitsiMeetView
|
|
|
|
onConferenceTerminated={this.onConferenceTerminated}
|
|
|
|
onConferenceJoined={this.onConferenceJoined}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={sharedStyles.container}
|
2019-10-07 20:56:30 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 19:43:47 +00:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
user: getUserSelector(state),
|
|
|
|
baseUrl: state.server.server
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(JitsiMeetView);
|