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

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