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

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