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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import logger from './logger';
  2. /**
  3. * Begins a request to get available DesktopCapturerSources.
  4. *
  5. * @param {Object} options - Additional configuration for getting a list of
  6. * sources.
  7. * @param {Array} options.types - An array with DesktopCapturerSource type strings.
  8. * @param {Object} options.thumbnailSize - The desired height and width of the
  9. * return native image object used for the preview image of the source.
  10. * @returns {Function}
  11. */
  12. export function obtainDesktopSources(options: { thumbnailSize?: Object; types: string[]; }) {
  13. return APP.API.requestDesktopSources(options).then(
  14. ({ sources, error }: { error: Error; sources: Array<{ id: string; }>; }) => {
  15. if (sources) {
  16. return _separateSourcesByType(sources);
  17. } else if (error) {
  18. logger.error(
  19. `Error while obtaining desktop sources: ${error}`);
  20. return null;
  21. }
  22. });
  23. }
  24. /**
  25. * Converts an array of DesktopCapturerSources to an object with types for keys
  26. * and values being an array with sources of the key's type.
  27. *
  28. * @param {Array} sources - DesktopCapturerSources.
  29. * @private
  30. * @returns {Object} An object with the sources split into separate arrays based
  31. * on source type.
  32. */
  33. export function _separateSourcesByType(sources: Array<{ id: string; }> = []) {
  34. const sourcesByType: any = {
  35. screen: [],
  36. window: []
  37. };
  38. sources.forEach(source => {
  39. const idParts = source.id.split(':');
  40. const type = idParts[0];
  41. if (sourcesByType[type]) {
  42. sourcesByType[type].push(source);
  43. }
  44. });
  45. return sourcesByType;
  46. }