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.

DesktopSourcePreview.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { translate } from '../../base/i18n/functions';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link DesktopSourcePreview}.
  7. */
  8. interface IProps extends WithTranslation {
  9. /**
  10. * The callback to invoke when the component is clicked. The id of the
  11. * clicked on DesktopCapturerSource will be passed in.
  12. */
  13. onClick: Function;
  14. /**
  15. * The callback to invoke when the component is double clicked. The id of
  16. * the DesktopCapturerSource will be passed in.
  17. */
  18. onDoubleClick: Function;
  19. /**
  20. * The indicator which determines whether this DesktopSourcePreview is
  21. * selected. If true, the 'is-selected' CSS class will be added to the root
  22. * of Component.
  23. */
  24. selected: boolean;
  25. /**
  26. * The DesktopCapturerSource to display.
  27. */
  28. source: any;
  29. /**
  30. * The source type of the DesktopCapturerSources to display.
  31. */
  32. type: string;
  33. }
  34. /**
  35. * React component for displaying a preview of a DesktopCapturerSource.
  36. *
  37. * @augments Component
  38. */
  39. class DesktopSourcePreview extends Component<IProps> {
  40. /**
  41. * Initializes a new DesktopSourcePreview instance.
  42. *
  43. * @param {Object} props - The read-only properties with which the new
  44. * instance is to be initialized.
  45. */
  46. constructor(props: IProps) {
  47. super(props);
  48. this._onClick = this._onClick.bind(this);
  49. this._onDoubleClick = this._onDoubleClick.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#render()}.
  53. *
  54. * @inheritdoc
  55. * @returns {ReactElement}
  56. */
  57. render() {
  58. const selectedClass = this.props.selected ? 'is-selected' : '';
  59. const displayClasses = `desktop-picker-source ${selectedClass}`;
  60. return (
  61. <div
  62. className = { displayClasses }
  63. onClick = { this._onClick }
  64. onDoubleClick = { this._onDoubleClick }>
  65. {this._renderThumbnailImageContainer()}
  66. <div className = 'desktop-source-preview-label'>
  67. { this.props.source.name }
  68. </div>
  69. </div>
  70. );
  71. }
  72. /**
  73. * Render thumbnail screenshare image.
  74. *
  75. * @returns {Object} - Thumbnail image.
  76. */
  77. _renderThumbnailImageContainer() {
  78. // default data URL for thumnbail image
  79. let srcImage = this.props.source.thumbnail.dataUrl;
  80. // legacy thumbnail image
  81. if (typeof this.props.source.thumbnail.toDataURL === 'function') {
  82. srcImage = this.props.source.thumbnail.toDataURL();
  83. }
  84. return (
  85. <div className = 'desktop-source-preview-image-container'>
  86. { this._renderThumbnailImage(srcImage) }
  87. </div>
  88. );
  89. }
  90. /**
  91. * Render thumbnail screenshare image.
  92. *
  93. * @param {string} src - Of the image.
  94. * @returns {Object} - Thumbnail image.
  95. */
  96. _renderThumbnailImage(src: string) {
  97. return (
  98. <img
  99. alt = { this.props.t('welcomepage.logo.desktopPreviewThumbnail') }
  100. className = 'desktop-source-preview-thumbnail'
  101. src = { src } />
  102. );
  103. }
  104. /**
  105. * Invokes the passed in onClick callback.
  106. *
  107. * @returns {void}
  108. */
  109. _onClick() {
  110. const { source, type } = this.props;
  111. this.props.onClick(source.id, type);
  112. }
  113. /**
  114. * Invokes the passed in onDoubleClick callback.
  115. *
  116. * @returns {void}
  117. */
  118. _onDoubleClick() {
  119. const { source, type } = this.props;
  120. this.props.onDoubleClick(source.id, type);
  121. }
  122. }
  123. export default translate(DesktopSourcePreview);