2018-04-11 17:02:31 +00:00
|
|
|
// @flow
|
2020-05-07 22:26:37 +00:00
|
|
|
import { CONFIG_WHITELIST } from '../config';
|
2021-12-16 16:55:45 +00:00
|
|
|
import { getParticipantCount } from '../participants';
|
2018-04-11 17:02:31 +00:00
|
|
|
import { toState } from '../redux';
|
2020-05-07 22:26:37 +00:00
|
|
|
import { parseURLParams } from '../util';
|
2018-04-11 17:02:31 +00:00
|
|
|
|
2018-07-11 08:57:07 +00:00
|
|
|
import { DEFAULT_SERVER_URL } from './constants';
|
2018-04-12 19:58:20 +00:00
|
|
|
|
2018-04-11 17:02:31 +00:00
|
|
|
/**
|
2018-04-13 10:57:12 +00:00
|
|
|
* Returns the effective value of a configuration/preference/setting by applying
|
2018-04-12 19:58:20 +00:00
|
|
|
* a precedence among the values specified by JWT, URL, settings,
|
|
|
|
* and config.
|
2018-04-11 17:02:31 +00:00
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {Object|Function} stateful - The redux state object or {@code getState} function.
|
2018-04-13 10:57:12 +00:00
|
|
|
* @param {string} propertyName - The name of the
|
|
|
|
* configuration/preference/setting (property) to retrieve.
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {Object} sources - Flags indicating the configuration/preference/setting sources to
|
|
|
|
* consider/retrieve values from.
|
|
|
|
* @param {boolean} sources.config - Config.
|
|
|
|
* @param {boolean} jwt - JWT.
|
|
|
|
* @param {boolean} settings - Settings.
|
|
|
|
* @param {boolean} urlParams - URL parameters.
|
2018-04-11 17:02:31 +00:00
|
|
|
* @returns {any}
|
|
|
|
*/
|
|
|
|
export function getPropertyValue(
|
|
|
|
stateful: Object | Function,
|
|
|
|
propertyName: string,
|
2018-04-13 10:57:12 +00:00
|
|
|
sources?: Object
|
2018-04-11 17:02:31 +00:00
|
|
|
) {
|
2018-04-13 10:57:12 +00:00
|
|
|
// Default values don't play nicely with partial objects and we want to make
|
|
|
|
// the function easy to use without exhaustively defining all flags:
|
|
|
|
sources = { // eslint-disable-line no-param-reassign
|
|
|
|
// Defaults:
|
|
|
|
config: true,
|
|
|
|
jwt: true,
|
2018-04-12 19:58:20 +00:00
|
|
|
settings: true,
|
2018-04-13 10:57:12 +00:00
|
|
|
urlParams: true,
|
|
|
|
|
|
|
|
...sources
|
|
|
|
};
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
// Precedence: jwt -> urlParams -> settings -> config.
|
2018-04-13 10:57:12 +00:00
|
|
|
|
2018-04-11 17:02:31 +00:00
|
|
|
const state = toState(stateful);
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// jwt
|
|
|
|
if (sources.jwt) {
|
|
|
|
const value = state['features/base/jwt'][propertyName];
|
2018-04-11 17:02:31 +00:00
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value[propertyName];
|
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// urlParams
|
|
|
|
if (sources.urlParams) {
|
2019-11-01 13:24:52 +00:00
|
|
|
if (CONFIG_WHITELIST.indexOf(propertyName) !== -1) {
|
|
|
|
const urlParams
|
|
|
|
= parseURLParams(state['features/base/connection'].locationURL);
|
|
|
|
const value = urlParams[`config.${propertyName}`];
|
2018-04-13 10:57:12 +00:00
|
|
|
|
2019-11-01 13:24:52 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-13 10:57:12 +00:00
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
// settings
|
|
|
|
if (sources.settings) {
|
|
|
|
const value = state['features/base/settings'][propertyName];
|
2018-04-13 10:57:12 +00:00
|
|
|
|
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 10:57:12 +00:00
|
|
|
// config
|
|
|
|
if (sources.config) {
|
|
|
|
const value = state['features/base/config'][propertyName];
|
|
|
|
|
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-11 17:02:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
2018-07-11 08:57:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the currently configured server URL.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string} - The currently configured server URL.
|
|
|
|
*/
|
|
|
|
export function getServerURL(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
|
|
|
|
return state['features/base/settings'].serverURL || DEFAULT_SERVER_URL;
|
|
|
|
}
|
2019-05-07 08:53:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches known devices for a matching deviceId and fall back to matching on
|
|
|
|
* label. Returns the stored preferred cameraDeviceId if a match is not found.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getUserSelectedCameraDeviceId(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const {
|
|
|
|
userSelectedCameraDeviceId,
|
|
|
|
userSelectedCameraDeviceLabel
|
|
|
|
} = state['features/base/settings'];
|
|
|
|
const { videoInput } = state['features/base/devices'].availableDevices;
|
|
|
|
|
|
|
|
return _getUserSelectedDeviceId({
|
|
|
|
availableDevices: videoInput,
|
|
|
|
|
|
|
|
// Operating systems may append " #{number}" somewhere in the label so
|
|
|
|
// find and strip that bit.
|
|
|
|
matchRegex: /\s#\d*(?!.*\s#\d*)/,
|
|
|
|
userSelectedDeviceId: userSelectedCameraDeviceId,
|
|
|
|
userSelectedDeviceLabel: userSelectedCameraDeviceLabel,
|
|
|
|
replacement: ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches known devices for a matching deviceId and fall back to matching on
|
|
|
|
* label. Returns the stored preferred micDeviceId if a match is not found.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getUserSelectedMicDeviceId(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const {
|
|
|
|
userSelectedMicDeviceId,
|
|
|
|
userSelectedMicDeviceLabel
|
|
|
|
} = state['features/base/settings'];
|
|
|
|
const { audioInput } = state['features/base/devices'].availableDevices;
|
|
|
|
|
|
|
|
return _getUserSelectedDeviceId({
|
|
|
|
availableDevices: audioInput,
|
|
|
|
|
|
|
|
// Operating systems may append " ({number}-" somewhere in the label so
|
|
|
|
// find and strip that bit.
|
|
|
|
matchRegex: /\s\(\d*-\s(?!.*\s\(\d*-\s)/,
|
|
|
|
userSelectedDeviceId: userSelectedMicDeviceId,
|
|
|
|
userSelectedDeviceLabel: userSelectedMicDeviceLabel,
|
|
|
|
replacement: ' ('
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches known devices for a matching deviceId and fall back to matching on
|
|
|
|
* label. Returns the stored preferred audioOutputDeviceId if a match is not found.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
export function getUserSelectedOutputDeviceId(stateful: Object | Function) {
|
|
|
|
const state = toState(stateful);
|
|
|
|
const {
|
|
|
|
userSelectedAudioOutputDeviceId,
|
|
|
|
userSelectedAudioOutputDeviceLabel
|
|
|
|
} = state['features/base/settings'];
|
|
|
|
const { audioOutput } = state['features/base/devices'].availableDevices;
|
|
|
|
|
|
|
|
return _getUserSelectedDeviceId({
|
|
|
|
availableDevices: audioOutput,
|
|
|
|
matchRegex: undefined,
|
|
|
|
userSelectedDeviceId: userSelectedAudioOutputDeviceId,
|
|
|
|
userSelectedDeviceLabel: userSelectedAudioOutputDeviceLabel,
|
|
|
|
replacement: undefined
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function to abstract the logic for choosing which device ID to
|
|
|
|
* use. Falls back to fuzzy matching on label if a device ID match is not found.
|
|
|
|
*
|
|
|
|
* @param {Object} options - The arguments used to match find the preferred
|
|
|
|
* device ID from available devices.
|
|
|
|
* @param {Array<string>} options.availableDevices - The array of currently
|
|
|
|
* available devices to match against.
|
|
|
|
* @param {Object} options.matchRegex - The regex to use to find strings
|
|
|
|
* appended to the label by the operating system. The matches will be replaced
|
|
|
|
* with options.replacement, with the intent of matching the same device that
|
|
|
|
* might have a modified label.
|
|
|
|
* @param {string} options.userSelectedDeviceId - The device ID the participant
|
|
|
|
* prefers to use.
|
|
|
|
* @param {string} options.userSelectedDeviceLabel - The label associated with the
|
|
|
|
* device ID the participant prefers to use.
|
|
|
|
* @param {string} options.replacement - The string to use with
|
|
|
|
* options.matchRegex to remove identifies added to the label by the operating
|
|
|
|
* system.
|
|
|
|
* @private
|
|
|
|
* @returns {string} The preferred device ID to use for media.
|
|
|
|
*/
|
|
|
|
function _getUserSelectedDeviceId(options) {
|
|
|
|
const {
|
|
|
|
availableDevices,
|
|
|
|
matchRegex,
|
|
|
|
userSelectedDeviceId,
|
|
|
|
userSelectedDeviceLabel,
|
|
|
|
replacement
|
|
|
|
} = options;
|
|
|
|
|
|
|
|
// If there is no label at all, there is no need to fall back to checking
|
|
|
|
// the label for a fuzzy match.
|
|
|
|
if (!userSelectedDeviceLabel || !userSelectedDeviceId) {
|
|
|
|
return userSelectedDeviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const foundMatchingBasedonDeviceId = availableDevices.find(
|
|
|
|
candidate => candidate.deviceId === userSelectedDeviceId);
|
|
|
|
|
|
|
|
// Prioritize matching the deviceId
|
|
|
|
if (foundMatchingBasedonDeviceId) {
|
|
|
|
return userSelectedDeviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const strippedDeviceLabel
|
|
|
|
= matchRegex ? userSelectedDeviceLabel.replace(matchRegex, replacement)
|
|
|
|
: userSelectedDeviceLabel;
|
|
|
|
const foundMatchBasedOnLabel = availableDevices.find(candidate => {
|
|
|
|
const { label } = candidate;
|
|
|
|
|
|
|
|
if (!label) {
|
|
|
|
return false;
|
|
|
|
} else if (strippedDeviceLabel === label) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const strippedCandidateLabel
|
|
|
|
= label.replace(matchRegex, replacement);
|
|
|
|
|
|
|
|
return strippedDeviceLabel === strippedCandidateLabel;
|
|
|
|
});
|
|
|
|
|
|
|
|
return foundMatchBasedOnLabel
|
|
|
|
? foundMatchBasedOnLabel.deviceId : userSelectedDeviceId;
|
|
|
|
}
|
|
|
|
|
2021-07-07 08:07:30 +00:00
|
|
|
/**
|
|
|
|
* Should we hide the helper dialog when a user tries to do audio only screen sharing.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The state of the application.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function shouldHideShareAudioHelper(state: Object): boolean {
|
|
|
|
|
|
|
|
return state['features/base/settings'].hideShareAudioHelper;
|
|
|
|
}
|
2021-12-16 16:55:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether we should hide self view.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function shouldHideSelfView(state: Object) {
|
|
|
|
return getParticipantCount(state) === 1 ? false : getHideSelfView(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the disable self view setting.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function getHideSelfView(state: Object) {
|
|
|
|
return state['features/base/config'].disableSelfView || state['features/base/settings'].disableSelfView;
|
|
|
|
}
|