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';
|
2021-11-17 20:13:06 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
|
|
|
import { RouteProp } from '@react-navigation/native';
|
2019-09-25 22:13:39 +00:00
|
|
|
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
|
|
|
|
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';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { events, logEvent } from '../utils/log';
|
2021-08-30 14:27:02 +00:00
|
|
|
import { isAndroid, isIOS } from '../utils/deviceInfo';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../theme';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { InsideStackParamList } from '../stacks/types';
|
2022-04-07 16:27:45 +00:00
|
|
|
import { IApplicationState, IUser } from '../definitions';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../lib/services';
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2021-11-17 20:13:06 +00:00
|
|
|
const formatUrl = (url: string, baseUrl: string, uriSize: number, avatarAuthURLFragment: string) =>
|
2021-09-13 20:41:05 +00:00
|
|
|
`${baseUrl}/avatar/${url}?format=png&width=${uriSize}&height=${uriSize}${avatarAuthURLFragment}`;
|
2021-11-17 20:13:06 +00:00
|
|
|
|
|
|
|
interface IJitsiMeetViewState {
|
|
|
|
userInfo: {
|
|
|
|
displayName: string;
|
|
|
|
avatar: string;
|
|
|
|
};
|
|
|
|
loading: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IJitsiMeetViewProps {
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: StackNavigationProp<InsideStackParamList, 'JitsiMeetView'>;
|
|
|
|
route: RouteProp<InsideStackParamList, 'JitsiMeetView'>;
|
2021-11-17 20:13:06 +00:00
|
|
|
baseUrl: string;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-04-07 16:27:45 +00:00
|
|
|
user: IUser;
|
2021-11-17 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class JitsiMeetView extends React.Component<IJitsiMeetViewProps, IJitsiMeetViewState> {
|
|
|
|
private rid: string;
|
|
|
|
private url: string;
|
|
|
|
private jitsiTimeout: number | null;
|
2019-09-25 22:13:39 +00:00
|
|
|
|
2021-11-17 20:13:06 +00:00
|
|
|
constructor(props: IJitsiMeetViewProps) {
|
2019-09-25 22:13:39 +00:00
|
|
|
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;
|
2022-04-07 16:27:45 +00:00
|
|
|
const { name, id: userId, token, username } = user;
|
2021-09-13 20:41:05 +00:00
|
|
|
const avatarAuthURLFragment = `&rc_token=${token}&rc_uid=${userId}`;
|
2020-02-18 14:06:14 +00:00
|
|
|
const avatar = formatUrl(username, baseUrl, 100, avatarAuthURLFragment);
|
2021-08-30 14:27:02 +00:00
|
|
|
this.state = {
|
|
|
|
userInfo: {
|
2022-04-07 16:27:45 +00:00
|
|
|
displayName: name as string,
|
2020-02-18 14:06:14 +00:00
|
|
|
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 });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-08-30 14:27:02 +00:00
|
|
|
|
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);
|
2021-11-16 16:04:33 +00:00
|
|
|
if (this.rid) {
|
2022-04-28 20:37:25 +00:00
|
|
|
Services.updateJitsiTimeout(this.rid).catch((e: unknown) => console.log(e));
|
2021-11-16 16:04:33 +00:00
|
|
|
if (this.jitsiTimeout) {
|
|
|
|
BackgroundTimer.clearInterval(this.jitsiTimeout);
|
|
|
|
BackgroundTimer.stopBackgroundTimer();
|
|
|
|
this.jitsiTimeout = null;
|
|
|
|
}
|
|
|
|
this.jitsiTimeout = BackgroundTimer.setInterval(() => {
|
2022-04-28 20:37:25 +00:00
|
|
|
Services.updateJitsiTimeout(this.rid).catch((e: unknown) => console.log(e));
|
2021-11-16 16:04:33 +00:00
|
|
|
}, 10000);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-25 22:13:39 +00:00
|
|
|
|
|
|
|
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();
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-25 22:13:39 +00:00
|
|
|
|
|
|
|
render() {
|
2021-08-30 14:27:02 +00:00
|
|
|
const { userInfo, loading } = this.state;
|
2022-03-18 02:37:10 +00:00
|
|
|
const { route } = this.props;
|
2021-08-30 14:27:02 +00:00
|
|
|
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}
|
|
|
|
/>
|
2022-03-18 02:37:10 +00:00
|
|
|
{loading ? <ActivityIndicator /> : null}
|
2021-08-30 14:27:02 +00:00
|
|
|
</>
|
2019-09-25 22:13:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 16:27:45 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-02-18 14:06:14 +00:00
|
|
|
user: getUserSelector(state),
|
|
|
|
baseUrl: state.server.server
|
|
|
|
});
|
|
|
|
|
2021-08-30 14:27:02 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(JitsiMeetView));
|