您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions.web.ts 5.4KB

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