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.

functions.ts 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import logger from './logger';
  2. import { ElectronWindowType } from './types';
  3. /**
  4. * Begins a request to get available DesktopCapturerSources.
  5. *
  6. * @param {Object} options - Additional configuration for getting a list of
  7. * sources.
  8. * @param {Array} options.types - An array with DesktopCapturerSource type strings.
  9. * @param {Object} options.thumbnailSize - The desired height and width of the
  10. * return native image object used for the preview image of the source.
  11. * @returns {Function}
  12. */
  13. export function obtainDesktopSources(options: { thumbnailSize?: Object; types: string[]; }) {
  14. const { JitsiMeetElectron } = window as ElectronWindowType;
  15. // TODO: delete this after 2 releases
  16. if (JitsiMeetElectron?.obtainDesktopStreams) {
  17. return new Promise((resolve, reject) => {
  18. JitsiMeetElectron.obtainDesktopStreams(
  19. (sources: Array<{ id: string; }>) => resolve(_separateSourcesByType(sources)),
  20. (error: Error) => {
  21. logger.error(
  22. `Error while obtaining desktop sources: ${error}`);
  23. reject(error);
  24. },
  25. options
  26. );
  27. });
  28. }
  29. return APP.API.requestDesktopSources(options).then(
  30. ({ sources, error }: { error: Error; sources: Array<{ id: string; }>; }) => {
  31. if (sources) {
  32. return _separateSourcesByType(sources);
  33. } else if (error) {
  34. logger.error(
  35. `Error while obtaining desktop sources: ${error}`);
  36. return null;
  37. }
  38. });
  39. }
  40. /**
  41. * Check usage of old jitsi meet electron version.
  42. *
  43. * @returns {boolean} True if we use old jitsi meet electron, otherwise false.
  44. */
  45. export function oldJitsiMeetElectronUsage() {
  46. const { JitsiMeetElectron } = window as ElectronWindowType;
  47. if (JitsiMeetElectron?.obtainDesktopStreams) {
  48. return true;
  49. }
  50. return false;
  51. }
  52. /**
  53. * Converts an array of DesktopCapturerSources to an object with types for keys
  54. * and values being an array with sources of the key's type.
  55. *
  56. * @param {Array} sources - DesktopCapturerSources.
  57. * @private
  58. * @returns {Object} An object with the sources split into separate arrays based
  59. * on source type.
  60. */
  61. export function _separateSourcesByType(sources: Array<{ id: string; }> = []) {
  62. const sourcesByType: any = {
  63. screen: [],
  64. window: []
  65. };
  66. sources.forEach(source => {
  67. const idParts = source.id.split(':');
  68. const type = idParts[0];
  69. if (sourcesByType[type]) {
  70. sourcesByType[type].push(source);
  71. }
  72. });
  73. return sourcesByType;
  74. }