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.

Thumbnail.js 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { createScreenSharingIssueEvent, sendAnalytics } from '../../../analytics';
  4. import { AudioLevelIndicator } from '../../../audio-level-indicator';
  5. import { Avatar } from '../../../base/avatar';
  6. import { isMobileBrowser } from '../../../base/environment/utils';
  7. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  8. import { MEDIA_TYPE, VideoTrack } from '../../../base/media';
  9. import {
  10. getParticipantByIdOrUndefined,
  11. getParticipantCount,
  12. pinParticipant
  13. } from '../../../base/participants';
  14. import { connect } from '../../../base/redux';
  15. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  16. import { isTestModeEnabled } from '../../../base/testing';
  17. import {
  18. getLocalAudioTrack,
  19. getLocalVideoTrack,
  20. getTrackByMediaTypeAndParticipant,
  21. updateLastTrackVideoMediaEvent
  22. } from '../../../base/tracks';
  23. import { ConnectionIndicator } from '../../../connection-indicator';
  24. import { DisplayName } from '../../../display-name';
  25. import { StatusIndicators, RaisedHandIndicator, DominantSpeakerIndicator } from '../../../filmstrip';
  26. import { PresenceLabel } from '../../../presence-status';
  27. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  28. import { LocalVideoMenuTriggerButton, RemoteVideoMenuTriggerButton } from '../../../video-menu';
  29. import { setVolume } from '../../actions.web';
  30. import {
  31. DISPLAY_MODE_TO_CLASS_NAME,
  32. DISPLAY_MODE_TO_STRING,
  33. DISPLAY_VIDEO,
  34. DISPLAY_VIDEO_WITH_NAME,
  35. MOBILE_FILMSTRIP_PORTRAIT_RATIO,
  36. VIDEO_TEST_EVENTS,
  37. SHOW_TOOLBAR_CONTEXT_MENU_AFTER
  38. } from '../../constants';
  39. import { isVideoPlayable, computeDisplayMode } from '../../functions';
  40. import logger from '../../logger';
  41. const JitsiTrackEvents = JitsiMeetJS.events.track;
  42. declare var interfaceConfig: Object;
  43. /**
  44. * The type of the React {@code Component} state of {@link Thumbnail}.
  45. */
  46. export type State = {|
  47. /**
  48. * The current audio level value for the Thumbnail.
  49. */
  50. audioLevel: number,
  51. /**
  52. * Indicates that the canplay event has been received.
  53. */
  54. canPlayEventReceived: boolean,
  55. /**
  56. * The current display mode of the thumbnail.
  57. */
  58. displayMode: number,
  59. /**
  60. * Indicates whether the thumbnail is hovered or not.
  61. */
  62. isHovered: boolean
  63. |};
  64. /**
  65. * The type of the React {@code Component} props of {@link Thumbnail}.
  66. */
  67. export type Props = {|
  68. /**
  69. * The audio track related to the participant.
  70. */
  71. _audioTrack: ?Object,
  72. /**
  73. * Disable/enable the auto hide functionality for the connection indicator.
  74. */
  75. _connectionIndicatorAutoHideEnabled: boolean,
  76. /**
  77. * Disable/enable the connection indicator.
  78. */
  79. _connectionIndicatorDisabled: boolean,
  80. /**
  81. * The current layout of the filmstrip.
  82. */
  83. _currentLayout: string,
  84. /**
  85. * The default display name for the local participant.
  86. */
  87. _defaultLocalDisplayName: string,
  88. /**
  89. * Indicates whether the local video flip feature is disabled or not.
  90. */
  91. _disableLocalVideoFlip: boolean,
  92. /**
  93. * Indicates whether the profile functionality is disabled.
  94. */
  95. _disableProfile: boolean,
  96. /**
  97. * The display mode of the thumbnail.
  98. */
  99. _displayMode: number,
  100. /**
  101. * The height of the Thumbnail.
  102. */
  103. _height: number,
  104. /**
  105. * The aspect ratio of the Thumbnail in percents.
  106. */
  107. _heightToWidthPercent: number,
  108. /**
  109. * Indicates whether the thumbnail should be hidden or not.
  110. */
  111. _isHidden: boolean,
  112. /**
  113. * Indicates whether audio only mode is enabled.
  114. */
  115. _isAudioOnly: boolean,
  116. /**
  117. * Indicates whether the participant associated with the thumbnail is displayed on the large video.
  118. */
  119. _isCurrentlyOnLargeVideo: boolean,
  120. /**
  121. * Whether we are currently running in a mobile browser.
  122. */
  123. _isMobile: boolean,
  124. /**
  125. * Whether we are currently running in a mobile browser in portrait orientation.
  126. */
  127. _isMobilePortrait: boolean,
  128. /**
  129. * Indicates whether the participant is screen sharing.
  130. */
  131. _isScreenSharing: boolean,
  132. /**
  133. * Indicates whether the video associated with the thumbnail is playable.
  134. */
  135. _isVideoPlayable: boolean,
  136. /**
  137. * Disable/enable the dominant speaker indicator.
  138. */
  139. _isDominantSpeakerDisabled: boolean,
  140. /**
  141. * Indicates whether testing mode is enabled.
  142. */
  143. _isTestModeEnabled: boolean,
  144. /**
  145. * The size of the icon of indicators.
  146. */
  147. _indicatorIconSize: number,
  148. /**
  149. * The current local video flip setting.
  150. */
  151. _localFlipX: boolean,
  152. /**
  153. * An object with information about the participant related to the thumbnaul.
  154. */
  155. _participant: Object,
  156. /**
  157. * True if there are more than 2 participants in the call.
  158. */
  159. _participantCountMoreThan2: boolean,
  160. /**
  161. * Indicates whether the "start silent" mode is enabled.
  162. */
  163. _startSilent: Boolean,
  164. /**
  165. * The video track that will be displayed in the thumbnail.
  166. */
  167. _videoTrack: ?Object,
  168. /**
  169. * The volume level for the thumbnail.
  170. */
  171. _volume?: ?number,
  172. /**
  173. * The width of the thumbnail.
  174. */
  175. _width: number,
  176. /**
  177. * The redux dispatch function.
  178. */
  179. dispatch: Function,
  180. /**
  181. * The horizontal offset in px for the thumbnail. Used to center the thumbnails from the last row in tile view.
  182. */
  183. horizontalOffset: number,
  184. /**
  185. * The ID of the participant related to the thumbnail.
  186. */
  187. participantID: ?string,
  188. /**
  189. * Styles that will be set to the Thumbnail's main span element.
  190. */
  191. style?: ?Object
  192. |};
  193. /**
  194. * Click handler for the display name container.
  195. *
  196. * @param {SyntheticEvent} event - The click event.
  197. * @returns {void}
  198. */
  199. function onClick(event) {
  200. // If the event is propagated to the thumbnail container the participant will be pinned. That's why the propagation
  201. // needs to be stopped.
  202. event.stopPropagation();
  203. }
  204. /**
  205. * Implements a thumbnail.
  206. *
  207. * @extends Component
  208. */
  209. class Thumbnail extends Component<Props, State> {
  210. /**
  211. * The long touch setTimeout handler.
  212. */
  213. timeoutHandle: Object;
  214. /**
  215. * Reference to local or remote Video Menu trigger button instance.
  216. */
  217. videoMenuTriggerRef: Object;
  218. /**
  219. * Initializes a new Thumbnail instance.
  220. *
  221. * @param {Object} props - The read-only React Component props with which
  222. * the new instance is to be initialized.
  223. */
  224. constructor(props: Props) {
  225. super(props);
  226. const state = {
  227. audioLevel: 0,
  228. canPlayEventReceived: false,
  229. isHovered: false,
  230. displayMode: DISPLAY_VIDEO
  231. };
  232. this.state = {
  233. ...state,
  234. displayMode: computeDisplayMode(Thumbnail.getDisplayModeInput(props, state))
  235. };
  236. this.timeoutHandle = null;
  237. this.videoMenuTriggerRef = null;
  238. this._setInstance = this._setInstance.bind(this);
  239. this._updateAudioLevel = this._updateAudioLevel.bind(this);
  240. this._onCanPlay = this._onCanPlay.bind(this);
  241. this._onClick = this._onClick.bind(this);
  242. this._onVolumeChange = this._onVolumeChange.bind(this);
  243. this._onMouseEnter = this._onMouseEnter.bind(this);
  244. this._onMouseLeave = this._onMouseLeave.bind(this);
  245. this._onTestingEvent = this._onTestingEvent.bind(this);
  246. this._onTouchStart = this._onTouchStart.bind(this);
  247. this._onTouchEnd = this._onTouchEnd.bind(this);
  248. this._onTouchMove = this._onTouchMove.bind(this);
  249. this._showPopupMenu = this._showPopupMenu.bind(this);
  250. }
  251. /**
  252. * Starts listening for audio level updates after the initial render.
  253. *
  254. * @inheritdoc
  255. * @returns {void}
  256. */
  257. componentDidMount() {
  258. this._listenForAudioUpdates();
  259. this._onDisplayModeChanged();
  260. }
  261. /**
  262. * Stops listening for audio level updates on the old track and starts
  263. * listening instead on the new track.
  264. *
  265. * @inheritdoc
  266. * @returns {void}
  267. */
  268. componentDidUpdate(prevProps: Props, prevState: State) {
  269. if (prevProps._audioTrack !== this.props._audioTrack) {
  270. this._stopListeningForAudioUpdates(prevProps._audioTrack);
  271. this._listenForAudioUpdates();
  272. this._updateAudioLevel(0);
  273. }
  274. if (prevState.displayMode !== this.state.displayMode) {
  275. this._onDisplayModeChanged();
  276. }
  277. }
  278. /**
  279. * Handles display mode changes.
  280. *
  281. * @returns {void}
  282. */
  283. _onDisplayModeChanged() {
  284. const input = Thumbnail.getDisplayModeInput(this.props, this.state);
  285. const displayModeString = DISPLAY_MODE_TO_STRING[this.state.displayMode];
  286. const id = this.props._participant?.id;
  287. this._maybeSendScreenSharingIssueEvents(input);
  288. logger.debug(`Displaying ${displayModeString} for ${id}, data: [${JSON.stringify(input)}]`);
  289. }
  290. /**
  291. * Sends screen sharing issue event if an issue is detected.
  292. *
  293. * @param {Object} input - The input used to compute the thumbnail display mode.
  294. * @returns {void}
  295. */
  296. _maybeSendScreenSharingIssueEvents(input) {
  297. const {
  298. _currentLayout,
  299. _isAudioOnly,
  300. _isScreenSharing
  301. } = this.props;
  302. const { displayMode } = this.state;
  303. const tileViewActive = _currentLayout === LAYOUTS.TILE_VIEW;
  304. if (![ DISPLAY_VIDEO, DISPLAY_VIDEO_WITH_NAME ].includes(displayMode)
  305. && tileViewActive
  306. && _isScreenSharing
  307. && !_isAudioOnly) {
  308. sendAnalytics(createScreenSharingIssueEvent({
  309. source: 'thumbnail',
  310. ...input
  311. }));
  312. }
  313. }
  314. /**
  315. * Implements React's {@link Component#getDerivedStateFromProps()}.
  316. *
  317. * @inheritdoc
  318. */
  319. static getDerivedStateFromProps(props: Props, prevState: State) {
  320. if (!props._videoTrack && prevState.canPlayEventReceived) {
  321. const newState = {
  322. ...prevState,
  323. canPlayEventReceived: false
  324. };
  325. return {
  326. ...newState,
  327. displayMode: computeDisplayMode(Thumbnail.getDisplayModeInput(props, newState))
  328. };
  329. }
  330. const newDisplayMode = computeDisplayMode(Thumbnail.getDisplayModeInput(props, prevState));
  331. if (newDisplayMode !== prevState.displayMode) {
  332. return {
  333. ...prevState,
  334. displayMode: newDisplayMode
  335. };
  336. }
  337. return null;
  338. }
  339. /**
  340. * Extracts information for props and state needed to compute the display mode.
  341. *
  342. * @param {Props} props - The component's props.
  343. * @param {State} state - The component's state.
  344. * @returns {Object}
  345. */
  346. static getDisplayModeInput(props: Props, state: State) {
  347. const {
  348. _currentLayout,
  349. _isAudioOnly,
  350. _isCurrentlyOnLargeVideo,
  351. _isScreenSharing,
  352. _isVideoPlayable,
  353. _participant,
  354. _videoTrack
  355. } = props;
  356. const tileViewActive = _currentLayout === LAYOUTS.TILE_VIEW;
  357. const { canPlayEventReceived, isHovered } = state;
  358. return {
  359. isCurrentlyOnLargeVideo: _isCurrentlyOnLargeVideo,
  360. isHovered,
  361. isAudioOnly: _isAudioOnly,
  362. tileViewActive,
  363. isVideoPlayable: _isVideoPlayable,
  364. connectionStatus: _participant?.connectionStatus,
  365. canPlayEventReceived,
  366. videoStream: Boolean(_videoTrack),
  367. isRemoteParticipant: !_participant?.isFakeParticipant && !_participant?.local,
  368. isScreenSharing: _isScreenSharing,
  369. videoStreamMuted: _videoTrack ? _videoTrack.muted : 'no stream'
  370. };
  371. }
  372. /**
  373. * Unsubscribe from audio level updates.
  374. *
  375. * @inheritdoc
  376. * @returns {void}
  377. */
  378. componentWillUnmount() {
  379. this._stopListeningForAudioUpdates(this.props._audioTrack);
  380. }
  381. /**
  382. * Starts listening for audio level updates from the library.
  383. *
  384. * @private
  385. * @returns {void}
  386. */
  387. _listenForAudioUpdates() {
  388. const { _audioTrack } = this.props;
  389. if (_audioTrack) {
  390. const { jitsiTrack } = _audioTrack;
  391. jitsiTrack && jitsiTrack.on(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, this._updateAudioLevel);
  392. }
  393. }
  394. /**
  395. * Stops listening to further updates from the passed track.
  396. *
  397. * @param {Object} audioTrack - The track.
  398. * @private
  399. * @returns {void}
  400. */
  401. _stopListeningForAudioUpdates(audioTrack) {
  402. if (audioTrack) {
  403. const { jitsiTrack } = audioTrack;
  404. jitsiTrack && jitsiTrack.off(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, this._updateAudioLevel);
  405. }
  406. }
  407. _updateAudioLevel: (number) => void;
  408. /**
  409. * Updates the internal state of the last know audio level. The level should
  410. * be between 0 and 1, as the level will be used as a percentage out of 1.
  411. *
  412. * @param {number} audioLevel - The new audio level for the track.
  413. * @private
  414. * @returns {void}
  415. */
  416. _updateAudioLevel(audioLevel) {
  417. this.setState({
  418. audioLevel
  419. });
  420. }
  421. /**
  422. * Returns an object with the styles for thumbnail.
  423. *
  424. * @returns {Object} - The styles for the thumbnail.
  425. */
  426. _getStyles(): Object {
  427. const { _height, _isHidden, _width, style, horizontalOffset } = this.props;
  428. let styles: {
  429. thumbnail: Object,
  430. avatar: Object
  431. } = {
  432. thumbnail: {},
  433. avatar: {}
  434. };
  435. const avatarSize = _height / 2;
  436. let { left } = style || {};
  437. if (typeof left === 'number' && horizontalOffset) {
  438. left += horizontalOffset;
  439. }
  440. styles = {
  441. thumbnail: {
  442. ...style,
  443. left,
  444. height: `${_height}px`,
  445. minHeight: `${_height}px`,
  446. minWidth: `${_width}px`,
  447. width: `${_width}px`
  448. },
  449. avatar: {
  450. height: `${avatarSize}px`,
  451. width: `${avatarSize}px`
  452. }
  453. };
  454. if (_isHidden) {
  455. styles.thumbnail.display = 'none';
  456. }
  457. return styles;
  458. }
  459. _onClick: () => void;
  460. /**
  461. * On click handler.
  462. *
  463. * @returns {void}
  464. */
  465. _onClick() {
  466. const { _participant, dispatch } = this.props;
  467. const { id, pinned } = _participant;
  468. dispatch(pinParticipant(pinned ? null : id));
  469. }
  470. _onMouseEnter: () => void;
  471. /**
  472. * Mouse enter handler.
  473. *
  474. * @returns {void}
  475. */
  476. _onMouseEnter() {
  477. this.setState({ isHovered: true });
  478. }
  479. _onMouseLeave: () => void;
  480. /**
  481. * Mouse leave handler.
  482. *
  483. * @returns {void}
  484. */
  485. _onMouseLeave() {
  486. this.setState({ isHovered: false });
  487. }
  488. _showPopupMenu: () => void;
  489. /**
  490. * Triggers showing the popover context menu.
  491. *
  492. * @returns {void}
  493. */
  494. _showPopupMenu() {
  495. if (this.videoMenuTriggerRef) {
  496. this.videoMenuTriggerRef.showContextMenu();
  497. }
  498. }
  499. _onTouchStart: () => void;
  500. /**
  501. * Set showing popover context menu after x miliseconds.
  502. *
  503. * @returns {void}
  504. */
  505. _onTouchStart() {
  506. this.timeoutHandle = setTimeout(this._showPopupMenu, SHOW_TOOLBAR_CONTEXT_MENU_AFTER);
  507. }
  508. _onTouchEnd: () => void;
  509. /**
  510. * Cancel showing popover context menu after x miliseconds if the no. Of miliseconds is not reached yet,
  511. * or just clears the timeout.
  512. *
  513. * @returns {void}
  514. */
  515. _onTouchEnd() {
  516. clearTimeout(this.timeoutHandle);
  517. }
  518. _onTouchMove: () => void;
  519. /**
  520. * Cancel showing Context menu after x miliseconds if the number of miliseconds is not reached
  521. * before a touch move(drag), or just clears the timeout.
  522. *
  523. * @returns {void}
  524. */
  525. _onTouchMove() {
  526. clearTimeout(this.timeoutHandle);
  527. }
  528. /**
  529. * Renders a fake participant (youtube video) thumbnail.
  530. *
  531. * @param {string} id - The id of the participant.
  532. * @returns {ReactElement}
  533. */
  534. _renderFakeParticipant() {
  535. const { _isMobile, _participant: { avatarURL } } = this.props;
  536. const styles = this._getStyles();
  537. const containerClassName = this._getContainerClassName();
  538. return (
  539. <span
  540. className = { containerClassName }
  541. id = 'sharedVideoContainer'
  542. onClick = { this._onClick }
  543. { ...(_isMobile ? {} : {
  544. onMouseEnter: this._onMouseEnter,
  545. onMouseLeave: this._onMouseLeave
  546. }) }
  547. style = { styles.thumbnail }>
  548. {avatarURL ? (
  549. <img
  550. className = 'sharedVideoAvatar'
  551. src = { avatarURL } />
  552. )
  553. : this._renderAvatar(styles.avatar)}
  554. </span>
  555. );
  556. }
  557. /**
  558. * Renders the top indicators of the thumbnail.
  559. *
  560. * @returns {Component}
  561. */
  562. _renderTopIndicators() {
  563. const {
  564. _connectionIndicatorAutoHideEnabled,
  565. _connectionIndicatorDisabled,
  566. _currentLayout,
  567. _isDominantSpeakerDisabled,
  568. _indicatorIconSize: iconSize,
  569. _participant,
  570. _participantCountMoreThan2
  571. } = this.props;
  572. const { isHovered } = this.state;
  573. const showConnectionIndicator = isHovered || !_connectionIndicatorAutoHideEnabled;
  574. const { id, dominantSpeaker = false } = _participant;
  575. const showDominantSpeaker = !_isDominantSpeakerDisabled && dominantSpeaker;
  576. let statsPopoverPosition, tooltipPosition;
  577. switch (_currentLayout) {
  578. case LAYOUTS.TILE_VIEW:
  579. statsPopoverPosition = 'right-start';
  580. tooltipPosition = 'right';
  581. break;
  582. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  583. statsPopoverPosition = 'left-start';
  584. tooltipPosition = 'left';
  585. break;
  586. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  587. statsPopoverPosition = 'top';
  588. tooltipPosition = 'top';
  589. break;
  590. default:
  591. statsPopoverPosition = 'auto';
  592. tooltipPosition = 'top';
  593. }
  594. return (
  595. <div>
  596. { !_connectionIndicatorDisabled
  597. && <ConnectionIndicator
  598. alwaysVisible = { showConnectionIndicator }
  599. enableStatsDisplay = { true }
  600. iconSize = { iconSize }
  601. participantId = { id }
  602. statsPopoverPosition = { statsPopoverPosition } />
  603. }
  604. <RaisedHandIndicator
  605. iconSize = { iconSize }
  606. participantId = { id }
  607. tooltipPosition = { tooltipPosition } />
  608. { showDominantSpeaker && _participantCountMoreThan2
  609. && <DominantSpeakerIndicator
  610. iconSize = { iconSize }
  611. tooltipPosition = { tooltipPosition } />
  612. }
  613. </div>);
  614. }
  615. /**
  616. * Renders the avatar.
  617. *
  618. * @param {Object} styles - The styles that will be applied to the avatar.
  619. * @returns {ReactElement}
  620. */
  621. _renderAvatar(styles) {
  622. const { _participant } = this.props;
  623. const { id } = _participant;
  624. return (
  625. <div
  626. className = 'avatar-container'
  627. style = { styles }>
  628. <Avatar
  629. className = 'userAvatar'
  630. participantId = { id } />
  631. </div>
  632. );
  633. }
  634. /**
  635. * Returns the container class name.
  636. *
  637. * @returns {string} - The class name that will be used for the container.
  638. */
  639. _getContainerClassName() {
  640. let className = 'videocontainer';
  641. const { displayMode } = this.state;
  642. const { _isAudioOnly, _isDominantSpeakerDisabled, _isHidden, _participant } = this.props;
  643. const isRemoteParticipant = !_participant?.local && !_participant?.isFakeParticipant;
  644. className += ` ${DISPLAY_MODE_TO_CLASS_NAME[displayMode]}`;
  645. if (_participant?.pinned) {
  646. className += ' videoContainerFocused';
  647. }
  648. if (!_isDominantSpeakerDisabled && _participant?.dominantSpeaker) {
  649. className += ' active-speaker';
  650. }
  651. if (_isHidden) {
  652. className += ' hidden';
  653. }
  654. if (isRemoteParticipant && _isAudioOnly) {
  655. className += ' audio-only';
  656. }
  657. return className;
  658. }
  659. /**
  660. * Renders the local participant's thumbnail.
  661. *
  662. * @returns {ReactElement}
  663. */
  664. _renderLocalParticipant() {
  665. const {
  666. _defaultLocalDisplayName,
  667. _disableLocalVideoFlip,
  668. _height,
  669. _isMobile,
  670. _isMobilePortrait,
  671. _isScreenSharing,
  672. _localFlipX,
  673. _disableProfile,
  674. _participant,
  675. _videoTrack
  676. } = this.props;
  677. const { id } = _participant || {};
  678. const { audioLevel } = this.state;
  679. const styles = this._getStyles();
  680. const containerClassName = this._getContainerClassName();
  681. const videoTrackClassName
  682. = !_disableLocalVideoFlip && _videoTrack && !_isScreenSharing && _localFlipX ? 'flipVideoX' : '';
  683. styles.thumbnail.height = _isMobilePortrait
  684. ? `${Math.floor(_height * MOBILE_FILMSTRIP_PORTRAIT_RATIO)}px`
  685. : styles.thumbnail.height;
  686. return (
  687. <span
  688. className = { containerClassName }
  689. id = 'localVideoContainer'
  690. onClick = { this._onClick }
  691. { ...(_isMobile
  692. ? {
  693. onTouchEnd: this._onTouchEnd,
  694. onTouchMove: this._onTouchMove,
  695. onTouchStart: this._onTouchStart
  696. }
  697. : {
  698. onMouseEnter: this._onMouseEnter,
  699. onMouseLeave: this._onMouseLeave
  700. }
  701. ) }
  702. style = { styles.thumbnail }>
  703. <div className = 'videocontainer__background' />
  704. <span id = 'localVideoWrapper'>
  705. <VideoTrack
  706. className = { videoTrackClassName }
  707. id = 'localVideo_container'
  708. videoTrack = { _videoTrack } />
  709. </span>
  710. <div className = 'videocontainer__toolbar'>
  711. <StatusIndicators participantID = { id } />
  712. </div>
  713. <div className = 'videocontainer__toptoolbar'>
  714. { this._renderTopIndicators() }
  715. </div>
  716. <div className = 'videocontainer__hoverOverlay' />
  717. <div
  718. className = 'displayNameContainer'
  719. onClick = { onClick }>
  720. <DisplayName
  721. allowEditing = { !_disableProfile }
  722. displayNameSuffix = { _defaultLocalDisplayName }
  723. elementID = 'localDisplayName'
  724. participantID = { id } />
  725. </div>
  726. { this._renderAvatar(styles.avatar) }
  727. <span className = 'audioindicator-container'>
  728. <AudioLevelIndicator audioLevel = { audioLevel } />
  729. </span>
  730. <span className = 'localvideomenu'>
  731. <LocalVideoMenuTriggerButton
  732. getRef = { this._setInstance } />
  733. </span>
  734. </span>
  735. );
  736. }
  737. _onCanPlay: Object => void;
  738. /**
  739. * Canplay event listener.
  740. *
  741. * @param {SyntheticEvent} event - The event.
  742. * @returns {void}
  743. */
  744. _onCanPlay(event) {
  745. this.setState({ canPlayEventReceived: true });
  746. const {
  747. _isTestModeEnabled,
  748. _videoTrack
  749. } = this.props;
  750. if (_videoTrack && _isTestModeEnabled) {
  751. this._onTestingEvent(event);
  752. }
  753. }
  754. _onTestingEvent: Object => void;
  755. /**
  756. * Event handler for testing events.
  757. *
  758. * @param {SyntheticEvent} event - The event.
  759. * @returns {void}
  760. */
  761. _onTestingEvent(event) {
  762. const {
  763. _videoTrack,
  764. dispatch
  765. } = this.props;
  766. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  767. dispatch(updateLastTrackVideoMediaEvent(jitsiVideoTrack, event.type));
  768. }
  769. _setInstance: Object => void;
  770. /**
  771. * Stores the local or remote video menu button instance in a variable.
  772. *
  773. * @param {Object} instance - The local or remote video menu trigger instance.
  774. *
  775. * @returns {void}
  776. */
  777. _setInstance(instance) {
  778. this.videoMenuTriggerRef = instance;
  779. }
  780. /**
  781. * Renders a remote participant's 'thumbnail.
  782. *
  783. * @returns {ReactElement}
  784. */
  785. _renderRemoteParticipant() {
  786. const {
  787. _isMobile,
  788. _isTestModeEnabled,
  789. _participant,
  790. _startSilent,
  791. _videoTrack,
  792. _volume = 1
  793. } = this.props;
  794. const { id } = _participant;
  795. const { audioLevel, canPlayEventReceived } = this.state;
  796. const styles = this._getStyles();
  797. const containerClassName = this._getContainerClassName();
  798. // hide volume when in silent mode
  799. const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
  800. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  801. const videoTrackId = jitsiVideoTrack && jitsiVideoTrack.getId();
  802. const videoEventListeners = {};
  803. if (_videoTrack && _isTestModeEnabled) {
  804. VIDEO_TEST_EVENTS.forEach(attribute => {
  805. videoEventListeners[attribute] = this._onTestingEvent;
  806. });
  807. }
  808. videoEventListeners.onCanPlay = this._onCanPlay;
  809. const videoElementStyle = canPlayEventReceived ? null : {
  810. display: 'none'
  811. };
  812. return (
  813. <span
  814. className = { containerClassName }
  815. id = { `participant_${id}` }
  816. onClick = { this._onClick }
  817. { ...(_isMobile
  818. ? {
  819. onTouchEnd: this._onTouchEnd,
  820. onTouchMove: this._onTouchMove,
  821. onTouchStart: this._onTouchStart
  822. }
  823. : {
  824. onMouseEnter: this._onMouseEnter,
  825. onMouseLeave: this._onMouseLeave
  826. }
  827. ) }
  828. style = { styles.thumbnail }>
  829. {
  830. _videoTrack && <VideoTrack
  831. eventHandlers = { videoEventListeners }
  832. id = { `remoteVideo_${videoTrackId || ''}` }
  833. muted = { true }
  834. style = { videoElementStyle }
  835. videoTrack = { _videoTrack } />
  836. }
  837. <div className = 'videocontainer__background' />
  838. <div className = 'videocontainer__toptoolbar'>
  839. { this._renderTopIndicators() }
  840. </div>
  841. <div className = 'videocontainer__toolbar'>
  842. <StatusIndicators participantID = { id } />
  843. </div>
  844. <div className = 'videocontainer__hoverOverlay' />
  845. <div className = 'displayNameContainer'>
  846. <DisplayName
  847. elementID = { `participant_${id}_name` }
  848. participantID = { id } />
  849. </div>
  850. { this._renderAvatar(styles.avatar) }
  851. <div className = 'presence-label-container'>
  852. <PresenceLabel
  853. className = 'presence-label'
  854. participantID = { id } />
  855. </div>
  856. <span className = 'audioindicator-container'>
  857. <AudioLevelIndicator audioLevel = { audioLevel } />
  858. </span>
  859. <span className = 'remotevideomenu'>
  860. <RemoteVideoMenuTriggerButton
  861. getRef = { this._setInstance }
  862. initialVolumeValue = { _volume }
  863. onVolumeChange = { onVolumeChange }
  864. participantID = { id } />
  865. </span>
  866. </span>
  867. );
  868. }
  869. _onVolumeChange: number => void;
  870. /**
  871. * Handles volume changes.
  872. *
  873. * @param {number} value - The new value for the volume.
  874. * @returns {void}
  875. */
  876. _onVolumeChange(value) {
  877. const { _participant, dispatch } = this.props;
  878. const { id } = _participant;
  879. dispatch(setVolume(id, value));
  880. }
  881. /**
  882. * Implements React's {@link Component#render()}.
  883. *
  884. * @inheritdoc
  885. * @returns {ReactElement}
  886. */
  887. render() {
  888. const { _participant } = this.props;
  889. if (!_participant) {
  890. return null;
  891. }
  892. const { isFakeParticipant, local } = _participant;
  893. if (local) {
  894. return this._renderLocalParticipant();
  895. }
  896. if (isFakeParticipant) {
  897. return this._renderFakeParticipant();
  898. }
  899. return this._renderRemoteParticipant();
  900. }
  901. }
  902. /**
  903. * Maps (parts of) the redux state to the associated props for this component.
  904. *
  905. * @param {Object} state - The Redux state.
  906. * @param {Object} ownProps - The own props of the component.
  907. * @private
  908. * @returns {Props}
  909. */
  910. function _mapStateToProps(state, ownProps): Object {
  911. const { participantID } = ownProps;
  912. const participant = getParticipantByIdOrUndefined(state, participantID);
  913. const id = participant?.id;
  914. const isLocal = participant?.local ?? true;
  915. const tracks = state['features/base/tracks'];
  916. const { participantsVolume } = state['features/filmstrip'];
  917. const _videoTrack = isLocal
  918. ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participantID);
  919. const _audioTrack = isLocal
  920. ? getLocalAudioTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID);
  921. const _currentLayout = getCurrentLayout(state);
  922. let size = {};
  923. let _isMobilePortrait = false;
  924. const {
  925. startSilent,
  926. disableLocalVideoFlip,
  927. disableProfile,
  928. iAmRecorder,
  929. iAmSipGateway
  930. } = state['features/base/config'];
  931. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  932. const { localFlipX } = state['features/base/settings'];
  933. const _isMobile = isMobileBrowser();
  934. switch (_currentLayout) {
  935. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  936. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  937. const {
  938. horizontalViewDimensions = {
  939. local: {},
  940. remote: {}
  941. },
  942. verticalViewDimensions = {
  943. local: {},
  944. remote: {}
  945. }
  946. } = state['features/filmstrip'];
  947. const { local, remote }
  948. = _currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW
  949. ? verticalViewDimensions : horizontalViewDimensions;
  950. const { width, height } = isLocal ? local : remote;
  951. size = {
  952. _width: width,
  953. _height: height
  954. };
  955. _isMobilePortrait = _isMobile && state['features/base/responsive-ui'].aspectRatio === ASPECT_RATIO_NARROW;
  956. break;
  957. }
  958. case LAYOUTS.TILE_VIEW: {
  959. const { width, height } = state['features/filmstrip'].tileViewDimensions.thumbnailSize;
  960. size = {
  961. _width: width,
  962. _height: height
  963. };
  964. break;
  965. }
  966. }
  967. return {
  968. _audioTrack,
  969. _connectionIndicatorAutoHideEnabled:
  970. Boolean(state['features/base/config'].connectionIndicators?.autoHide ?? true),
  971. _connectionIndicatorDisabled: _isMobile
  972. || Boolean(state['features/base/config'].connectionIndicators?.disabled),
  973. _currentLayout,
  974. _defaultLocalDisplayName: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
  975. _disableLocalVideoFlip: Boolean(disableLocalVideoFlip),
  976. _disableProfile: disableProfile,
  977. _isHidden: isLocal && iAmRecorder && !iAmSipGateway,
  978. _isAudioOnly: Boolean(state['features/base/audio-only'].enabled),
  979. _isCurrentlyOnLargeVideo: state['features/large-video']?.participantId === id,
  980. _isDominantSpeakerDisabled: interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR,
  981. _isMobile,
  982. _isMobilePortrait,
  983. _isScreenSharing: _videoTrack?.videoType === 'desktop',
  984. _isTestModeEnabled: isTestModeEnabled(state),
  985. _isVideoPlayable: id && isVideoPlayable(state, id),
  986. _indicatorIconSize: NORMAL,
  987. _localFlipX: Boolean(localFlipX),
  988. _participant: participant,
  989. _participantCountMoreThan2: getParticipantCount(state) > 2,
  990. _startSilent: Boolean(startSilent),
  991. _videoTrack,
  992. _volume: isLocal ? undefined : id ? participantsVolume[id] : undefined,
  993. ...size
  994. };
  995. }
  996. export default connect(_mapStateToProps)(Thumbnail);