Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Thumbnail.js 29KB

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