Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

functions.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const logger = require('jitsi-meet-logger').getLogger(__filename);
  2. /**
  3. * Begins a request to get available DesktopCapturerSources.
  4. *
  5. * @param {Array} types - An array with DesktopCapturerSource type strings.
  6. * @param {Object} options - Additional configuration for getting a list of
  7. * sources.
  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(types, options = {}) {
  13. const capturerOptions = {
  14. types
  15. };
  16. if (options.thumbnailSize) {
  17. capturerOptions.thumbnailSize = options.thumbnailSize;
  18. }
  19. return new Promise((resolve, reject) => {
  20. const { JitsiMeetElectron } = window;
  21. if (JitsiMeetElectron && JitsiMeetElectron.obtainDesktopStreams) {
  22. JitsiMeetElectron.obtainDesktopStreams(
  23. sources => resolve(_seperateSourcesByType(sources)),
  24. error => {
  25. logger.error(
  26. `Error while obtaining desktop sources: ${error}`);
  27. reject(error);
  28. },
  29. capturerOptions
  30. );
  31. } else {
  32. const reason = 'Called JitsiMeetElectron.obtainDesktopStreams'
  33. + ' but it is not defined';
  34. logger.error(reason);
  35. return Promise.reject(new Error(reason));
  36. }
  37. });
  38. }
  39. /**
  40. * Converts an array of DesktopCapturerSources to an object with types for keys
  41. * and values being an array with sources of the key's type.
  42. *
  43. * @param {Array} sources - DesktopCapturerSources.
  44. * @private
  45. * @returns {Object} An object with the sources split into seperate arrays based
  46. * on source type.
  47. */
  48. function _seperateSourcesByType(sources = []) {
  49. const sourcesByType = {
  50. screen: [],
  51. window: []
  52. };
  53. sources.forEach(source => {
  54. const idParts = source.id.split(':');
  55. const type = idParts[0];
  56. if (sourcesByType[type]) {
  57. sourcesByType[type].push(source);
  58. }
  59. });
  60. return sourcesByType;
  61. }