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

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