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

functions.js 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // @flow
  2. import { i18next, DEFAULT_LANGUAGE, LANGUAGES } from '../base/i18n';
  3. import { createLocalTrack } from '../base/lib-jitsi-meet/functions';
  4. import {
  5. getLocalParticipant,
  6. isLocalParticipantModerator
  7. } from '../base/participants';
  8. import { toState } from '../base/redux';
  9. import { parseStandardURIString } from '../base/util';
  10. import { isFollowMeActive } from '../follow-me';
  11. declare var interfaceConfig: Object;
  12. /**
  13. * Used for web. Indicates if the setting section is enabled.
  14. *
  15. * @param {string} settingName - The name of the setting section as defined in
  16. * interface_config.js and SettingsMenu.js.
  17. * @returns {boolean} True to indicate that the given setting section
  18. * is enabled, false otherwise.
  19. */
  20. export function isSettingEnabled(settingName: string) {
  21. return interfaceConfig.SETTINGS_SECTIONS.includes(settingName);
  22. }
  23. /**
  24. * Normalizes a URL entered by the user.
  25. * FIXME: Consider adding this to base/util/uri.
  26. *
  27. * @param {string} url - The URL to validate.
  28. * @returns {string|null} - The normalized URL, or null if the URL is invalid.
  29. */
  30. export function normalizeUserInputURL(url: string) {
  31. /* eslint-disable no-param-reassign */
  32. if (url) {
  33. url = url.replace(/\s/g, '').toLowerCase();
  34. const urlRegExp = new RegExp('^(\\w+://)?(.+)$');
  35. const urlComponents = urlRegExp.exec(url);
  36. if (urlComponents && (!urlComponents[1]
  37. || !urlComponents[1].startsWith('http'))) {
  38. url = `https://${urlComponents[2]}`;
  39. }
  40. const parsedURI = parseStandardURIString(url);
  41. if (!parsedURI.host) {
  42. return null;
  43. }
  44. return parsedURI.toString();
  45. }
  46. return url;
  47. /* eslint-enable no-param-reassign */
  48. }
  49. /**
  50. * Used for web. Returns whether or not only Device Selection is configured to
  51. * display as a setting.
  52. *
  53. * @returns {boolean}
  54. */
  55. export function shouldShowOnlyDeviceSelection() {
  56. return interfaceConfig.SETTINGS_SECTIONS.length === 1
  57. && isSettingEnabled('devices');
  58. }
  59. /**
  60. * Returns the properties for the "More" tab from settings dialog from Redux
  61. * state.
  62. *
  63. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  64. * {@code getState} function to be used to retrieve the state.
  65. * @returns {Object} - The properties for the "More" tab from settings dialog.
  66. */
  67. export function getMoreTabProps(stateful: Object | Function) {
  68. const state = toState(stateful);
  69. const language = i18next.language || DEFAULT_LANGUAGE;
  70. const {
  71. conference,
  72. followMeEnabled,
  73. startAudioMutedPolicy,
  74. startVideoMutedPolicy
  75. } = state['features/base/conference'];
  76. const followMeActive = isFollowMeActive(state);
  77. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  78. // The settings sections to display.
  79. const showModeratorSettings = Boolean(
  80. conference
  81. && configuredTabs.includes('moderator')
  82. && isLocalParticipantModerator(state));
  83. return {
  84. currentLanguage: language,
  85. followMeActive: Boolean(conference && followMeActive),
  86. followMeEnabled: Boolean(conference && followMeEnabled),
  87. languages: LANGUAGES,
  88. showLanguageSettings: configuredTabs.includes('language'),
  89. showModeratorSettings,
  90. startAudioMuted: Boolean(conference && startAudioMutedPolicy),
  91. startVideoMuted: Boolean(conference && startVideoMutedPolicy)
  92. };
  93. }
  94. /**
  95. * Returns the properties for the "Profile" tab from settings dialog from Redux
  96. * state.
  97. *
  98. * @param {(Function|Object)} stateful -The (whole) redux state, or redux's
  99. * {@code getState} function to be used to retrieve the state.
  100. * @returns {Object} - The properties for the "Profile" tab from settings
  101. * dialog.
  102. */
  103. export function getProfileTabProps(stateful: Object | Function) {
  104. const state = toState(stateful);
  105. const {
  106. authEnabled,
  107. authLogin,
  108. conference
  109. } = state['features/base/conference'];
  110. const localParticipant = getLocalParticipant(state);
  111. return {
  112. authEnabled: Boolean(conference && authEnabled),
  113. authLogin,
  114. displayName: localParticipant.name,
  115. email: localParticipant.email
  116. };
  117. }
  118. /**
  119. * Returns a promise which resolves with a list of objects containing
  120. * all the video jitsiTracks and appropriate errors for the given device ids.
  121. *
  122. * @param {string[]} ids - The list of the camera ids for wich to create tracks.
  123. *
  124. * @returns {Promise<Object[]>}
  125. */
  126. export function createLocalVideoTracks(ids: string[]) {
  127. return Promise.all(ids.map(deviceId => createLocalTrack('video', deviceId)
  128. .then(jitsiTrack => {
  129. return {
  130. jitsiTrack,
  131. deviceId
  132. };
  133. })
  134. .catch(() => {
  135. return {
  136. jitsiTrack: null,
  137. deviceId,
  138. error: 'deviceSelection.previewUnavailable'
  139. };
  140. })));
  141. }
  142. /**
  143. * Returns a promise which resolves with an object containing the corresponding
  144. * the audio jitsiTrack/error.
  145. *
  146. * @param {string} deviceId - The deviceId for the current microphone.
  147. *
  148. * @returns {Promise<Object>}
  149. */
  150. export function createLocalAudioTrack(deviceId: string) {
  151. return createLocalTrack('audio', deviceId)
  152. .then(jitsiTrack => {
  153. return {
  154. hasError: false,
  155. jitsiTrack
  156. };
  157. })
  158. .catch(() => {
  159. return {
  160. hasError: true,
  161. jitsiTrack: null
  162. };
  163. });
  164. }
  165. /**
  166. * Returns the visibility state of the audio settings.
  167. *
  168. * @param {Object} state - The state of the application.
  169. * @returns {boolean}
  170. */
  171. export function getAudioSettingsVisibility(state: Object) {
  172. return state['features/settings'].audioSettingsVisible;
  173. }
  174. /**
  175. * Returns the visibility state of the video settings.
  176. *
  177. * @param {Object} state - The state of the application.
  178. * @returns {boolean}
  179. */
  180. export function getVideoSettingsVisibility(state: Object) {
  181. return state['features/settings'].videoSettingsVisible;
  182. }