選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

functions.js 8.5KB

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