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 32KB

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