2016-10-05 14:36:59 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { appNavigate } from '../../app';
|
|
|
|
import { isRoomValid } from '../../base/conference';
|
|
|
|
import { VideoTrack } from '../../base/media';
|
|
|
|
import { getLocalVideoTrack } from '../../base/tracks';
|
2016-12-01 18:55:42 +00:00
|
|
|
import { generateRoomWithoutSeparator } from '../../base/util';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base (abstract) class for container component rendering the welcome page.
|
|
|
|
*
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
export class AbstractWelcomePage extends Component {
|
2016-12-01 01:52:39 +00:00
|
|
|
/**
|
|
|
|
* AbstractWelcomePage component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
2017-01-28 03:36:20 +00:00
|
|
|
_localVideoTrack: React.PropTypes.object,
|
|
|
|
_room: React.PropTypes.string,
|
|
|
|
dispatch: React.PropTypes.func
|
2016-12-01 01:52:39 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new AbstractWelcomePage instance, including the initial
|
|
|
|
* state of the room name input.
|
|
|
|
*
|
|
|
|
* @param {Object} props - Component properties.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save room name into component's local state.
|
|
|
|
*
|
2016-12-01 18:55:42 +00:00
|
|
|
* @type {Object}
|
2016-12-16 03:00:06 +00:00
|
|
|
* @property {number|null} animateTimeoutId - Identificator for
|
|
|
|
* letter animation timeout.
|
|
|
|
* @property {string} generatedRoomname - Automatically generated
|
|
|
|
* room name.
|
2016-12-01 18:55:42 +00:00
|
|
|
* @property {string} room - Room name.
|
|
|
|
* @property {string} roomPlaceholder - Room placeholder
|
|
|
|
* that's used as a placeholder for input.
|
|
|
|
* @property {nubmer|null} updateTimeoutId - Identificator for
|
|
|
|
* updating generated room name.
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
this.state = {
|
2016-12-16 03:00:06 +00:00
|
|
|
animateTimeoutId: null,
|
|
|
|
generatedRoomname: '',
|
2016-12-01 18:55:42 +00:00
|
|
|
room: '',
|
|
|
|
roomPlaceholder: '',
|
|
|
|
updateTimeoutId: null
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every 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);
|
2016-12-01 18:55:42 +00:00
|
|
|
this._updateRoomname = this._updateRoomname.bind(this);
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is executed when component receives new properties.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @param {Object} nextProps - New props component will receive.
|
|
|
|
*/
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-01-28 03:36:20 +00:00
|
|
|
this.setState({ room: nextProps._room });
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 18:55:42 +00:00
|
|
|
/**
|
2016-12-16 03:00:06 +00:00
|
|
|
* This method is executed when method will be unmounted from DOM.
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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}
|
|
|
|
*/
|
|
|
|
_animateRoomnameChanging(word) {
|
|
|
|
let animateTimeoutId = null;
|
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(
|
|
|
|
() => {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the 'Join' button is (to be) disabled i.e. there's no
|
|
|
|
* valid room name typed into the respective text input field.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean} If the 'Join' button is (to be) disabled, true;
|
|
|
|
* otherwise, false.
|
|
|
|
*/
|
|
|
|
_isJoinDisabled() {
|
|
|
|
return !isRoomValid(this.state.room);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-12-16 03:00:06 +00:00
|
|
|
if (room) {
|
2016-12-01 18:55:42 +00:00
|
|
|
this.props.dispatch(appNavigate(room));
|
|
|
|
}
|
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}
|
|
|
|
*/
|
|
|
|
_onRoomChange(value) {
|
|
|
|
this.setState({ room: value });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a local video if any.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {(ReactElement|null)}
|
|
|
|
*/
|
|
|
|
_renderLocalVideo() {
|
|
|
|
return (
|
2017-01-28 03:36:20 +00:00
|
|
|
<VideoTrack videoTrack = { this.props._localVideoTrack } />
|
2016-10-05 14:36:59 +00:00
|
|
|
);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects local video track from tracks in state, local participant and room
|
|
|
|
* and maps them to component props. It seems it's not possible to 'connect'
|
|
|
|
* base component and then extend from it. So we export this function in order
|
|
|
|
* to be used in child classes for 'connect'.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
2017-01-28 23:34:57 +00:00
|
|
|
* @protected
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {{
|
2017-01-28 03:36:20 +00:00
|
|
|
* _localVideoTrack: (Track|undefined),
|
|
|
|
* _room: string
|
2016-10-05 14:36:59 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-01-28 23:34:57 +00:00
|
|
|
export function _mapStateToProps(state) {
|
2016-10-05 14:36:59 +00:00
|
|
|
const conference = state['features/base/conference'];
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
|
|
|
|
return {
|
2017-01-28 03:36:20 +00:00
|
|
|
_localVideoTrack: getLocalVideoTrack(tracks),
|
|
|
|
_room: conference.room
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|