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.js 6.2KB

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