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

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