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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import React, { Component } from 'react';
  2. /**
  3. * React component for displaying a preview of a DesktopCapturerSource.
  4. *
  5. * @extends Component
  6. */
  7. class DesktopSourcePreview extends Component {
  8. /**
  9. * DesktopSourcePreview component's property types.
  10. *
  11. * @static
  12. */
  13. static propTypes = {
  14. /**
  15. * The callback to invoke when the component is clicked. The id of
  16. * the DesktopCapturerSource will be passed in.
  17. */
  18. onClick: React.PropTypes.func,
  19. /**
  20. * The callback to invoke when the component is double clicked. The id
  21. * of the DesktopCapturerSource will be passed in.
  22. */
  23. onDoubleClick: React.PropTypes.func,
  24. /**
  25. * The indicator which determines whether this DesktopSourcePreview is
  26. * selected. If true, the 'is-selected' CSS class will be added to the
  27. * Component.
  28. */
  29. selected: React.PropTypes.bool,
  30. /**
  31. * The DesktopCapturerSource to display.
  32. */
  33. source: React.PropTypes.object,
  34. /**
  35. * The source type of the DesktopCapturerSources to display.
  36. */
  37. type: React.PropTypes.string
  38. };
  39. /**
  40. * Initializes a new DesktopSourcePreview instance.
  41. *
  42. * @param {Object} props - The read-only properties with which the new
  43. * instance is to be initialized.
  44. */
  45. constructor(props) {
  46. super(props);
  47. this._onClick = this._onClick.bind(this);
  48. this._onDoubleClick = this._onDoubleClick.bind(this);
  49. }
  50. /**
  51. * Implements React's {@link Component#render()}.
  52. *
  53. * @inheritdoc
  54. * @returns {ReactElement}
  55. */
  56. render() {
  57. const selectedClass = this.props.selected ? 'is-selected' : '';
  58. const displayClasses = `desktop-picker-source ${selectedClass}`;
  59. return (
  60. <div
  61. className = { displayClasses }
  62. onClick = { this._onClick }
  63. onDoubleClick = { this._onDoubleClick }>
  64. <div className = 'desktop-source-preview-image-container'>
  65. <img
  66. className = 'desktop-source-preview-thumbnail'
  67. src = { this.props.source.thumbnail.toDataURL() } />
  68. </div>
  69. <div className = 'desktop-source-preview-label'>
  70. { this.props.source.name }
  71. </div>
  72. </div>
  73. );
  74. }
  75. /**
  76. * Invokes the passed in onClick callback.
  77. *
  78. * @returns {void}
  79. */
  80. _onClick() {
  81. const { source, type } = this.props;
  82. this.props.onClick(source.id, type);
  83. }
  84. /**
  85. * Invokes the passed in onDoubleClick callback.
  86. *
  87. * @returns {void}
  88. */
  89. _onDoubleClick() {
  90. const { source, type } = this.props;
  91. this.props.onDoubleClick(source.id, type);
  92. }
  93. }
  94. export default DesktopSourcePreview;