Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

functions.js 8.6KB

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