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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { createScreenSharingIssueEvent, sendAnalytics } from '../../../analytics';
  4. import { AudioLevelIndicator } from '../../../audio-level-indicator';
  5. import { Avatar } from '../../../base/avatar';
  6. import { isMobileBrowser } from '../../../base/environment/utils';
  7. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  8. import { MEDIA_TYPE, VideoTrack } from '../../../base/media';
  9. import {
  10. getParticipantByIdOrUndefined,
  11. getParticipantCount,
  12. pinParticipant
  13. } from '../../../base/participants';
  14. import { connect } from '../../../base/redux';
  15. import { ASPECT_RATIO_NARROW } from '../../../base/responsive-ui/constants';
  16. import { isTestModeEnabled } from '../../../base/testing';
  17. import {
  18. getLocalAudioTrack,
  19. getLocalVideoTrack,
  20. getTrackByMediaTypeAndParticipant,
  21. updateLastTrackVideoMediaEvent
  22. } from '../../../base/tracks';
  23. import { ConnectionIndicator } from '../../../connection-indicator';
  24. import { DisplayName } from '../../../display-name';
  25. import { StatusIndicators, RaisedHandIndicator, DominantSpeakerIndicator } from '../../../filmstrip';
  26. import { PresenceLabel } from '../../../presence-status';
  27. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  28. import { LocalVideoMenuTriggerButton, RemoteVideoMenuTriggerButton } from '../../../video-menu';
  29. import { setVolume } from '../../actions.web';
  30. import {
  31. DISPLAY_MODE_TO_CLASS_NAME,
  32. DISPLAY_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. const JitsiTrackEvents = JitsiMeetJS.events.track;
  39. declare var interfaceConfig: Object;
  40. /**
  41. * The type of the React {@code Component} state of {@link Thumbnail}.
  42. */
  43. export type State = {|
  44. /**
  45. * The current audio level value for the Thumbnail.
  46. */
  47. audioLevel: number,
  48. /**
  49. * Indicates that the canplay event has been received.
  50. */
  51. canPlayEventReceived: boolean,
  52. /**
  53. * The current display mode of the thumbnail.
  54. */
  55. displayMode: number,
  56. /**
  57. * Indicates whether the thumbnail is hovered or not.
  58. */
  59. isHovered: boolean
  60. |};
  61. /**
  62. * The type of the React {@code Component} props of {@link Thumbnail}.
  63. */
  64. export type Props = {|
  65. /**
  66. * The audio track related to the participant.
  67. */
  68. _audioTrack: ?Object,
  69. /**
  70. * Disable/enable the auto hide functionality for the connection indicator.
  71. */
  72. _connectionIndicatorAutoHideEnabled: boolean,
  73. /**
  74. * Disable/enable the connection indicator.
  75. */
  76. _connectionIndicatorDisabled: boolean,
  77. /**
  78. * The current layout of the filmstrip.
  79. */
  80. _currentLayout: string,
  81. /**
  82. * The default display name for the local participant.
  83. */
  84. _defaultLocalDisplayName: string,
  85. /**
  86. * Indicates whether the local video flip feature is disabled or not.
  87. */
  88. _disableLocalVideoFlip: boolean,
  89. /**
  90. * Indicates whether the profile functionality is disabled.
  91. */
  92. _disableProfile: boolean,
  93. /**
  94. * The display mode of the thumbnail.
  95. */
  96. _displayMode: number,
  97. /**
  98. * The height of the Thumbnail.
  99. */
  100. _height: number,
  101. /**
  102. * The aspect ratio of the Thumbnail in percents.
  103. */
  104. _heightToWidthPercent: number,
  105. /**
  106. * Indicates whether the thumbnail should be hidden or not.
  107. */
  108. _isHidden: boolean,
  109. /**
  110. * Indicates whether audio only mode is enabled.
  111. */
  112. _isAudioOnly: boolean,
  113. /**
  114. * Indicates whether the participant associated with the thumbnail is displayed on the large video.
  115. */
  116. _isCurrentlyOnLargeVideo: boolean,
  117. /**
  118. * Whether we are currently running in a mobile browser.
  119. */
  120. _isMobile: boolean,
  121. /**
  122. * Whether we are currently running in a mobile browser in portrait orientation.
  123. */
  124. _isMobilePortrait: boolean,
  125. /**
  126. * Indicates whether the participant is screen sharing.
  127. */
  128. _isScreenSharing: boolean,
  129. /**
  130. * Indicates whether the video associated with the thumbnail is playable.
  131. */
  132. _isVideoPlayable: boolean,
  133. /**
  134. * Disable/enable the dominant speaker indicator.
  135. */
  136. _isDominantSpeakerDisabled: boolean,
  137. /**
  138. * Indicates whether testing mode is enabled.
  139. */
  140. _isTestModeEnabled: boolean,
  141. /**
  142. * The size of the icon of indicators.
  143. */
  144. _indicatorIconSize: number,
  145. /**
  146. * The current local video flip setting.
  147. */
  148. _localFlipX: boolean,
  149. /**
  150. * An object with information about the participant related to the thumbnaul.
  151. */
  152. _participant: Object,
  153. /**
  154. * True if there are more than 2 participants in the call.
  155. */
  156. _participantCountMoreThan2: boolean,
  157. /**
  158. * Indicates whether the "start silent" mode is enabled.
  159. */
  160. _startSilent: Boolean,
  161. /**
  162. * The video track that will be displayed in the thumbnail.
  163. */
  164. _videoTrack: ?Object,
  165. /**
  166. * The volume level for the thumbnail.
  167. */
  168. _volume?: ?number,
  169. /**
  170. * The width of the thumbnail.
  171. */
  172. _width: number,
  173. /**
  174. * The redux dispatch function.
  175. */
  176. dispatch: Function,
  177. /**
  178. * The horizontal offset in px for the thumbnail. Used to center the thumbnails from the last row in tile view.
  179. */
  180. horizontalOffset: number,
  181. /**
  182. * The ID of the participant related to the thumbnail.
  183. */
  184. participantID: ?string,
  185. /**
  186. * Styles that will be set to the Thumbnail's main span element.
  187. */
  188. style?: ?Object
  189. |};
  190. /**
  191. * Click handler for the display name container.
  192. *
  193. * @param {SyntheticEvent} event - The click event.
  194. * @returns {void}
  195. */
  196. function onClick(event) {
  197. // If the event is propagated to the thumbnail container the participant will be pinned. That's why the propagation
  198. // needs to be stopped.
  199. event.stopPropagation();
  200. }
  201. /**
  202. * Implements a thumbnail.
  203. *
  204. * @extends Component
  205. */
  206. class Thumbnail extends Component<Props, State> {
  207. /**
  208. * The long touch setTimeout handler.
  209. */
  210. timeoutHandle: Object;
  211. /**
  212. * Reference to local or remote Video Menu trigger button instance.
  213. */
  214. videoMenuTriggerRef: Object;
  215. /**
  216. * Initializes a new Thumbnail instance.
  217. *
  218. * @param {Object} props - The read-only React Component props with which
  219. * the new instance is to be initialized.
  220. */
  221. constructor(props: Props) {
  222. super(props);
  223. const state = {
  224. audioLevel: 0,
  225. canPlayEventReceived: false,
  226. isHovered: false,
  227. displayMode: DISPLAY_VIDEO
  228. };
  229. this.state = {
  230. ...state,
  231. displayMode: computeDisplayMode(Thumbnail.getDisplayModeInput(props, state))
  232. };
  233. this.timeoutHandle = null;
  234. this.videoMenuTriggerRef = null;
  235. this._setInstance = this._setInstance.bind(this);
  236. this._updateAudioLevel = this._updateAudioLevel.bind(this);
  237. this._onCanPlay = this._onCanPlay.bind(this);
  238. this._onClick = this._onClick.bind(this);
  239. this._onVolumeChange = this._onVolumeChange.bind(this);
  240. this._onMouseEnter = this._onMouseEnter.bind(this);
  241. this._onMouseLeave = this._onMouseLeave.bind(this);
  242. this._onTestingEvent = this._onTestingEvent.bind(this);
  243. this._onTouchStart = this._onTouchStart.bind(this);
  244. this._onTouchEnd = this._onTouchEnd.bind(this);
  245. this._onTouchMove = this._onTouchMove.bind(this);
  246. this._showPopupMenu = this._showPopupMenu.bind(this);
  247. }
  248. /**
  249. * Starts listening for audio level updates after the initial render.
  250. *
  251. * @inheritdoc
  252. * @returns {void}
  253. */
  254. componentDidMount() {
  255. this._listenForAudioUpdates();
  256. this._onDisplayModeChanged();
  257. }
  258. /**
  259. * Stops listening for audio level updates on the old track and starts
  260. * listening instead on the new track.
  261. *
  262. * @inheritdoc
  263. * @returns {void}
  264. */
  265. componentDidUpdate(prevProps: Props, prevState: State) {
  266. if (prevProps._audioTrack !== this.props._audioTrack) {
  267. this._stopListeningForAudioUpdates(prevProps._audioTrack);
  268. this._listenForAudioUpdates();
  269. this._updateAudioLevel(0);
  270. }
  271. if (prevState.displayMode !== this.state.displayMode) {
  272. this._onDisplayModeChanged();
  273. }
  274. }
  275. /**
  276. * Handles display mode changes.
  277. *
  278. * @returns {void}
  279. */
  280. _onDisplayModeChanged() {
  281. const input = Thumbnail.getDisplayModeInput(this.props, this.state);
  282. this._maybeSendScreenSharingIssueEvents(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. _isMobilePortrait,
  664. _isScreenSharing,
  665. _localFlipX,
  666. _disableProfile,
  667. _participant,
  668. _videoTrack
  669. } = this.props;
  670. const { id } = _participant || {};
  671. const { audioLevel } = this.state;
  672. const styles = this._getStyles();
  673. let containerClassName = this._getContainerClassName();
  674. const videoTrackClassName
  675. = !_disableLocalVideoFlip && _videoTrack && !_isScreenSharing && _localFlipX ? 'flipVideoX' : '';
  676. if (_isMobilePortrait) {
  677. styles.thumbnail.height = styles.thumbnail.width;
  678. containerClassName = `${containerClassName} self-view-mobile-portrait`;
  679. }
  680. return (
  681. <span
  682. className = { containerClassName }
  683. id = 'localVideoContainer'
  684. onClick = { this._onClick }
  685. { ...(_isMobile
  686. ? {
  687. onTouchEnd: this._onTouchEnd,
  688. onTouchMove: this._onTouchMove,
  689. onTouchStart: this._onTouchStart
  690. }
  691. : {
  692. onMouseEnter: this._onMouseEnter,
  693. onMouseLeave: this._onMouseLeave
  694. }
  695. ) }
  696. style = { styles.thumbnail }>
  697. <div className = 'videocontainer__background' />
  698. <span id = 'localVideoWrapper'>
  699. <VideoTrack
  700. className = { videoTrackClassName }
  701. id = 'localVideo_container'
  702. videoTrack = { _videoTrack } />
  703. </span>
  704. <div className = 'videocontainer__toolbar'>
  705. <StatusIndicators participantID = { id } />
  706. </div>
  707. <div className = 'videocontainer__toptoolbar'>
  708. { this._renderTopIndicators() }
  709. </div>
  710. <div className = 'videocontainer__hoverOverlay' />
  711. <div
  712. className = 'displayNameContainer'
  713. onClick = { onClick }>
  714. <DisplayName
  715. allowEditing = { !_disableProfile }
  716. displayNameSuffix = { _defaultLocalDisplayName }
  717. elementID = 'localDisplayName'
  718. participantID = { id } />
  719. </div>
  720. { this._renderAvatar(styles.avatar) }
  721. <span className = 'audioindicator-container'>
  722. <AudioLevelIndicator audioLevel = { audioLevel } />
  723. </span>
  724. <span className = 'localvideomenu'>
  725. <LocalVideoMenuTriggerButton
  726. getRef = { this._setInstance } />
  727. </span>
  728. </span>
  729. );
  730. }
  731. _onCanPlay: Object => void;
  732. /**
  733. * Canplay event listener.
  734. *
  735. * @param {SyntheticEvent} event - The event.
  736. * @returns {void}
  737. */
  738. _onCanPlay(event) {
  739. this.setState({ canPlayEventReceived: true });
  740. const {
  741. _isTestModeEnabled,
  742. _videoTrack
  743. } = this.props;
  744. if (_videoTrack && _isTestModeEnabled) {
  745. this._onTestingEvent(event);
  746. }
  747. }
  748. _onTestingEvent: Object => void;
  749. /**
  750. * Event handler for testing events.
  751. *
  752. * @param {SyntheticEvent} event - The event.
  753. * @returns {void}
  754. */
  755. _onTestingEvent(event) {
  756. const {
  757. _videoTrack,
  758. dispatch
  759. } = this.props;
  760. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  761. dispatch(updateLastTrackVideoMediaEvent(jitsiVideoTrack, event.type));
  762. }
  763. _setInstance: Object => void;
  764. /**
  765. * Stores the local or remote video menu button instance in a variable.
  766. *
  767. * @param {Object} instance - The local or remote video menu trigger instance.
  768. *
  769. * @returns {void}
  770. */
  771. _setInstance(instance) {
  772. this.videoMenuTriggerRef = instance;
  773. }
  774. /**
  775. * Renders a remote participant's 'thumbnail.
  776. *
  777. * @returns {ReactElement}
  778. */
  779. _renderRemoteParticipant() {
  780. const {
  781. _isMobile,
  782. _isTestModeEnabled,
  783. _participant,
  784. _startSilent,
  785. _videoTrack,
  786. _volume = 1
  787. } = this.props;
  788. const { id } = _participant;
  789. const { audioLevel, canPlayEventReceived } = this.state;
  790. const styles = this._getStyles();
  791. const containerClassName = this._getContainerClassName();
  792. // hide volume when in silent mode
  793. const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
  794. const jitsiVideoTrack = _videoTrack?.jitsiTrack;
  795. const videoTrackId = jitsiVideoTrack && jitsiVideoTrack.getId();
  796. const videoEventListeners = {};
  797. if (_videoTrack && _isTestModeEnabled) {
  798. VIDEO_TEST_EVENTS.forEach(attribute => {
  799. videoEventListeners[attribute] = this._onTestingEvent;
  800. });
  801. }
  802. videoEventListeners.onCanPlay = this._onCanPlay;
  803. const videoElementStyle = canPlayEventReceived ? null : {
  804. display: 'none'
  805. };
  806. return (
  807. <span
  808. className = { containerClassName }
  809. id = { `participant_${id}` }
  810. onClick = { this._onClick }
  811. { ...(_isMobile
  812. ? {
  813. onTouchEnd: this._onTouchEnd,
  814. onTouchMove: this._onTouchMove,
  815. onTouchStart: this._onTouchStart
  816. }
  817. : {
  818. onMouseEnter: this._onMouseEnter,
  819. onMouseLeave: this._onMouseLeave
  820. }
  821. ) }
  822. style = { styles.thumbnail }>
  823. {
  824. _videoTrack && <VideoTrack
  825. eventHandlers = { videoEventListeners }
  826. id = { `remoteVideo_${videoTrackId || ''}` }
  827. muted = { true }
  828. style = { videoElementStyle }
  829. videoTrack = { _videoTrack } />
  830. }
  831. <div className = 'videocontainer__background' />
  832. <div className = 'videocontainer__toptoolbar'>
  833. { this._renderTopIndicators() }
  834. </div>
  835. <div className = 'videocontainer__toolbar'>
  836. <StatusIndicators participantID = { id } />
  837. </div>
  838. <div className = 'videocontainer__hoverOverlay' />
  839. <div className = 'displayNameContainer'>
  840. <DisplayName
  841. elementID = { `participant_${id}_name` }
  842. participantID = { id } />
  843. </div>
  844. { this._renderAvatar(styles.avatar) }
  845. <div className = 'presence-label-container'>
  846. <PresenceLabel
  847. className = 'presence-label'
  848. participantID = { id } />
  849. </div>
  850. <span className = 'audioindicator-container'>
  851. <AudioLevelIndicator audioLevel = { audioLevel } />
  852. </span>
  853. <span className = 'remotevideomenu'>
  854. <RemoteVideoMenuTriggerButton
  855. getRef = { this._setInstance }
  856. initialVolumeValue = { _volume }
  857. onVolumeChange = { onVolumeChange }
  858. participantID = { id } />
  859. </span>
  860. </span>
  861. );
  862. }
  863. _onVolumeChange: number => void;
  864. /**
  865. * Handles volume changes.
  866. *
  867. * @param {number} value - The new value for the volume.
  868. * @returns {void}
  869. */
  870. _onVolumeChange(value) {
  871. const { _participant, dispatch } = this.props;
  872. const { id } = _participant;
  873. dispatch(setVolume(id, value));
  874. }
  875. /**
  876. * Implements React's {@link Component#render()}.
  877. *
  878. * @inheritdoc
  879. * @returns {ReactElement}
  880. */
  881. render() {
  882. const { _participant } = this.props;
  883. if (!_participant) {
  884. return null;
  885. }
  886. const { isFakeParticipant, local } = _participant;
  887. if (local) {
  888. return this._renderLocalParticipant();
  889. }
  890. if (isFakeParticipant) {
  891. return this._renderFakeParticipant();
  892. }
  893. return this._renderRemoteParticipant();
  894. }
  895. }
  896. /**
  897. * Maps (parts of) the redux state to the associated props for this component.
  898. *
  899. * @param {Object} state - The Redux state.
  900. * @param {Object} ownProps - The own props of the component.
  901. * @private
  902. * @returns {Props}
  903. */
  904. function _mapStateToProps(state, ownProps): Object {
  905. const { participantID } = ownProps;
  906. const participant = getParticipantByIdOrUndefined(state, participantID);
  907. const id = participant?.id;
  908. const isLocal = participant?.local ?? true;
  909. const tracks = state['features/base/tracks'];
  910. const { participantsVolume } = state['features/filmstrip'];
  911. const _videoTrack = isLocal
  912. ? getLocalVideoTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, participantID);
  913. const _audioTrack = isLocal
  914. ? getLocalAudioTrack(tracks) : getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID);
  915. const _currentLayout = getCurrentLayout(state);
  916. let size = {};
  917. let _isMobilePortrait = false;
  918. const {
  919. startSilent,
  920. disableLocalVideoFlip,
  921. disableProfile,
  922. iAmRecorder,
  923. iAmSipGateway
  924. } = state['features/base/config'];
  925. const { NORMAL = 8 } = interfaceConfig.INDICATOR_FONT_SIZES || {};
  926. const { localFlipX } = state['features/base/settings'];
  927. const _isMobile = isMobileBrowser();
  928. switch (_currentLayout) {
  929. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  930. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW: {
  931. const {
  932. horizontalViewDimensions = {
  933. local: {},
  934. remote: {}
  935. },
  936. verticalViewDimensions = {
  937. local: {},
  938. remote: {}
  939. }
  940. } = state['features/filmstrip'];
  941. const { local, remote }
  942. = _currentLayout === LAYOUTS.VERTICAL_FILMSTRIP_VIEW
  943. ? verticalViewDimensions : horizontalViewDimensions;
  944. const { width, height } = isLocal ? local : remote;
  945. size = {
  946. _width: width,
  947. _height: height
  948. };
  949. _isMobilePortrait = _isMobile && state['features/base/responsive-ui'].aspectRatio === ASPECT_RATIO_NARROW;
  950. break;
  951. }
  952. case LAYOUTS.TILE_VIEW: {
  953. const { width, height } = state['features/filmstrip'].tileViewDimensions.thumbnailSize;
  954. size = {
  955. _width: width,
  956. _height: height
  957. };
  958. break;
  959. }
  960. }
  961. return {
  962. _audioTrack,
  963. _connectionIndicatorAutoHideEnabled:
  964. Boolean(state['features/base/config'].connectionIndicators?.autoHide ?? true),
  965. _connectionIndicatorDisabled: _isMobile
  966. || Boolean(state['features/base/config'].connectionIndicators?.disabled),
  967. _currentLayout,
  968. _defaultLocalDisplayName: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
  969. _disableLocalVideoFlip: Boolean(disableLocalVideoFlip),
  970. _disableProfile: disableProfile,
  971. _isHidden: isLocal && iAmRecorder && !iAmSipGateway,
  972. _isAudioOnly: Boolean(state['features/base/audio-only'].enabled),
  973. _isCurrentlyOnLargeVideo: state['features/large-video']?.participantId === id,
  974. _isDominantSpeakerDisabled: interfaceConfig.DISABLE_DOMINANT_SPEAKER_INDICATOR,
  975. _isMobile,
  976. _isMobilePortrait,
  977. _isScreenSharing: _videoTrack?.videoType === 'desktop',
  978. _isTestModeEnabled: isTestModeEnabled(state),
  979. _isVideoPlayable: id && isVideoPlayable(state, id),
  980. _indicatorIconSize: NORMAL,
  981. _localFlipX: Boolean(localFlipX),
  982. _participant: participant,
  983. _participantCountMoreThan2: getParticipantCount(state) > 2,
  984. _startSilent: Boolean(startSilent),
  985. _videoTrack,
  986. _volume: isLocal ? undefined : id ? participantsVolume[id] : undefined,
  987. ...size
  988. };
  989. }
  990. export default connect(_mapStateToProps)(Thumbnail);