2019-09-25 22:13:39 +00:00
|
|
|
import React from 'react';
|
2021-08-30 14:27:02 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
2019-09-25 22:13:39 +00:00
|
|
|
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';
|
2021-08-30 14:27:02 +00:00
|
|
|
import ActivityIndicator from '../containers/ActivityIndicator';
|
2020-08-05 13:15:56 +00:00
|
|
|
import { logEvent, events } from '../utils/log';
|
2021-08-30 14:27:02 +00:00
|
|
|
import { isAndroid, isIOS } from '../utils/deviceInfo';
|
|
|
|
import { withTheme } from '../theme';
|
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,
|
2021-08-30 14:27:02 +00:00
|
|
|
theme: PropTypes.string,
|
2020-02-18 14:06:14 +00:00
|
|
|
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;
|
2021-08-30 14:27:02 +00:00
|
|
|
this.url = props.route.params?.url;
|
2019-09-25 22:13:39 +00:00
|
|
|
this.jitsiTimeout = null;
|
|
|
|
|
2021-08-30 14:27:02 +00:00
|
|
|
const { user, baseUrl } = 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);
|
2021-08-30 14:27:02 +00:00
|
|
|
this.state = {
|
|
|
|
userInfo: {
|
2020-02-18 14:06:14 +00:00
|
|
|
displayName,
|
|
|
|
avatar
|
2021-08-30 14:27:02 +00:00
|
|
|
},
|
|
|
|
loading: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { route } = this.props;
|
|
|
|
const { userInfo } = this.state;
|
|
|
|
|
|
|
|
if (isIOS) {
|
|
|
|
setTimeout(() => {
|
|
|
|
const onlyAudio = route.params?.onlyAudio ?? false;
|
|
|
|
if (onlyAudio) {
|
|
|
|
JitsiMeet.audioCall(this.url, userInfo);
|
|
|
|
} else {
|
|
|
|
JitsiMeet.call(this.url, userInfo);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
2019-09-25 22:13:39 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2021-08-30 14:27:02 +00:00
|
|
|
this.jitsiTimeout = null;
|
|
|
|
BackgroundTimer.stopBackgroundTimer();
|
2019-10-09 14:58:27 +00:00
|
|
|
}
|
|
|
|
JitsiMeet.endCall();
|
|
|
|
}
|
|
|
|
|
2021-08-30 14:27:02 +00:00
|
|
|
onConferenceWillJoin = () => {
|
|
|
|
this.setState({ loading: false });
|
|
|
|
}
|
|
|
|
|
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);
|
2021-08-30 14:27:02 +00:00
|
|
|
BackgroundTimer.stopBackgroundTimer();
|
|
|
|
this.jitsiTimeout = null;
|
2019-09-25 22:13:39 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
navigation.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-08-30 14:27:02 +00:00
|
|
|
const { userInfo, loading } = this.state;
|
|
|
|
const { route, theme } = this.props;
|
|
|
|
const onlyAudio = route.params?.onlyAudio ?? false;
|
|
|
|
const options = isAndroid ? { url: this.url, userInfo, audioOnly: onlyAudio } : null;
|
2019-09-25 22:13:39 +00:00
|
|
|
return (
|
2021-08-30 14:27:02 +00:00
|
|
|
<>
|
|
|
|
<RNJitsiMeetView
|
|
|
|
onConferenceWillJoin={this.onConferenceWillJoin}
|
|
|
|
onConferenceTerminated={this.onConferenceTerminated}
|
|
|
|
onConferenceJoined={this.onConferenceJoined}
|
|
|
|
style={StyleSheet.absoluteFill}
|
|
|
|
options={options}
|
|
|
|
/>
|
|
|
|
{loading ? <ActivityIndicator theme={theme} /> : null}
|
|
|
|
</>
|
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
|
|
|
|
});
|
|
|
|
|
2021-08-30 14:27:02 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(JitsiMeetView));
|