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 3.9KB

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