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.

RemoteVideoMenuTriggerButton.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Icon, IconMenuThumb } from '../../../base/icons';
  4. import { Popover } from '../../../base/popover';
  5. import {
  6. MuteButton,
  7. KickButton,
  8. PrivateMessageMenuButton,
  9. RemoteControlButton,
  10. RemoteVideoMenu,
  11. VolumeSlider
  12. } from './';
  13. declare var $: Object;
  14. declare var interfaceConfig: Object;
  15. /**
  16. * The type of the React {@code Component} props of
  17. * {@link RemoteVideoMenuTriggerButton}.
  18. */
  19. type Props = {
  20. /**
  21. * A value between 0 and 1 indicating the volume of the participant's
  22. * audio element.
  23. */
  24. initialVolumeValue: number,
  25. /**
  26. * Whether or not the participant is currently muted.
  27. */
  28. isAudioMuted: boolean,
  29. /**
  30. * Whether or not the participant is a conference moderator.
  31. */
  32. isModerator: boolean,
  33. /**
  34. * Callback to invoke when the popover has been displayed.
  35. */
  36. onMenuDisplay: Function,
  37. /**
  38. * Callback to invoke choosing to start a remote control session with
  39. * the participant.
  40. */
  41. onRemoteControlToggle: Function,
  42. /**
  43. * Callback to invoke when changing the level of the participant's
  44. * audio element.
  45. */
  46. onVolumeChange: Function,
  47. /**
  48. * The position relative to the trigger the remote menu should display
  49. * from. Valid values are those supported by AtlasKit
  50. * {@code InlineDialog}.
  51. */
  52. menuPosition: string,
  53. /**
  54. * The ID for the participant on which the remote video menu will act.
  55. */
  56. participantID: string,
  57. /**
  58. * The current state of the participant's remote control session.
  59. */
  60. remoteControlState: number
  61. };
  62. /**
  63. * React {@code Component} for displaying an icon associated with opening the
  64. * the {@code RemoteVideoMenu}.
  65. *
  66. * @extends {Component}
  67. */
  68. class RemoteVideoMenuTriggerButton extends Component<Props> {
  69. /**
  70. * The internal reference to topmost DOM/HTML element backing the React
  71. * {@code Component}. Accessed directly for associating an element as
  72. * the trigger for a popover.
  73. *
  74. * @private
  75. * @type {HTMLDivElement}
  76. */
  77. _rootElement = null;
  78. /**
  79. * Initializes a new {#@code RemoteVideoMenuTriggerButton} instance.
  80. *
  81. * @param {Object} props - The read-only properties with which the new
  82. * instance is to be initialized.
  83. */
  84. constructor(props: Object) {
  85. super(props);
  86. // Bind event handler so it is only bound once for every instance.
  87. this._onShowRemoteMenu = this._onShowRemoteMenu.bind(this);
  88. }
  89. /**
  90. * Implements React's {@link Component#render()}.
  91. *
  92. * @inheritdoc
  93. * @returns {ReactElement}
  94. */
  95. render() {
  96. const content = this._renderRemoteVideoMenu();
  97. if (!content) {
  98. return null;
  99. }
  100. return (
  101. <Popover
  102. content = { content }
  103. onPopoverOpen = { this._onShowRemoteMenu }
  104. position = { this.props.menuPosition }>
  105. <span
  106. className = 'popover-trigger remote-video-menu-trigger'>
  107. <Icon
  108. size = '1em'
  109. src = { IconMenuThumb }
  110. title = 'Remote user controls' />
  111. </span>
  112. </Popover>
  113. );
  114. }
  115. _onShowRemoteMenu: () => void;
  116. /**
  117. * Opens the {@code RemoteVideoMenu}.
  118. *
  119. * @private
  120. * @returns {void}
  121. */
  122. _onShowRemoteMenu() {
  123. this.props.onMenuDisplay();
  124. }
  125. /**
  126. * Creates a new {@code RemoteVideoMenu} with buttons for interacting with
  127. * the remote participant.
  128. *
  129. * @private
  130. * @returns {ReactElement}
  131. */
  132. _renderRemoteVideoMenu() {
  133. const {
  134. initialVolumeValue,
  135. isAudioMuted,
  136. isModerator,
  137. onRemoteControlToggle,
  138. onVolumeChange,
  139. remoteControlState,
  140. participantID
  141. } = this.props;
  142. const buttons = [];
  143. if (isModerator) {
  144. buttons.push(
  145. <MuteButton
  146. isAudioMuted = { isAudioMuted }
  147. key = 'mute'
  148. participantID = { participantID } />
  149. );
  150. buttons.push(
  151. <KickButton
  152. key = 'kick'
  153. participantID = { participantID } />
  154. );
  155. }
  156. if (remoteControlState) {
  157. buttons.push(
  158. <RemoteControlButton
  159. key = 'remote-control'
  160. onClick = { onRemoteControlToggle }
  161. participantID = { participantID }
  162. remoteControlState = { remoteControlState } />
  163. );
  164. }
  165. buttons.push(
  166. <PrivateMessageMenuButton
  167. key = 'privateMessage'
  168. participantID = { participantID } />
  169. );
  170. if (onVolumeChange) {
  171. buttons.push(
  172. <VolumeSlider
  173. initialValue = { initialVolumeValue }
  174. key = 'volume-slider'
  175. onChange = { onVolumeChange } />
  176. );
  177. }
  178. if (buttons.length > 0) {
  179. return (
  180. <RemoteVideoMenu id = { participantID }>
  181. { buttons }
  182. </RemoteVideoMenu>
  183. );
  184. }
  185. return null;
  186. }
  187. }
  188. export default RemoteVideoMenuTriggerButton;