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. * AbstractWelcomePage component's property types.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. dispatch: React.PropTypes.func,
  19. localVideoTrack: React.PropTypes.object,
  20. room: React.PropTypes.string
  21. }
  22. /**
  23. * Initializes a new AbstractWelcomePage instance, including the initial
  24. * state of the room name input.
  25. *
  26. * @param {Object} props - Component properties.
  27. */
  28. constructor(props) {
  29. super(props);
  30. /**
  31. * Save room name into component's local state.
  32. *
  33. * @type {{room: string}}
  34. */
  35. this.state = {
  36. room: ''
  37. };
  38. // Bind event handlers so they are only bound once for every instance.
  39. this._onJoinClick = this._onJoinClick.bind(this);
  40. this._onRoomChange = this._onRoomChange.bind(this);
  41. }
  42. /**
  43. * This method is executed when component receives new properties.
  44. *
  45. * @inheritdoc
  46. * @param {Object} nextProps - New props component will receive.
  47. */
  48. componentWillReceiveProps(nextProps) {
  49. this.setState({ room: nextProps.room });
  50. }
  51. /**
  52. * Determines whether the 'Join' button is (to be) disabled i.e. there's no
  53. * valid room name typed into the respective text input field.
  54. *
  55. * @protected
  56. * @returns {boolean} If the 'Join' button is (to be) disabled, true;
  57. * otherwise, false.
  58. */
  59. _isJoinDisabled() {
  60. return !isRoomValid(this.state.room);
  61. }
  62. /**
  63. * Handles click on 'Join' button.
  64. *
  65. * @protected
  66. * @returns {void}
  67. */
  68. _onJoinClick() {
  69. this.props.dispatch(appNavigate(this.state.room));
  70. }
  71. /**
  72. * Handles 'change' event for the room name text input field.
  73. *
  74. * @param {string} value - The text typed into the respective text input
  75. * field.
  76. * @protected
  77. * @returns {void}
  78. */
  79. _onRoomChange(value) {
  80. this.setState({ room: value });
  81. }
  82. /**
  83. * Renders a local video if any.
  84. *
  85. * @protected
  86. * @returns {(ReactElement|null)}
  87. */
  88. _renderLocalVideo() {
  89. return (
  90. <VideoTrack videoTrack = { this.props.localVideoTrack } />
  91. );
  92. }
  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. }