2017-09-27 03:18:08 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-28 21:25:04 +00:00
|
|
|
import { toState } from '../redux';
|
2020-10-21 16:57:50 +00:00
|
|
|
import { getPropertyValue } from '../settings';
|
2017-09-28 21:25:04 +00:00
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
import { VIDEO_MUTISM_AUTHORITY } from './constants';
|
|
|
|
|
2020-10-21 16:57:50 +00:00
|
|
|
|
|
|
|
// XXX The configurations/preferences/settings startWithAudioMuted and startWithVideoMuted were introduced for
|
|
|
|
// conferences/meetings. So it makes sense for these to not be considered outside of conferences/meetings
|
|
|
|
// (e.g. WelcomePage). Later on, though, we introduced a "Video <-> Voice" toggle on the WelcomePage which utilizes
|
|
|
|
// startAudioOnly outside of conferences/meetings so that particular configuration/preference/setting employs slightly
|
|
|
|
// exclusive logic.
|
|
|
|
const START_WITH_AUDIO_VIDEO_MUTED_SOURCES = {
|
|
|
|
// We have startWithAudioMuted and startWithVideoMuted here:
|
|
|
|
config: true,
|
|
|
|
settings: true,
|
|
|
|
|
|
|
|
// XXX We've already overwritten base/config with urlParams. However,
|
|
|
|
// settings are more important than the server-side config.
|
|
|
|
// Consequently, we need to read from urlParams anyway:
|
|
|
|
urlParams: true,
|
|
|
|
|
|
|
|
// We don't have startWithAudioMuted and startWithVideoMuted here:
|
|
|
|
jwt: false
|
|
|
|
};
|
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Determines whether audio is currently muted.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateful - The redux store, state, or
|
|
|
|
* {@code getState} function.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isAudioMuted(stateful: Function | Object) {
|
|
|
|
return Boolean(toState(stateful)['features/base/media'].audio.muted);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-09-27 03:18:08 +00:00
|
|
|
* Determines whether video is currently muted by the audio-only authority.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-09-28 21:25:04 +00:00
|
|
|
* @param {Function|Object} stateful - The redux store, state, or
|
|
|
|
* {@code getState} function.
|
2017-09-27 03:18:08 +00:00
|
|
|
* @returns {boolean}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-09-28 21:25:04 +00:00
|
|
|
export function isVideoMutedByAudioOnly(stateful: Function | Object) {
|
|
|
|
return (
|
|
|
|
_isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY));
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2017-08-18 11:30:30 +00:00
|
|
|
|
2017-09-08 09:26:54 +00:00
|
|
|
/**
|
2017-09-27 03:18:08 +00:00
|
|
|
* Determines whether video is currently muted by a specific
|
2017-10-01 06:35:19 +00:00
|
|
|
* {@code VIDEO_MUTISM_AUTHORITY}.
|
2017-09-08 09:26:54 +00:00
|
|
|
*
|
2017-09-28 21:25:04 +00:00
|
|
|
* @param {Function|Object} stateful - The redux store, state, or
|
|
|
|
* {@code getState} function.
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {number} videoMutismAuthority - The {@code VIDEO_MUTISM_AUTHORITY}
|
2017-09-27 03:18:08 +00:00
|
|
|
* which is to be checked whether it has muted video.
|
|
|
|
* @returns {boolean} If video is currently muted by the specified
|
2017-10-01 06:35:19 +00:00
|
|
|
* {@code videoMutismAuthority}, then {@code true}; otherwise, {@code false}.
|
2017-09-08 09:26:54 +00:00
|
|
|
*/
|
2017-09-27 03:18:08 +00:00
|
|
|
function _isVideoMutedByAuthority(
|
2017-09-28 21:25:04 +00:00
|
|
|
stateful: Function | Object,
|
2017-09-27 03:18:08 +00:00
|
|
|
videoMutismAuthority: number) {
|
2017-09-28 21:25:04 +00:00
|
|
|
const { muted } = toState(stateful)['features/base/media'].video;
|
2017-09-27 03:18:08 +00:00
|
|
|
|
2017-09-28 21:25:04 +00:00
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
return Boolean(muted & videoMutismAuthority);
|
2017-09-08 09:26:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 16:57:50 +00:00
|
|
|
/**
|
|
|
|
* Computes the startWithAudioMuted by retrieving its values from config, URL and settings.
|
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or {@code getState} function.
|
|
|
|
* @returns {boolean} - The computed startWithAudioMuted value that will be used.
|
|
|
|
*/
|
|
|
|
export function getStartWithAudioMuted(stateful: Object | Function) {
|
|
|
|
return Boolean(getPropertyValue(stateful, 'startWithAudioMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 11:38:49 +00:00
|
|
|
* Computes the startWithVideoMuted by retrieving its values from config, URL and settings.
|
2020-10-21 16:57:50 +00:00
|
|
|
*
|
|
|
|
* @param {Object|Function} stateful - The redux state object or {@code getState} function.
|
2021-01-26 11:38:49 +00:00
|
|
|
* @returns {boolean} - The computed startWithVideoMuted value that will be used.
|
2020-10-21 16:57:50 +00:00
|
|
|
*/
|
|
|
|
export function getStartWithVideoMuted(stateful: Object | Function) {
|
|
|
|
return Boolean(getPropertyValue(stateful, 'startWithVideoMuted', START_WITH_AUDIO_VIDEO_MUTED_SOURCES));
|
|
|
|
}
|
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
/**
|
|
|
|
* Determines whether video is currently muted.
|
|
|
|
*
|
|
|
|
* @param {Function|Object} stateful - The redux store, state, or {@code getState} function.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isVideoMuted(stateful: Function | Object) {
|
|
|
|
return Boolean(toState(stateful)['features/base/media'].video.muted);
|
|
|
|
}
|
|
|
|
|
2017-08-18 11:30:30 +00:00
|
|
|
/**
|
2017-09-27 03:18:08 +00:00
|
|
|
* Determines whether video is currently muted by the user authority.
|
2017-08-18 11:30:30 +00:00
|
|
|
*
|
2017-09-28 21:25:04 +00:00
|
|
|
* @param {Function|Object} stateful - The redux store, state, or
|
|
|
|
* {@code getState} function.
|
2017-08-18 11:30:30 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-09-28 21:25:04 +00:00
|
|
|
export function isVideoMutedByUser(stateful: Function | Object) {
|
|
|
|
return _isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.USER);
|
2017-09-27 03:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether a specific videoTrack should be rendered.
|
|
|
|
*
|
|
|
|
* @param {Track} videoTrack - The video track which is to be rendered.
|
|
|
|
* @param {boolean} waitForVideoStarted - True if the specified videoTrack
|
|
|
|
* should be rendered only after its associated video has started;
|
|
|
|
* otherwise, false.
|
|
|
|
* @returns {boolean} True if the specified videoTrack should be renderd;
|
|
|
|
* otherwise, false.
|
|
|
|
*/
|
|
|
|
export function shouldRenderVideoTrack(
|
2018-10-30 05:02:23 +00:00
|
|
|
videoTrack: ?{ muted: boolean, videoStarted: boolean },
|
2017-09-27 03:18:08 +00:00
|
|
|
waitForVideoStarted: boolean) {
|
|
|
|
return (
|
|
|
|
videoTrack
|
|
|
|
&& !videoTrack.muted
|
|
|
|
&& (!waitForVideoStarted || videoTrack.videoStarted));
|
2017-08-18 11:30:30 +00:00
|
|
|
}
|