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.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. /**
  4. * React component for displaying a preview of a DesktopCapturerSource.
  5. *
  6. * @extends Component
  7. */
  8. class DesktopSourcePreview extends Component {
  9. /**
  10. * DesktopSourcePreview component's property types.
  11. *
  12. * @static
  13. */
  14. static propTypes = {
  15. /**
  16. * The callback to invoke when the component is clicked. The id of
  17. * the DesktopCapturerSource will be passed in.
  18. */
  19. onClick: PropTypes.func,
  20. /**
  21. * The callback to invoke when the component is double clicked. The id
  22. * of the DesktopCapturerSource will be passed in.
  23. */
  24. onDoubleClick: PropTypes.func,
  25. /**
  26. * The indicator which determines whether this DesktopSourcePreview is
  27. * selected. If true, the 'is-selected' CSS class will be added to the
  28. * Component.
  29. */
  30. selected: PropTypes.bool,
  31. /**
  32. * The DesktopCapturerSource to display.
  33. */
  34. source: PropTypes.object,
  35. /**
  36. * The source type of the DesktopCapturerSources to display.
  37. */
  38. type: PropTypes.string
  39. };
  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) {
  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. <div className = 'desktop-source-preview-image-container'>
  66. <img
  67. className = 'desktop-source-preview-thumbnail'
  68. src = { this.props.source.thumbnail.toDataURL() } />
  69. </div>
  70. <div className = 'desktop-source-preview-label'>
  71. { this.props.source.name }
  72. </div>
  73. </div>
  74. );
  75. }
  76. /**
  77. * Invokes the passed in onClick callback.
  78. *
  79. * @returns {void}
  80. */
  81. _onClick() {
  82. const { source, type } = this.props;
  83. this.props.onClick(source.id, type);
  84. }
  85. /**
  86. * Invokes the passed in onDoubleClick callback.
  87. *
  88. * @returns {void}
  89. */
  90. _onDoubleClick() {
  91. const { source, type } = this.props;
  92. this.props.onDoubleClick(source.id, type);
  93. }
  94. }
  95. export default DesktopSourcePreview;