2017-10-04 22:36:09 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-07-09 07:17:23 +00:00
|
|
|
import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random';
|
2017-09-05 22:45:20 +00:00
|
|
|
import { Component } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2018-02-26 21:37:27 +00:00
|
|
|
import { createWelcomePageEvent, sendAnalytics } from '../../analytics';
|
2020-06-04 14:09:13 +00:00
|
|
|
import { appNavigate } from '../../app/actions';
|
2022-12-20 17:03:57 +00:00
|
|
|
import { IDeeplinkingConfig } from '../../base/config/configType';
|
2020-05-18 12:07:09 +00:00
|
|
|
import isInsecureRoomName from '../../base/util/isInsecureRoomName';
|
2019-05-28 13:32:29 +00:00
|
|
|
import { isCalendarEnabled } from '../../calendar-sync';
|
2020-03-31 11:06:04 +00:00
|
|
|
import { isRecentListEnabled } from '../../recent-list/functions';
|
2017-04-14 18:08:54 +00:00
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
/**
|
|
|
|
* {@code AbstractWelcomePage}'s React {@code Component} prop types.
|
|
|
|
*/
|
2021-11-11 14:32:56 +00:00
|
|
|
export type Props = {
|
2018-02-02 14:50:16 +00:00
|
|
|
|
2019-05-28 13:32:29 +00:00
|
|
|
/**
|
|
|
|
* Whether the calendar functionality is enabled or not.
|
|
|
|
*/
|
|
|
|
_calendarEnabled: boolean,
|
|
|
|
|
2022-12-20 17:03:57 +00:00
|
|
|
/**
|
|
|
|
* The deeplinking config.
|
|
|
|
*/
|
|
|
|
_deeplinkingCfg: IDeeplinkingConfig,
|
|
|
|
|
2020-05-27 22:12:06 +00:00
|
|
|
/**
|
|
|
|
* Whether the insecure room name functionality is enabled or not.
|
|
|
|
*/
|
|
|
|
_enableInsecureRoomNameWarning: boolean,
|
|
|
|
|
2020-06-29 12:17:35 +00:00
|
|
|
/**
|
|
|
|
* URL for the moderated rooms microservice, if available.
|
|
|
|
*/
|
|
|
|
_moderatedRoomServiceUrl: ?string,
|
|
|
|
|
2020-03-31 11:06:04 +00:00
|
|
|
/**
|
2021-11-04 21:10:43 +00:00
|
|
|
* Whether the recent list is enabled.
|
2020-03-31 11:06:04 +00:00
|
|
|
*/
|
|
|
|
_recentListEnabled: Boolean,
|
|
|
|
|
2018-02-02 14:50:16 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* Room name to join to.
|
2018-02-02 14:50:16 +00:00
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
_room: string,
|
2018-04-12 19:58:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current settings.
|
|
|
|
*/
|
|
|
|
_settings: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux dispatch Function.
|
|
|
|
*/
|
2019-03-19 15:42:25 +00:00
|
|
|
dispatch: Dispatch<any>
|
2017-10-04 22:36:09 +00:00
|
|
|
};
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Base (abstract) class for container component rendering the welcome page.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
2021-11-11 14:32:56 +00:00
|
|
|
export class AbstractWelcomePage<P: Props> extends Component<P, *> {
|
2017-10-04 22:36:09 +00:00
|
|
|
_mounted: ?boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save room name into component's local state.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
* @property {number|null} animateTimeoutId - Identifier of the letter
|
|
|
|
* animation timeout.
|
|
|
|
* @property {string} generatedRoomname - Automatically generated room name.
|
|
|
|
* @property {string} room - Room name.
|
|
|
|
* @property {string} roomPlaceholder - Room placeholder that's used as a
|
|
|
|
* placeholder for input.
|
2021-03-16 15:59:33 +00:00
|
|
|
* @property {number|null} updateTimeoutId - Identifier of the timeout
|
2017-10-04 22:36:09 +00:00
|
|
|
* updating the generated room name.
|
|
|
|
*/
|
|
|
|
state = {
|
|
|
|
animateTimeoutId: undefined,
|
|
|
|
generatedRoomname: '',
|
2020-05-18 12:07:09 +00:00
|
|
|
insecureRoomName: false,
|
2017-10-04 22:36:09 +00:00
|
|
|
joining: false,
|
|
|
|
room: '',
|
|
|
|
roomPlaceholder: '',
|
|
|
|
updateTimeoutId: undefined
|
|
|
|
};
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-07-19 21:25:06 +00:00
|
|
|
* Initializes a new {@code AbstractWelcomePage} instance.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-10-04 22:36:09 +00:00
|
|
|
* @param {Props} props - The React {@code Component} props to initialize
|
2017-07-19 21:25:06 +00:00
|
|
|
* the new {@code AbstractWelcomePage} instance with.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2021-11-11 14:32:56 +00:00
|
|
|
constructor(props: P) {
|
2016-10-05 14:36:59 +00:00
|
|
|
super(props);
|
|
|
|
|
2017-07-19 21:25:06 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2016-12-16 03:00:06 +00:00
|
|
|
this._animateRoomnameChanging
|
|
|
|
= this._animateRoomnameChanging.bind(this);
|
2016-12-01 18:55:42 +00:00
|
|
|
this._onJoin = this._onJoin.bind(this);
|
2016-10-05 14:36:59 +00:00
|
|
|
this._onRoomChange = this._onRoomChange.bind(this);
|
2020-05-18 12:07:09 +00:00
|
|
|
this._renderInsecureRoomNameWarning = this._renderInsecureRoomNameWarning.bind(this);
|
2016-12-01 18:55:42 +00:00
|
|
|
this._updateRoomname = this._updateRoomname.bind(this);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-29 02:11:10 +00:00
|
|
|
* Implements React's {@link Component#componentDidMount()}. Invoked
|
|
|
|
* immediately after mounting occurs.
|
2017-09-14 09:46:35 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-10-29 02:11:10 +00:00
|
|
|
componentDidMount() {
|
2017-09-14 09:46:35 +00:00
|
|
|
this._mounted = true;
|
2019-11-28 14:03:34 +00:00
|
|
|
sendAnalytics(createWelcomePageEvent('viewed', undefined, { value: 1 }));
|
2017-09-14 09:46:35 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 18:55:42 +00:00
|
|
|
/**
|
2017-09-14 09:46:35 +00:00
|
|
|
* Implements React's {@link Component#componentWillUnmount()}. Invoked
|
|
|
|
* immediately before this component is unmounted and destroyed.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2016-12-16 03:00:06 +00:00
|
|
|
* @inheritdoc
|
2016-12-01 18:55:42 +00:00
|
|
|
*/
|
2016-12-16 03:00:06 +00:00
|
|
|
componentWillUnmount() {
|
2016-12-01 18:55:42 +00:00
|
|
|
this._clearTimeouts();
|
2017-09-14 09:46:35 +00:00
|
|
|
this._mounted = false;
|
2016-12-01 18:55:42 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_animateRoomnameChanging: (string) => void;
|
|
|
|
|
2016-12-01 18:55:42 +00:00
|
|
|
/**
|
2016-12-16 03:00:06 +00:00
|
|
|
* Animates the changing of the room name.
|
2016-12-01 18:55:42 +00:00
|
|
|
*
|
2016-12-16 03:00:06 +00:00
|
|
|
* @param {string} word - The part of room name that should be added to
|
|
|
|
* placeholder.
|
2016-12-01 18:55:42 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
_animateRoomnameChanging(word: string) {
|
|
|
|
let animateTimeoutId;
|
2016-12-16 03:00:06 +00:00
|
|
|
const roomPlaceholder = this.state.roomPlaceholder + word.substr(0, 1);
|
2016-12-01 18:55:42 +00:00
|
|
|
|
|
|
|
if (word.length > 1) {
|
2016-12-16 03:00:06 +00:00
|
|
|
animateTimeoutId
|
|
|
|
= setTimeout(
|
2017-06-15 00:40:51 +00:00
|
|
|
() => {
|
|
|
|
this._animateRoomnameChanging(
|
|
|
|
word.substring(1, word.length));
|
|
|
|
},
|
|
|
|
70);
|
2016-12-01 18:55:42 +00:00
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
animateTimeoutId,
|
|
|
|
roomPlaceholder
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-16 03:00:06 +00:00
|
|
|
/**
|
|
|
|
* Method that clears timeouts for animations and updates of room name.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_clearTimeouts() {
|
|
|
|
clearTimeout(this.state.animateTimeoutId);
|
|
|
|
clearTimeout(this.state.updateTimeoutId);
|
|
|
|
}
|
|
|
|
|
2020-05-18 12:07:09 +00:00
|
|
|
/**
|
|
|
|
* Renders the insecure room name warning.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_doRenderInsecureRoomNameWarning: () => React$Component<any>;
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_onJoin: () => void;
|
|
|
|
|
2016-12-01 18:55:42 +00:00
|
|
|
/**
|
|
|
|
* Handles joining. Either by clicking on 'Join' button
|
|
|
|
* or by pressing 'Enter' in room name input field.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2016-12-01 18:55:42 +00:00
|
|
|
_onJoin() {
|
2016-12-16 03:00:06 +00:00
|
|
|
const room = this.state.room || this.state.generatedRoomname;
|
2016-12-01 18:55:42 +00:00
|
|
|
|
2018-02-26 21:37:27 +00:00
|
|
|
sendAnalytics(
|
|
|
|
createWelcomePageEvent('clicked', 'joinButton', {
|
|
|
|
isGenerated: !this.state.room,
|
|
|
|
room
|
|
|
|
}));
|
|
|
|
|
2017-09-14 09:46:35 +00:00
|
|
|
if (room) {
|
|
|
|
this.setState({ joining: true });
|
|
|
|
|
|
|
|
// By the time the Promise of appNavigate settles, this component
|
|
|
|
// may have already been unmounted.
|
2017-10-04 22:36:09 +00:00
|
|
|
const onAppNavigateSettled
|
|
|
|
= () => this._mounted && this.setState({ joining: false });
|
2017-09-14 09:46:35 +00:00
|
|
|
|
2019-10-04 07:31:22 +00:00
|
|
|
this.props.dispatch(appNavigate(room))
|
2017-09-14 09:46:35 +00:00
|
|
|
.then(onAppNavigateSettled, onAppNavigateSettled);
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_onRoomChange: (string) => void;
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Handles 'change' event for the room name text input field.
|
|
|
|
*
|
|
|
|
* @param {string} value - The text typed into the respective text input
|
|
|
|
* field.
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
_onRoomChange(value: string) {
|
2020-05-18 12:07:09 +00:00
|
|
|
this.setState({
|
|
|
|
room: value,
|
2020-05-27 22:12:06 +00:00
|
|
|
insecureRoomName: this.props._enableInsecureRoomNameWarning && value && isInsecureRoomName(value)
|
2020-05-18 12:07:09 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
_renderInsecureRoomNameWarning: () => React$Component<any>;
|
2020-05-18 12:07:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the insecure room name warning if needed.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderInsecureRoomNameWarning() {
|
2020-05-27 22:12:06 +00:00
|
|
|
if (this.props._enableInsecureRoomNameWarning && this.state.insecureRoomName) {
|
2020-05-18 12:07:09 +00:00
|
|
|
return this._doRenderInsecureRoomNameWarning();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 22:36:09 +00:00
|
|
|
_updateRoomname: () => void;
|
|
|
|
|
2016-12-16 03:00:06 +00:00
|
|
|
/**
|
|
|
|
* Triggers the generation of a new room name and initiates an animation of
|
|
|
|
* its changing.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_updateRoomname() {
|
|
|
|
const generatedRoomname = generateRoomWithoutSeparator();
|
|
|
|
const roomPlaceholder = '';
|
|
|
|
const updateTimeoutId = setTimeout(this._updateRoomname, 10000);
|
|
|
|
|
|
|
|
this._clearTimeouts();
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
generatedRoomname,
|
|
|
|
roomPlaceholder,
|
|
|
|
updateTimeoutId
|
|
|
|
},
|
|
|
|
() => this._animateRoomnameChanging(generatedRoomname));
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-09-05 22:45:20 +00:00
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props of
|
|
|
|
* {@code AbstractWelcomePage}.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-09-05 22:45:20 +00:00
|
|
|
* @param {Object} state - The redux state.
|
2017-01-28 23:34:57 +00:00
|
|
|
* @protected
|
2020-06-29 12:17:35 +00:00
|
|
|
* @returns {Props}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-10-04 22:36:09 +00:00
|
|
|
export function _mapStateToProps(state: Object) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2019-05-28 13:32:29 +00:00
|
|
|
_calendarEnabled: isCalendarEnabled(state),
|
2022-12-22 13:15:38 +00:00
|
|
|
_deeplinkingCfg: state['features/base/config'].deeplinking || {},
|
2020-05-27 22:12:06 +00:00
|
|
|
_enableInsecureRoomNameWarning: state['features/base/config'].enableInsecureRoomNameWarning || false,
|
2020-06-29 12:17:35 +00:00
|
|
|
_moderatedRoomServiceUrl: state['features/base/config'].moderatedRoomServiceUrl,
|
2020-03-31 11:06:04 +00:00
|
|
|
_recentListEnabled: isRecentListEnabled(),
|
2018-04-12 19:58:20 +00:00
|
|
|
_room: state['features/base/conference'].room,
|
|
|
|
_settings: state['features/base/settings']
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|