選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

RemoteControlButton.tsx 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  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. * The type of the React {@code Component} props of {@link RemoteControlButton}.
  19. */
  20. interface IProps extends WithTranslation {
  21. /**
  22. * Callback to execute when the button is clicked.
  23. */
  24. notifyClick?: Function;
  25. /**
  26. * Notify mode for `participantMenuButtonClicked` event -
  27. * whether to only notify or to also prevent button click routine.
  28. */
  29. notifyMode?: string;
  30. /**
  31. * The callback to invoke when the component is clicked.
  32. */
  33. onClick: (() => void) | null;
  34. /**
  35. * The ID of the participant linked to the onClick callback.
  36. */
  37. participantID: string;
  38. /**
  39. * The current status of remote control. Should be a number listed in the
  40. * enum REMOTE_CONTROL_MENU_STATES.
  41. */
  42. remoteControlState: number;
  43. }
  44. /**
  45. * Implements a React {@link Component} which displays a button showing the
  46. * current state of remote control for a participant and can start or stop a
  47. * remote control session.
  48. *
  49. * @augments Component
  50. */
  51. class RemoteControlButton extends Component<IProps> {
  52. /**
  53. * Initializes a new {@code RemoteControlButton} instance.
  54. *
  55. * @param {Object} props - The read-only React Component props with which
  56. * the new instance is to be initialized.
  57. */
  58. constructor(props: IProps) {
  59. super(props);
  60. // Bind event handlers so they are only bound once for every instance.
  61. this._onClick = this._onClick.bind(this);
  62. }
  63. /**
  64. * Implements React's {@link Component#render()}.
  65. *
  66. * @inheritdoc
  67. * @returns {null|ReactElement}
  68. */
  69. render() {
  70. const { remoteControlState, t } = this.props;
  71. let disabled = false, icon;
  72. switch (remoteControlState) {
  73. case REMOTE_CONTROL_MENU_STATES.NOT_STARTED:
  74. icon = IconRemoteControlStart;
  75. break;
  76. case REMOTE_CONTROL_MENU_STATES.REQUESTING:
  77. disabled = true;
  78. icon = IconRemoteControlStart;
  79. break;
  80. case REMOTE_CONTROL_MENU_STATES.STARTED:
  81. icon = IconRemoteControlStop;
  82. break;
  83. case REMOTE_CONTROL_MENU_STATES.NOT_SUPPORTED:
  84. // Intentionally fall through.
  85. default:
  86. return null;
  87. }
  88. return (
  89. <ContextMenuItem
  90. accessibilityLabel = { t('videothumbnail.remoteControl') }
  91. className = 'kicklink'
  92. disabled = { disabled }
  93. icon = { icon }
  94. onClick = { this._onClick }
  95. text = { t('videothumbnail.remoteControl') } />
  96. );
  97. }
  98. /**
  99. * Sends analytics event for pressing the button and executes the passed
  100. * onClick handler.
  101. *
  102. * @private
  103. * @returns {void}
  104. */
  105. _onClick() {
  106. const { notifyClick, notifyMode, onClick, participantID, remoteControlState } = this.props;
  107. notifyClick?.();
  108. if (notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY) {
  109. return;
  110. }
  111. // TODO: What do we do in case the state is e.g. "requesting"?
  112. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED
  113. || remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  114. const enable
  115. = remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  116. sendAnalytics(createRemoteVideoMenuButtonEvent(
  117. 'remote.control.button',
  118. {
  119. enable,
  120. 'participant_id': participantID
  121. }));
  122. }
  123. onClick?.();
  124. }
  125. }
  126. export default translate(RemoteControlButton);