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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  581. statsPopoverPosition = 'top';
  582. tooltipPosition = 'top';
  583. break;
  584. default:
  585. statsPopoverPosition = 'auto';
  586. tooltipPosition = 'top';
  587. }
  588. return (
  589. <div>
  590. { !_connectionIndicatorDisabled
  591. && <ConnectionIndicator
  592. alwaysVisible = { showConnectionIndicator }
  593. enableStatsDisplay = { true }
  594. iconSize = { iconSize }
  595. participantId = { id }
  596. statsPopoverPosition = { statsPopoverPosition } />
  597. }
  598. <RaisedHandIndicator
  599. iconSize = { iconSize }
  600. participantId = { id }
  601. tooltipPosition = { tooltipPosition } />
  602. { showDominantSpeaker && _participantCountMoreThan2
  603. && <DominantSpeakerIndicator
  604. iconSize = { iconSize }
  605. tooltipPosition = { tooltipPosition } />
  606. }
  607. </div>);
  608. }
  609. /**
  610. * Renders the avatar.
  611. *
  612. * @param {Object} styles - The styles that will be applied to the avatar.
  613. * @returns {ReactElement}
  614. */
  615. _renderAvatar(styles) {
  616. const { _participant } = this.props;
  617. const { id } = _participant;
  618. return (
  619. <div
  620. className = 'avatar-container'
  621. style = { styles }>
  622. <Avatar
  623. className = 'userAvatar'
  624. participantId = { id } />
  625. </div>
  626. );
  627. }
  628. /**
  629. * Returns the container class name.
  630. *
  631. * @returns {string} - The class name that will be used for the container.
  632. */
  633. _getContainerClassName() {
  634. let className = 'videocontainer';
  635. const { displayMode } = this.state;
  636. const { _isAudioOnly, _isDominantSpeakerDisabled, _isHidden, _participant } = this.props;
  637. const isRemoteParticipant = !_participant?.local && !_participant?.isFakeParticipant;
  638. className += ` ${DISPLAY_MODE_TO_CLASS_NAME[displayMode]}`;
  639. if (_participant?.pinned) {
  640. className += ' videoContainerFocused';
  641. }
  642. if (!_isDominantSpeakerDisabled && _participant?.dominantSpeaker) {
  643. className += ' active-speaker';
  644. }
  645. if (_isHidden) {
  646. className += ' hidden';
  647. }
  648. if (isRemoteParticipant && _isAudioOnly) {
  649. className += ' audio-only';
  650. }
  651. return className;
  652. }
  653. /**
  654. * Renders the local participant's thumbnail.
  655. *
  656. * @returns {ReactElement}
  657. */
  658. _renderLocalParticipant() {
  659. const {
  660. _defaultLocalDisplayName,
  661. _disableLocalVideoFlip,
  662. _isMobile,
  663. _isScreenSharing,
  664. _localFlipX,
  665. _disableProfile,
  666. _participant,
  667. _videoTrack
  668. } = this.props;
  669. const { id } = _participant || {};
  670. const { audioLevel } = this.state;
  671. const styles = this._getStyles();
  672. const containerClassName = this._getContainerClassName();
  673. const videoTrackClassName
  674. = !_disableLocalVideoFlip && _videoTrack && !_isScreenSharing && _localFlipX ? 'flipVideoX' : '';
  675. return (
  676. <span
  677. className = { containerClassName }
  678. id = 'localVideoContainer'
  679. onClick = { this._onClick }
  680. { ...(_isMobile
  681. ? {
  682. onTouchEnd: this._onTouchEnd,
  683. onTouchMove: this._onTouchMove,
  684. onTouchStart: this._onTouchStart
  685. }
  686. : {
  687. onMouseEnter: this._onMouseEnter,
  688. onMouseLeave: this._onMouseLeave
  689. }
  690. ) }
  691. style = { styles.thumbnail }>
  692. <div className = 'videocontainer__background' />
  693. <span id = 'localVideoWrapper'>
  694. <VideoTrack
  695. className = { videoTrackClassName }
  696. id = 'localVideo_container'
  697. videoTrack = { _videoTrack } />
  698. </span>
  699. <div className = 'videocontainer__toolbar'>
  700. <StatusIndicators participantID = { id } />
  701. </div>
  702. <div className = 'videocontainer__toptoolbar'>
  703. { this._renderTopIndicators() }
  704. </div>
  705. <div className = 'videocontainer__hoverOverlay' />
  706. <div
  707. className = 'displayNameContainer'
  708. onClick = { onClick }>
  709. <DisplayName
  710. allowEditing = { !_disableProfile }
  711. displayNameSuffix = { _defaultLocalDisplayName }
  712. elementID = 'localDisplayName'
  713. participantID = { id } />
  714. </div>
  715. { this._renderAvatar(styles.avatar) }
  716. <span className = 'audioindicator-container'>
  717. <AudioLevelIndicator audioLevel = { audioLevel } />
  718. </span>
  719. <span className = 'localvideomenu'>
  720. <LocalVideoMenuTriggerButton
  721. getRef = { this._setInstance } />
  722. </span>
  723. </span>
  724. );
  725. }
  726. _onCanPlay: Object => void;
  727. /**
  728. * Canplay event listener.
  729. *
  730. * @param {SyntheticEvent} event - The event.
  731. * @returns {void}
  732. */
  733. _onCanPlay(event) {
  734. this.setState({ canPlayEventReceived: true });
  735. const {
  736. _isTestModeEnabled,
  737. _videoTrack
  738. } = this.props;
  739. if (_videoTrack && _isTestModeEnabled) {
  740. this._onTestingEvent(event);
  741. }
  742. }
  743. _onTestingEvent: Object => void;
  744. /**
  745. * Event handler for testing events.
  746. *
  747. * @param {SyntheticEvent} event - The event.
  748. * @returns {void}
  749. */
  750. _onTestingEvent(event) {
  751. const {
  752. _videoTrack,
  753. dispatch
  754. } = this.props;
  755. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  756. dispatch(updateLastTrackVideoMediaEvent(jitsiVideoTrack, event.type));
  757. }
  758. _setInstance: Object => void;
  759. /**
  760. * Stores the local or remote video menu button instance in a variable.
  761. *
  762. * @param {Object} instance - The local or remote video menu trigger instance.
  763. *
  764. * @returns {void}
  765. */
  766. _setInstance(instance) {
  767. this.videoMenuTriggerRef = instance;
  768. }
  769. /**
  770. * Renders a remote participant's 'thumbnail.
  771. *
  772. * @returns {ReactElement}
  773. */
  774. _renderRemoteParticipant() {
  775. const {
  776. _isMobile,
  777. _isTestModeEnabled,
  778. _participant,
  779. _startSilent,
  780. _videoTrack,
  781. _volume = 1
  782. } = this.props;
  783. const { id } = _participant;
  784. const { audioLevel, canPlayEventReceived } = this.state;
  785. const styles = this._getStyles();
  786. const containerClassName = this._getContainerClassName();
  787. // hide volume when in silent mode
  788. const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
  789. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  790. const videoTrackId = jitsiVideoTrack && jitsiVideoTrack.getId();
  791. const videoEventListeners = {};
  792. if (_videoTrack && _isTestModeEnabled) {
  793. VIDEO_TEST_EVENTS.forEach(attribute => {
  794. videoEventListeners[attribute] = this._onTestingEvent;
  795. });
  796. }
  797. videoEventListeners.onCanPlay = this._onCanPlay;
  798. const videoElementStyle = canPlayEventReceived ? null : {
  799. display: 'none'
  800. };
  801. return (
  802. <span
  803. className = { containerClassName }
  804. id = { `participant_${id}` }
  805. onClick = { this._onClick }
  806. { ...(_isMobile
  807. ? {
  808. onTouchEnd: this._onTouchEnd,
  809. onTouchMove: this._onTouchMove,
  810. onTouchStart: this._onTouchStart
  811. }
  812. : {
  813. onMouseEnter: this._onMouseEnter,
  814. onMouseLeave: this._onMouseLeave
  815. }
  816. ) }
  817. style = { styles.thumbnail }>
  818. {
  819. _videoTrack && <VideoTrack
  820. eventHandlers = { videoEventListeners }
  821. id = { `remoteVideo_${videoTrackId || ''}` }
  822. muted = { true }
  823. style = { videoElementStyle }
  824. videoTrack = { _videoTrack } />
  825. }
  826. <div className = 'videocontainer__background' />
  827. <div className = 'videocontainer__toptoolbar'>
  828. { this._renderTopIndicators() }
  829. </div>
  830. <div className = 'videocontainer__toolbar'>
  831. <StatusIndicators participantID = { id } />
  832. </div>
  833. <div className = 'videocontainer__hoverOverlay' />
  834. <div className = 'displayNameContainer'>
  835. <DisplayName
  836. elementID = { `participant_${id}_name` }
  837. participantID = { id } />
  838. </div>
  839. { this._renderAvatar(styles.avatar) }
  840. <div className = 'presence-label-container'>
  841. <PresenceLabel
  842. className = 'presence-label'
  843. participantID = { id } />
  844. </div>
  845. <span className = 'audioindicator-container'>
  846. <AudioLevelIndicator audioLevel = { audioLevel } />
  847. </span>
  848. <span className = 'remotevideomenu'>
  849. <RemoteVideoMenuTriggerButton
  850. getRef = { this._setInstance }
  851. initialVolumeValue = { _volume }
  852. onVolumeChange = { onVolumeChange }
  853. participantID = { id } />
  854. </span>
  855. </span>
  856. );
  857. }
  858. _onVolumeChange: number => void;
  859. /**
  860. * Handles volume changes.
  861. *
  862. * @param {number} value - The new value for the volume.
  863. * @returns {void}
  864. */
  865. _onVolumeChange(value) {
  866. const { _participant, dispatch } = this.props;
  867. const { id } = _participant;
  868. dispatch(setVolume(id, value));
  869. }
  870. /**
  871. * Implements React's {@link Component#render()}.
  872. *
  873. * @inheritdoc
  874. * @returns {ReactElement}
  875. */
  876. render() {
  877. const { _participant } = this.props;
  878. if (!_participant) {
  879. return null;
  880. }
  881. const { isFakeParticipant, local } = _participant;
  882. if (local) {
  883. return this._renderLocalParticipant();
  884. }
  885. if (isFakeParticipant) {
  886. return this._renderFakeParticipant();
  887. }
  888. return this._renderRemoteParticipant();
  889. }
  890. }
  891. /**
  892. * Maps (parts of) the redux state to the associated props for this component.
  893. *
  894. * @param {Object} state - The Redux state.
  895. * @param {Object} ownProps - The own props of the component.
  896. * @private
  897. * @returns {Props}
  898. */
  899. function _mapStateToProps(state, ownProps): Object {
  900. const { participantID } = ownProps;
  901. const participant = getParticipantByIdOrUndefined(state, participantID);
  902. const id = participant?.id;
  903. const isLocal = participant?.local ?? true;
  904. const tracks = state['features/base/tracks'];
  905. const { participantsVolume } = state['features/filmstrip'];
  906. const _videoTrack = isLocal
  907. ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participantID);
  908. const _audioTrack = isLocal
  909. ? getLocalAudioTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID);
  910. const _currentLayout = getCurrentLayout(state);
  911. let size = {};
  912. const {
  913. startSilent,
  914. disableLocalVideoFlip,
  915. disableProfile,
  916. iAmRecorder,
  917. iAmSipGateway
  918. } = state['features/base/config'];
  919. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  920. const { localFlipX } = state['features/base/settings'];
  921. const _isMobile = isMobileBrowser();
  922. switch (_currentLayout) {
  923. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  924. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  925. const {
  926. horizontalViewDimensions = {
  927. local: {},
  928. remote: {}
  929. },
  930. verticalViewDimensions = {
  931. local: {},
  932. remote: {}
  933. }
  934. } = state['features/filmstrip'];
  935. const { local, remote }
  936. = _currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW
  937. ? verticalViewDimensions : horizontalViewDimensions;
  938. const { width, height } = isLocal ? local : remote;
  939. size = {
  940. _width: width,
  941. _height: height
  942. };
  943. break;
  944. }
  945. case LAYOUTS.TILE_VIEW: {
  946. const { width, height } = state['features/filmstrip'].tileViewDimensions.thumbnailSize;
  947. size = {
  948. _width: width,
  949. _height: height
  950. };
  951. break;
  952. }
  953. }
  954. return {
  955. _audioTrack,
  956. _connectionIndicatorAutoHideEnabled:
  957. Boolean(state['features/base/config'].connectionIndicators?.autoHide ?? true),
  958. _connectionIndicatorDisabled: _isMobile
  959. || Boolean(state['features/base/config'].connectionIndicators?.disabled),
  960. _currentLayout,
  961. _defaultLocalDisplayName: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
  962. _disableLocalVideoFlip: Boolean(disableLocalVideoFlip),
  963. _disableProfile: disableProfile,
  964. _isHidden: isLocal && iAmRecorder && !iAmSipGateway,
  965. _isAudioOnly: Boolean(state['features/base/audio-only'].enabled),
  966. _isCurrentlyOnLargeVideo: state['features/large-video']?.participantId === id,
  967. _isDominantSpeakerDisabled: interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR,
  968. _isMobile,
  969. _isScreenSharing: _videoTrack?.videoType === 'desktop',
  970. _isTestModeEnabled: isTestModeEnabled(state),
  971. _isVideoPlayable: id && isVideoPlayable(state, id),
  972. _indicatorIconSize: NORMAL,
  973. _localFlipX: Boolean(localFlipX),
  974. _participant: participant,
  975. _participantCountMoreThan2: getParticipantCount(state) > 2,
  976. _startSilent: Boolean(startSilent),
  977. _videoTrack,
  978. _volume: isLocal ? undefined : id ? participantsVolume[id] : undefined,
  979. ...size
  980. };
  981. }
  982. export default connect(_mapStateToProps)(Thumbnail);