Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

functions.js 6.8KB

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