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

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