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