Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Filmstrip.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import {
  5. createShortcutEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { translate } from '../../../base/i18n';
  10. import { Icon, IconMenuDown, IconMenuUp } from '../../../base/icons';
  11. import { connect } from '../../../base/redux';
  12. import { isButtonEnabled } from '../../../toolbox/functions.web';
  13. import { LAYOUTS, getCurrentLayout } from '../../../video-layout';
  14. import { setFilmstripVisible } from '../../actions';
  15. import { shouldRemoteVideosBeVisible } from '../../functions';
  16. declare var APP: Object;
  17. declare var interfaceConfig: Object;
  18. /**
  19. * The type of the React {@code Component} props of {@link Filmstrip}.
  20. */
  21. type Props = {
  22. /**
  23. * Additional CSS class names top add to the root.
  24. */
  25. _className: string,
  26. /**
  27. * The current layout of the filmstrip.
  28. */
  29. _currentLayout: string,
  30. /**
  31. * The number of columns in tile view.
  32. */
  33. _columns: number,
  34. /**
  35. * The width of the filmstrip.
  36. */
  37. _filmstripWidth: number,
  38. /**
  39. * Whether the filmstrip scrollbar should be hidden or not.
  40. */
  41. _hideScrollbar: boolean,
  42. /**
  43. * Whether the filmstrip toolbar should be hidden or not.
  44. */
  45. _hideToolbar: boolean,
  46. /**
  47. * The number of rows in tile view.
  48. */
  49. _rows: number,
  50. /**
  51. * Additional CSS class names to add to the container of all the thumbnails.
  52. */
  53. _videosClassName: string,
  54. /**
  55. * Whether or not the filmstrip videos should currently be displayed.
  56. */
  57. _visible: boolean,
  58. /**
  59. * The redux {@code dispatch} function.
  60. */
  61. dispatch: Dispatch<any>,
  62. /**
  63. * Invoked to obtain translated strings.
  64. */
  65. t: Function
  66. };
  67. /**
  68. * Implements a React {@link Component} which represents the filmstrip on
  69. * Web/React.
  70. *
  71. * @extends Component
  72. */
  73. class Filmstrip extends Component <Props> {
  74. /**
  75. * Initializes a new {@code Filmstrip} instance.
  76. *
  77. * @param {Object} props - The read-only properties with which the new
  78. * instance is to be initialized.
  79. */
  80. constructor(props: Props) {
  81. super(props);
  82. // Bind event handlers so they are only bound once for every instance.
  83. this._onShortcutToggleFilmstrip = this._onShortcutToggleFilmstrip.bind(this);
  84. this._onToolbarToggleFilmstrip = this._onToolbarToggleFilmstrip.bind(this);
  85. }
  86. /**
  87. * Implements React's {@link Component#componentDidMount}.
  88. *
  89. * @inheritdoc
  90. */
  91. componentDidMount() {
  92. APP.keyboardshortcut.registerShortcut(
  93. 'F',
  94. 'filmstripPopover',
  95. this._onShortcutToggleFilmstrip,
  96. 'keyboardShortcuts.toggleFilmstrip'
  97. );
  98. }
  99. /**
  100. * Implements React's {@link Component#componentDidUpdate}.
  101. *
  102. * @inheritdoc
  103. */
  104. componentWillUnmount() {
  105. APP.keyboardshortcut.unregisterShortcut('F');
  106. }
  107. /**
  108. * Implements React's {@link Component#render()}.
  109. *
  110. * @inheritdoc
  111. * @returns {ReactElement}
  112. */
  113. render() {
  114. // Note: Appending of {@code RemoteVideo} views is handled through
  115. // VideoLayout. The views do not get blown away on render() because
  116. // ReactDOMComponent is only aware of the given JSX and not new appended
  117. // DOM. As such, when updateDOMProperties gets called, only attributes
  118. // will get updated without replacing the DOM. If the known DOM gets
  119. // modified, then the views will get blown away.
  120. const filmstripStyle = { };
  121. const filmstripRemoteVideosContainerStyle = {};
  122. let remoteVideoContainerClassName = 'remote-videos-container';
  123. switch (this.props._currentLayout) {
  124. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  125. // Adding 18px for the 2px margins, 2px borders on the left and right and 5px padding on the left and right.
  126. // Also adding 7px for the scrollbar.
  127. filmstripStyle.maxWidth = (interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120) + 25;
  128. break;
  129. case LAYOUTS.TILE_VIEW: {
  130. // The size of the side margins for each tile as set in CSS.
  131. const { _columns, _rows, _filmstripWidth } = this.props;
  132. if (_rows > _columns) {
  133. remoteVideoContainerClassName += ' has-overflow';
  134. }
  135. filmstripRemoteVideosContainerStyle.width = _filmstripWidth;
  136. break;
  137. }
  138. }
  139. let remoteVideosWrapperClassName = 'filmstrip__videos';
  140. if (this.props._hideScrollbar) {
  141. remoteVideosWrapperClassName += ' hide-scrollbar';
  142. }
  143. let toolbar = null;
  144. if (!this.props._hideToolbar && isButtonEnabled('filmstrip')) {
  145. toolbar = this._renderToggleButton();
  146. }
  147. return (
  148. <div
  149. className = { `filmstrip ${this.props._className}` }
  150. style = { filmstripStyle }>
  151. { toolbar }
  152. <div
  153. className = { this.props._videosClassName }
  154. id = 'remoteVideos'>
  155. <div
  156. className = 'filmstrip__videos'
  157. id = 'filmstripLocalVideo'>
  158. <div id = 'filmstripLocalVideoThumbnail' />
  159. </div>
  160. <div
  161. className = { remoteVideosWrapperClassName }
  162. id = 'filmstripRemoteVideos'>
  163. {/*
  164. * XXX This extra video container is needed for
  165. * scrolling thumbnails in Firefox; otherwise, the flex
  166. * thumbnails resize instead of causing overflow.
  167. */}
  168. <div
  169. className = { remoteVideoContainerClassName }
  170. id = 'filmstripRemoteVideosContainer'
  171. style = { filmstripRemoteVideosContainerStyle }>
  172. <div id = 'localVideoTileViewContainer' />
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. );
  178. }
  179. /**
  180. * Dispatches an action to change the visibility of the filmstrip.
  181. *
  182. * @private
  183. * @returns {void}
  184. */
  185. _doToggleFilmstrip() {
  186. this.props.dispatch(setFilmstripVisible(!this.props._visible));
  187. }
  188. _onShortcutToggleFilmstrip: () => void;
  189. /**
  190. * Creates an analytics keyboard shortcut event and dispatches an action for
  191. * toggling filmstrip visibility.
  192. *
  193. * @private
  194. * @returns {void}
  195. */
  196. _onShortcutToggleFilmstrip() {
  197. sendAnalytics(createShortcutEvent(
  198. 'toggle.filmstrip',
  199. {
  200. enable: this.props._visible
  201. }));
  202. this._doToggleFilmstrip();
  203. }
  204. _onToolbarToggleFilmstrip: () => void;
  205. /**
  206. * Creates an analytics toolbar event and dispatches an action for opening
  207. * the speaker stats modal.
  208. *
  209. * @private
  210. * @returns {void}
  211. */
  212. _onToolbarToggleFilmstrip() {
  213. sendAnalytics(createToolbarEvent(
  214. 'toggle.filmstrip.button',
  215. {
  216. enable: this.props._visible
  217. }));
  218. this._doToggleFilmstrip();
  219. }
  220. /**
  221. * Creates a React Element for changing the visibility of the filmstrip when
  222. * clicked.
  223. *
  224. * @private
  225. * @returns {ReactElement}
  226. */
  227. _renderToggleButton() {
  228. const icon = this.props._visible ? IconMenuDown : IconMenuUp;
  229. const { t } = this.props;
  230. return (
  231. <div className = 'filmstrip__toolbar'>
  232. <button
  233. aria-label = { t('toolbar.accessibilityLabel.toggleFilmstrip') }
  234. id = 'toggleFilmstripButton'
  235. onClick = { this._onToolbarToggleFilmstrip }>
  236. <Icon src = { icon } />
  237. </button>
  238. </div>
  239. );
  240. }
  241. }
  242. /**
  243. * Maps (parts of) the Redux state to the associated {@code Filmstrip}'s props.
  244. *
  245. * @param {Object} state - The Redux state.
  246. * @private
  247. * @returns {Props}
  248. */
  249. function _mapStateToProps(state) {
  250. const { iAmSipGateway } = state['features/base/config'];
  251. const { visible } = state['features/filmstrip'];
  252. const reduceHeight
  253. = state['features/toolbox'].visible && interfaceConfig.TOOLBAR_BUTTONS.length;
  254. const remoteVideosVisible = shouldRemoteVideosBeVisible(state);
  255. const { isOpen: shiftRight } = state['features/chat'];
  256. const className = `${remoteVideosVisible ? '' : 'hide-videos'} ${
  257. reduceHeight ? 'reduce-height' : ''
  258. } ${shiftRight ? 'shift-right' : ''}`.trim();
  259. const videosClassName = `filmstrip__videos${visible ? '' : ' hidden'}`;
  260. const { gridDimensions = {}, filmstripWidth } = state['features/filmstrip'].tileViewDimensions;
  261. return {
  262. _className: className,
  263. _columns: gridDimensions.columns,
  264. _currentLayout: getCurrentLayout(state),
  265. _filmstripWidth: filmstripWidth,
  266. _hideScrollbar: Boolean(iAmSipGateway),
  267. _hideToolbar: Boolean(iAmSipGateway),
  268. _rows: gridDimensions.rows,
  269. _videosClassName: videosClassName,
  270. _visible: visible
  271. };
  272. }
  273. export default translate(connect(_mapStateToProps)(Filmstrip));