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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import {
  4. createRemoteVideoMenuButtonEvent,
  5. sendAnalytics
  6. } from '../../../analytics';
  7. import { translate } from '../../../base/i18n';
  8. import { IconRemoteControlStart, IconRemoteControlStop } from '../../../base/icons';
  9. import VideoMenuButton from './VideoMenuButton';
  10. // TODO: Move these enums into the store after further reactification of the
  11. // non-react RemoteVideo component.
  12. export const REMOTE_CONTROL_MENU_STATES = {
  13. NOT_SUPPORTED: 0,
  14. NOT_STARTED: 1,
  15. REQUESTING: 2,
  16. STARTED: 3
  17. };
  18. /**
  19. * The type of the React {@code Component} props of {@link RemoteControlButton}.
  20. */
  21. type Props = {
  22. /**
  23. * The callback to invoke when the component is clicked.
  24. */
  25. onClick: Function,
  26. /**
  27. * The ID of the participant linked to the onClick callback.
  28. */
  29. participantID: string,
  30. /**
  31. * The current status of remote control. Should be a number listed in the
  32. * enum REMOTE_CONTROL_MENU_STATES.
  33. */
  34. remoteControlState: number,
  35. /**
  36. * Invoked to obtain translated strings.
  37. */
  38. t: Function
  39. };
  40. /**
  41. * Implements a React {@link Component} which displays a button showing the
  42. * current state of remote control for a participant and can start or stop a
  43. * remote control session.
  44. *
  45. * @extends Component
  46. */
  47. class RemoteControlButton extends Component<Props> {
  48. /**
  49. * Initializes a new {@code RemoteControlButton} instance.
  50. *
  51. * @param {Object} props - The read-only React Component props with which
  52. * the new instance is to be initialized.
  53. */
  54. constructor(props: Props) {
  55. super(props);
  56. // Bind event handlers so they are only bound once for every instance.
  57. this._onClick = this._onClick.bind(this);
  58. }
  59. /**
  60. * Implements React's {@link Component#render()}.
  61. *
  62. * @inheritdoc
  63. * @returns {null|ReactElement}
  64. */
  65. render() {
  66. const {
  67. participantID,
  68. remoteControlState,
  69. t
  70. } = this.props;
  71. let className, 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. className = ' disabled';
  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. <VideoMenuButton
  90. buttonText = { t('videothumbnail.remoteControl') }
  91. displayClass = { className }
  92. icon = { icon }
  93. id = { `remoteControl_${participantID}` }
  94. onClick = { this._onClick } />
  95. );
  96. }
  97. _onClick: () => void;
  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 { onClick, participantID, remoteControlState } = this.props;
  107. // TODO: What do we do in case the state is e.g. "requesting"?
  108. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED
  109. || remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  110. const enable
  111. = remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  112. sendAnalytics(createRemoteVideoMenuButtonEvent(
  113. 'remote.control.button',
  114. {
  115. enable,
  116. 'participant_id': participantID
  117. }));
  118. }
  119. if (onClick) {
  120. onClick();
  121. }
  122. }
  123. }
  124. export default translate(RemoteControlButton);