You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractWelcomePage.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, { Component } from 'react';
  2. import { appNavigate } from '../../app';
  3. import { isRoomValid } from '../../base/conference';
  4. import { VideoTrack } from '../../base/media';
  5. import { getLocalVideoTrack } from '../../base/tracks';
  6. /**
  7. * Base (abstract) class for container component rendering the welcome page.
  8. *
  9. * @abstract
  10. */
  11. export class AbstractWelcomePage extends Component {
  12. /**
  13. * Initializes a new AbstractWelcomePage instance, including the initial
  14. * state of the room name input.
  15. *
  16. * @param {Object} props - Component properties.
  17. */
  18. constructor(props) {
  19. super(props);
  20. /**
  21. * Save room name into component's local state.
  22. *
  23. * @type {{room: string}}
  24. */
  25. this.state = {
  26. room: ''
  27. };
  28. // Bind event handlers so they are only bound once for every instance.
  29. this._onJoinClick = this._onJoinClick.bind(this);
  30. this._onRoomChange = this._onRoomChange.bind(this);
  31. }
  32. /**
  33. * This method is executed when component receives new properties.
  34. *
  35. * @inheritdoc
  36. * @param {Object} nextProps - New props component will receive.
  37. */
  38. componentWillReceiveProps(nextProps) {
  39. this.setState({ room: nextProps.room });
  40. }
  41. /**
  42. * Determines whether the 'Join' button is (to be) disabled i.e. there's no
  43. * valid room name typed into the respective text input field.
  44. *
  45. * @protected
  46. * @returns {boolean} If the 'Join' button is (to be) disabled, true;
  47. * otherwise, false.
  48. */
  49. _isJoinDisabled() {
  50. return !isRoomValid(this.state.room);
  51. }
  52. /**
  53. * Handles click on 'Join' button.
  54. *
  55. * @protected
  56. * @returns {void}
  57. */
  58. _onJoinClick() {
  59. this.props.dispatch(appNavigate(this.state.room));
  60. }
  61. /**
  62. * Handles 'change' event for the room name text input field.
  63. *
  64. * @param {string} value - The text typed into the respective text input
  65. * field.
  66. * @protected
  67. * @returns {void}
  68. */
  69. _onRoomChange(value) {
  70. this.setState({ room: value });
  71. }
  72. /**
  73. * Renders a local video if any.
  74. *
  75. * @protected
  76. * @returns {(ReactElement|null)}
  77. */
  78. _renderLocalVideo() {
  79. return (
  80. <VideoTrack videoTrack = { this.props.localVideoTrack } />
  81. );
  82. }
  83. }
  84. /**
  85. * AbstractWelcomePage component's property types.
  86. *
  87. * @static
  88. */
  89. AbstractWelcomePage.propTypes = {
  90. dispatch: React.PropTypes.func,
  91. localVideoTrack: React.PropTypes.object,
  92. room: React.PropTypes.string
  93. };
  94. /**
  95. * Selects local video track from tracks in state, local participant and room
  96. * and maps them to component props. It seems it's not possible to 'connect'
  97. * base component and then extend from it. So we export this function in order
  98. * to be used in child classes for 'connect'.
  99. *
  100. * @param {Object} state - Redux state.
  101. * @returns {{
  102. * localVideoTrack: (Track|undefined),
  103. * room: string
  104. * }}
  105. */
  106. export function mapStateToProps(state) {
  107. const conference = state['features/base/conference'];
  108. const tracks = state['features/base/tracks'];
  109. return {
  110. localVideoTrack: getLocalVideoTrack(tracks),
  111. room: conference.room
  112. };
  113. }