2018-01-26 10:19:43 +00:00
|
|
|
// @flow
|
2020-06-26 09:47:48 +00:00
|
|
|
|
|
|
|
import { SERVER_URL_CHANGE_ENABLED, getFeatureFlag } from '../base/flags';
|
2018-06-20 20:19:53 +00:00
|
|
|
import { i18next, DEFAULT_LANGUAGE, LANGUAGES } from '../base/i18n';
|
2020-03-30 14:17:18 +00:00
|
|
|
import { createLocalTrack } from '../base/lib-jitsi-meet/functions';
|
2019-05-30 21:10:40 +00:00
|
|
|
import {
|
|
|
|
getLocalParticipant,
|
|
|
|
isLocalParticipantModerator
|
|
|
|
} from '../base/participants';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { toState } from '../base/redux';
|
|
|
|
import { parseStandardURIString } from '../base/util';
|
2020-04-30 21:25:34 +00:00
|
|
|
import { isFollowMeActive } from '../follow-me';
|
2018-01-26 10:19:43 +00:00
|
|
|
|
2021-06-28 07:48:16 +00:00
|
|
|
import { SS_DEFAULT_FRAME_RATE, SS_SUPPORTED_FRAMERATES } from './constants';
|
|
|
|
|
2018-04-28 01:43:11 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for web. Indicates if the setting section is enabled.
|
|
|
|
*
|
|
|
|
* @param {string} settingName - The name of the setting section as defined in
|
|
|
|
* interface_config.js and SettingsMenu.js.
|
|
|
|
* @returns {boolean} True to indicate that the given setting section
|
|
|
|
* is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
export function isSettingEnabled(settingName: string) {
|
|
|
|
return interfaceConfig.SETTINGS_SECTIONS.includes(settingName);
|
|
|
|
}
|
|
|
|
|
2020-06-26 09:47:48 +00:00
|
|
|
/**
|
|
|
|
* Returns true if user is allowed to change Server URL.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful - The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @returns {boolean} True to indicate that user can change Server URL, false otherwise.
|
|
|
|
*/
|
|
|
|
export function isServerURLChangeEnabled(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const flag = getFeatureFlag(state, SERVER_URL_CHANGE_ENABLED, true);
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2018-01-26 10:19:43 +00:00
|
|
|
/**
|
|
|
|
* Normalizes a URL entered by the user.
|
|
|
|
* FIXME: Consider adding this to base/util/uri.
|
|
|
|
*
|
|
|
|
* @param {string} url - The URL to validate.
|
|
|
|
* @returns {string|null} - The normalized URL, or null if the URL is invalid.
|
|
|
|
*/
|
|
|
|
export function normalizeUserInputURL(url: string) {
|
|
|
|
/* eslint-disable no-param-reassign */
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
url = url.replace(/\s/g, '').toLowerCase();
|
2018-02-26 16:14:46 +00:00
|
|
|
|
2018-01-26 10:19:43 +00:00
|
|
|
const urlRegExp = new RegExp('^(\\w+://)?(.+)$');
|
|
|
|
const urlComponents = urlRegExp.exec(url);
|
|
|
|
|
2018-10-03 09:29:19 +00:00
|
|
|
if (urlComponents && (!urlComponents[1]
|
|
|
|
|| !urlComponents[1].startsWith('http'))) {
|
2018-01-26 10:19:43 +00:00
|
|
|
url = `https://${urlComponents[2]}`;
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:14:46 +00:00
|
|
|
const parsedURI = parseStandardURIString(url);
|
2018-01-26 10:19:43 +00:00
|
|
|
|
|
|
|
if (!parsedURI.host) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedURI.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
|
|
|
|
/* eslint-enable no-param-reassign */
|
|
|
|
}
|
2018-04-28 01:43:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for web. Returns whether or not only Device Selection is configured to
|
|
|
|
* display as a setting.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function shouldShowOnlyDeviceSelection() {
|
|
|
|
return interfaceConfig.SETTINGS_SECTIONS.length === 1
|
|
|
|
&& isSettingEnabled('devices');
|
|
|
|
}
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the properties for the "More" tab from settings dialog from Redux
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful -The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @returns {Object} - The properties for the "More" tab from settings dialog.
|
|
|
|
*/
|
|
|
|
export function getMoreTabProps(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
2021-06-28 07:48:16 +00:00
|
|
|
const framerate = state['features/screen-share'].captureFrameRate ?? SS_DEFAULT_FRAME_RATE;
|
2018-06-20 20:19:53 +00:00
|
|
|
const language = i18next.language || DEFAULT_LANGUAGE;
|
2018-08-06 15:24:59 +00:00
|
|
|
const {
|
|
|
|
conference,
|
|
|
|
followMeEnabled,
|
|
|
|
startAudioMutedPolicy,
|
|
|
|
startVideoMutedPolicy
|
|
|
|
} = state['features/base/conference'];
|
2020-04-30 21:25:34 +00:00
|
|
|
const followMeActive = isFollowMeActive(state);
|
2018-06-20 20:19:53 +00:00
|
|
|
const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
|
|
|
|
|
|
|
|
// The settings sections to display.
|
2018-08-06 15:24:59 +00:00
|
|
|
const showModeratorSettings = Boolean(
|
|
|
|
conference
|
|
|
|
&& configuredTabs.includes('moderator')
|
2019-05-30 21:10:40 +00:00
|
|
|
&& isLocalParticipantModerator(state));
|
2018-06-20 20:19:53 +00:00
|
|
|
|
|
|
|
return {
|
2021-06-28 07:48:16 +00:00
|
|
|
currentFramerate: framerate,
|
2018-06-20 20:19:53 +00:00
|
|
|
currentLanguage: language,
|
2021-06-28 07:48:16 +00:00
|
|
|
desktopShareFramerates: SS_SUPPORTED_FRAMERATES,
|
2019-04-26 18:11:53 +00:00
|
|
|
followMeActive: Boolean(conference && followMeActive),
|
2018-08-06 15:24:59 +00:00
|
|
|
followMeEnabled: Boolean(conference && followMeEnabled),
|
2018-06-20 20:19:53 +00:00
|
|
|
languages: LANGUAGES,
|
|
|
|
showLanguageSettings: configuredTabs.includes('language'),
|
|
|
|
showModeratorSettings,
|
2020-07-16 10:00:37 +00:00
|
|
|
showPrejoinSettings: state['features/base/config'].prejoinPageEnabled,
|
|
|
|
showPrejoinPage: !state['features/base/settings'].userSelectedSkipPrejoin,
|
2018-08-06 15:24:59 +00:00
|
|
|
startAudioMuted: Boolean(conference && startAudioMutedPolicy),
|
|
|
|
startVideoMuted: Boolean(conference && startVideoMutedPolicy)
|
2018-06-20 20:19:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the properties for the "Profile" tab from settings dialog from Redux
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @param {(Function|Object)} stateful -The (whole) redux state, or redux's
|
|
|
|
* {@code getState} function to be used to retrieve the state.
|
|
|
|
* @returns {Object} - The properties for the "Profile" tab from settings
|
|
|
|
* dialog.
|
|
|
|
*/
|
|
|
|
export function getProfileTabProps(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
2018-08-06 15:24:59 +00:00
|
|
|
const {
|
|
|
|
authEnabled,
|
|
|
|
authLogin,
|
|
|
|
conference
|
|
|
|
} = state['features/base/conference'];
|
2018-06-20 20:19:53 +00:00
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
return {
|
2018-08-06 15:24:59 +00:00
|
|
|
authEnabled: Boolean(conference && authEnabled),
|
2019-03-19 20:44:37 +00:00
|
|
|
authLogin,
|
2018-06-20 20:19:53 +00:00
|
|
|
displayName: localParticipant.name,
|
|
|
|
email: localParticipant.email
|
|
|
|
};
|
|
|
|
}
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a promise which resolves with a list of objects containing
|
|
|
|
* all the video jitsiTracks and appropriate errors for the given device ids.
|
|
|
|
*
|
2021-03-16 15:59:33 +00:00
|
|
|
* @param {string[]} ids - The list of the camera ids for which to create tracks.
|
2021-02-02 00:20:39 +00:00
|
|
|
* @param {number} [timeout] - A timeout for the createLocalTrack function call.
|
2020-03-30 14:17:18 +00:00
|
|
|
*
|
|
|
|
* @returns {Promise<Object[]>}
|
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
export function createLocalVideoTracks(ids: string[], timeout: ?number) {
|
|
|
|
return Promise.all(ids.map(deviceId => createLocalTrack('video', deviceId, timeout)
|
2020-03-30 14:17:18 +00:00
|
|
|
.then(jitsiTrack => {
|
|
|
|
return {
|
|
|
|
jitsiTrack,
|
|
|
|
deviceId
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
return {
|
|
|
|
jitsiTrack: null,
|
|
|
|
deviceId,
|
|
|
|
error: 'deviceSelection.previewUnavailable'
|
|
|
|
};
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-06-25 10:31:14 +00:00
|
|
|
* Returns a promise which resolves with a list of objects containing
|
|
|
|
* the audio track and the corresponding audio device information.
|
2020-03-30 14:17:18 +00:00
|
|
|
*
|
2020-06-25 10:31:14 +00:00
|
|
|
* @param {Object[]} devices - A list of microphone devices.
|
2021-02-02 00:20:39 +00:00
|
|
|
* @param {number} [timeout] - A timeout for the createLocalTrack function call.
|
2020-06-25 10:31:14 +00:00
|
|
|
* @returns {Promise<{
|
|
|
|
* deviceId: string,
|
|
|
|
* hasError: boolean,
|
|
|
|
* jitsiTrack: Object,
|
|
|
|
* label: string
|
|
|
|
* }[]>}
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2021-02-02 00:20:39 +00:00
|
|
|
export function createLocalAudioTracks(devices: Object[], timeout: ?number) {
|
2020-06-25 10:31:14 +00:00
|
|
|
return Promise.all(
|
|
|
|
devices.map(async ({ deviceId, label }) => {
|
|
|
|
let jitsiTrack = null;
|
|
|
|
let hasError = false;
|
|
|
|
|
|
|
|
try {
|
2021-02-02 00:20:39 +00:00
|
|
|
jitsiTrack = await createLocalTrack('audio', deviceId, timeout);
|
2020-06-25 10:31:14 +00:00
|
|
|
} catch (err) {
|
|
|
|
hasError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
deviceId,
|
|
|
|
hasError,
|
|
|
|
jitsiTrack,
|
|
|
|
label
|
|
|
|
};
|
|
|
|
}));
|
2020-03-30 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the visibility state of the audio settings.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the application.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function getAudioSettingsVisibility(state: Object) {
|
|
|
|
return state['features/settings'].audioSettingsVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the visibility state of the video settings.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the application.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function getVideoSettingsVisibility(state: Object) {
|
|
|
|
return state['features/settings'].videoSettingsVisible;
|
|
|
|
}
|