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.web.ts 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { IStateful } from '../base/app/types';
  2. import { createLocalTrack } from '../base/lib-jitsi-meet/functions';
  3. import { toState } from '../base/redux/functions';
  4. import { getUserSelectedCameraDeviceId } from '../base/settings/functions.web';
  5. import { areKeyboardShortcutsEnabled, getKeyboardShortcutsHelpDescriptions } from '../keyboard-shortcuts/functions';
  6. import { isPrejoinPageVisible } from '../prejoin/functions';
  7. export * from './functions.any';
  8. /**
  9. * Returns a promise which resolves with a list of objects containing
  10. * all the video jitsiTracks and appropriate errors for the given device ids.
  11. *
  12. * @param {string[]} ids - The list of the camera ids for which to create tracks.
  13. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  14. *
  15. * @returns {Promise<Object[]>}
  16. */
  17. export function createLocalVideoTracks(ids: string[], timeout?: number) {
  18. return Promise.all(ids.map(deviceId => createLocalTrack('video', deviceId, timeout)
  19. .then((jitsiTrack: any) => {
  20. return {
  21. jitsiTrack,
  22. deviceId
  23. };
  24. })
  25. .catch(() => {
  26. return {
  27. jitsiTrack: null,
  28. deviceId,
  29. error: 'deviceSelection.previewUnavailable'
  30. };
  31. })));
  32. }
  33. /**
  34. * Returns a promise which resolves with a list of objects containing
  35. * the audio track and the corresponding audio device information.
  36. *
  37. * @param {Object[]} devices - A list of microphone devices.
  38. * @param {number} [timeout] - A timeout for the createLocalTrack function call.
  39. * @returns {Promise<{
  40. * deviceId: string,
  41. * hasError: boolean,
  42. * jitsiTrack: Object,
  43. * label: string
  44. * }[]>}
  45. */
  46. export function createLocalAudioTracks(devices: Array<{ deviceId: string; label: string; }>, timeout?: number) {
  47. return Promise.all(
  48. devices.map(async ({ deviceId, label }) => {
  49. let jitsiTrack = null;
  50. let hasError = false;
  51. try {
  52. jitsiTrack = await createLocalTrack('audio', deviceId, timeout);
  53. } catch (err) {
  54. hasError = true;
  55. }
  56. return {
  57. deviceId,
  58. hasError,
  59. jitsiTrack,
  60. label
  61. };
  62. }));
  63. }
  64. /**
  65. * Returns the properties for the "Shortcuts" tab from settings dialog from Redux
  66. * state.
  67. *
  68. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  69. * {@code getState} function to be used to retrieve the state.
  70. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the shortcuts dialog is displayed on the
  71. * welcome page or not.
  72. * @returns {Object} - The properties for the "Shortcuts" tab from settings
  73. * dialog.
  74. */
  75. export function getShortcutsTabProps(stateful: IStateful, isDisplayedOnWelcomePage?: boolean) {
  76. const state = toState(stateful);
  77. return {
  78. displayShortcuts: !isDisplayedOnWelcomePage && !isPrejoinPageVisible(state),
  79. keyboardShortcutsEnabled: areKeyboardShortcutsEnabled(state),
  80. keyboardShortcutsHelpDescriptions: getKeyboardShortcutsHelpDescriptions(state)
  81. };
  82. }
  83. /**
  84. * Returns the properties for the "Virtual Background" tab from settings dialog from Redux
  85. * state.
  86. *
  87. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  88. * {@code getState} function to be used to retrieve the state.
  89. * @param {boolean} isDisplayedOnWelcomePage - Indicates whether the device selection dialog is displayed on the
  90. * welcome page or not.
  91. * @returns {Object} - The properties for the "Shortcuts" tab from settings
  92. * dialog.
  93. */
  94. export function getVirtualBackgroundTabProps(stateful: IStateful, isDisplayedOnWelcomePage?: boolean) {
  95. const state = toState(stateful);
  96. const settings = state['features/base/settings'];
  97. const userSelectedCamera = getUserSelectedCameraDeviceId(state);
  98. let selectedVideoInputId = settings.cameraDeviceId;
  99. if (isDisplayedOnWelcomePage) {
  100. selectedVideoInputId = userSelectedCamera;
  101. }
  102. return {
  103. options: state['features/virtual-background'],
  104. selectedVideoInputId
  105. };
  106. }