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.

RemoteControlButton.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import {
  4. createRemoteVideoMenuButtonEvent,
  5. sendAnalytics
  6. } from '../../analytics';
  7. import { translate } from '../../base/i18n';
  8. import RemoteVideoMenuButton from './RemoteVideoMenuButton';
  9. // TODO: Move these enums into the store after further reactification of the
  10. // non-react RemoteVideo component.
  11. export const REMOTE_CONTROL_MENU_STATES = {
  12. NOT_SUPPORTED: 0,
  13. NOT_STARTED: 1,
  14. REQUESTING: 2,
  15. STARTED: 3
  16. };
  17. /**
  18. * Implements a React {@link Component} which displays a button showing the
  19. * current state of remote control for a participant and can start or stop a
  20. * remote control session.
  21. *
  22. * @extends Component
  23. */
  24. class RemoteControlButton extends Component {
  25. /**
  26. * {@code RemoteControlButton} component's property types.
  27. *
  28. * @static
  29. */
  30. static propTypes = {
  31. /**
  32. * The callback to invoke when the component is clicked.
  33. */
  34. onClick: PropTypes.func,
  35. /**
  36. * The ID of the participant linked to the onClick callback.
  37. */
  38. participantID: PropTypes.string,
  39. /**
  40. * The current status of remote control. Should be a number listed in
  41. * the enum REMOTE_CONTROL_MENU_STATES.
  42. */
  43. remoteControlState: PropTypes.number,
  44. /**
  45. * Invoked to obtain translated strings.
  46. */
  47. t: PropTypes.func
  48. };
  49. /**
  50. * Initializes a new {@code RemoteControlButton} instance.
  51. *
  52. * @param {Object} props - The read-only React Component props with which
  53. * the new instance is to be initialized.
  54. */
  55. constructor(props) {
  56. super(props);
  57. // Bind event handlers so they are only bound once for every instance.
  58. this._onClick = this._onClick.bind(this);
  59. }
  60. /**
  61. * Implements React's {@link Component#render()}.
  62. *
  63. * @inheritdoc
  64. * @returns {null|ReactElement}
  65. */
  66. render() {
  67. const {
  68. participantID,
  69. remoteControlState,
  70. t
  71. } = this.props;
  72. let className, icon;
  73. switch (remoteControlState) {
  74. case REMOTE_CONTROL_MENU_STATES.NOT_STARTED:
  75. className = 'requestRemoteControlLink';
  76. icon = 'fa fa-play';
  77. break;
  78. case REMOTE_CONTROL_MENU_STATES.REQUESTING:
  79. className = 'requestRemoteControlLink disabled';
  80. icon = 'remote-control-spinner fa fa-spinner fa-spin';
  81. break;
  82. case REMOTE_CONTROL_MENU_STATES.STARTED:
  83. className = 'requestRemoteControlLink';
  84. icon = 'fa fa-stop';
  85. break;
  86. case REMOTE_CONTROL_MENU_STATES.NOT_SUPPORTED:
  87. // Intentionally fall through.
  88. default:
  89. return null;
  90. }
  91. return (
  92. <RemoteVideoMenuButton
  93. buttonText = { t('videothumbnail.remoteControl') }
  94. displayClass = { className }
  95. iconClass = { icon }
  96. id = { `remoteControl_${participantID}` }
  97. onClick = { this._onClick } />
  98. );
  99. }
  100. /**
  101. * Sends analytics event for pressing the button and executes the passed
  102. * onClick handler.
  103. *
  104. * @private
  105. * @returns {void}
  106. */
  107. _onClick() {
  108. const { onClick, participantID, remoteControlState } = this.props;
  109. // TODO: What do we do in case the state is e.g. "requesting"?
  110. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED
  111. || remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  112. const enable
  113. = remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  114. sendAnalytics(createRemoteVideoMenuButtonEvent(
  115. 'remote.control.button',
  116. {
  117. enable,
  118. 'participant_id': participantID
  119. }));
  120. }
  121. if (onClick) {
  122. onClick();
  123. }
  124. }
  125. }
  126. export default translate(RemoteControlButton);