2019-09-25 22:13:39 +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-18 14:06:14 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
|
|
|
import RocketChat from '../lib/rocketchat';
|
2020-02-18 14:06:14 +00:00
|
|
|
import { getUserSelector } from '../selectors/login';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
|
|
|
import sharedStyles from './Styles';
|
2020-08-05 13:15:56 +00:00
|
|
|
import { logEvent, events } from '../utils/log';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2020-02-18 14:06:14 +00:00
|
|
|
const formatUrl = (url, baseUrl, uriSize, avatarAuthURLFragment) => (
|
|
|
|
`${ baseUrl }/avatar/${ url }?format=png&width=${ uriSize }&height=${ uriSize }${ avatarAuthURLFragment }`
|
|
|
|
);
|
|
|
|
|
2019-09-25 22:13:39 +00:00
|
|
|
class JitsiMeetView extends React.Component {
|
|
|
|
static propTypes = {
|
2020-02-18 14:06:14 +00:00
|
|
|
navigation: PropTypes.object,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object,
|
2020-02-18 14:06:14 +00:00
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
token: PropTypes.string
|
|
|
|
})
|
2019-09-25 22:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
2019-09-25 22:13:39 +00:00
|
|
|
this.onConferenceTerminated = this.onConferenceTerminated.bind(this);
|
|
|
|
this.onConferenceJoined = this.onConferenceJoined.bind(this);
|
|
|
|
this.jitsiTimeout = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { route, user, baseUrl } = this.props;
|
2020-02-18 14:06:14 +00:00
|
|
|
const {
|
|
|
|
name: displayName, id: userId, token, username
|
|
|
|
} = user;
|
|
|
|
|
|
|
|
const avatarAuthURLFragment = `&rc_token=${ token }&rc_uid=${ userId }`;
|
|
|
|
const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment);
|
|
|
|
|
2019-09-25 22:13:39 +00:00
|
|
|
setTimeout(() => {
|
2020-02-18 14:06:14 +00:00
|
|
|
const userInfo = {
|
|
|
|
displayName,
|
|
|
|
avatar
|
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
const url = route.params?.url;
|
|
|
|
const onlyAudio = route.params?.onlyAudio ?? false;
|
2019-09-25 22:13:39 +00:00
|
|
|
if (onlyAudio) {
|
2020-02-18 14:06:14 +00:00
|
|
|
JitsiMeet.audioCall(url, userInfo);
|
2019-09-25 22:13:39 +00:00
|
|
|
} else {
|
2020-02-18 14:06:14 +00:00
|
|
|
JitsiMeet.call(url, userInfo);
|
2019-09-25 22:13:39 +00:00
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2019-10-09 14:58:27 +00:00
|
|
|
componentWillUnmount() {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.JM_CONFERENCE_TERMINATE);
|
2019-10-09 14:58:27 +00:00
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
}
|
|
|
|
JitsiMeet.endCall();
|
|
|
|
}
|
|
|
|
|
2019-09-25 22:13:39 +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 = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.JM_CONFERENCE_JOIN);
|
2019-09-25 22:13:39 +00:00
|
|
|
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 = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.JM_CONFERENCE_TERMINATE);
|
2019-09-25 22:13:39 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
}
|
|
|
|
navigation.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<RNJitsiMeetView
|
|
|
|
onConferenceTerminated={this.onConferenceTerminated}
|
|
|
|
onConferenceJoined={this.onConferenceJoined}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={sharedStyles.container}
|
2019-09-25 22:13:39 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 14:06:14 +00:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
user: getUserSelector(state),
|
|
|
|
baseUrl: state.server.server
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(JitsiMeetView);
|