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.

Filmstrip.js 11KB

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