jiti-meet/react/features/base/media/functions.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-09-27 03:18:08 +00:00
/* @flow */
2017-09-28 21:25:04 +00:00
import { toState } from '../redux';
import { VIDEO_MUTISM_AUTHORITY } from './constants';
/**
2017-09-27 03:18:08 +00:00
* Determines whether video is currently muted by the audio-only authority.
*
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}
*/
2017-09-28 21:25:04 +00:00
export function isVideoMutedByAudioOnly(stateful: Function | Object) {
return (
_isVideoMutedByAuthority(stateful, VIDEO_MUTISM_AUTHORITY.AUDIO_ONLY));
}
/**
2017-09-27 03:18:08 +00:00
* Determines whether video is currently muted by a specific
* {@code VIDEO_MUTISM_AUTHORITY}.
*
2017-09-28 21:25:04 +00:00
* @param {Function|Object} stateful - The redux store, state, or
* {@code getState} function.
* @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
* {@code videoMutismAuthority}, then {@code true}; otherwise, {@code false}.
*/
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-27 03:18:08 +00:00
* Determines whether video is currently muted by the user authority.
*
2017-09-28 21:25:04 +00:00
* @param {Function|Object} stateful - The redux store, state, or
* {@code getState} function.
* @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(
videoTrack: ?{ muted: boolean, videoStarted: boolean },
2017-09-27 03:18:08 +00:00
waitForVideoStarted: boolean) {
return (
videoTrack
&& !videoTrack.muted
&& (!waitForVideoStarted || videoTrack.videoStarted));
}