2017-02-03 18:50:06 +00:00
|
|
|
/* @flow */
|
|
|
|
|
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2021-06-23 11:23:44 +00:00
|
|
|
import { showModeratedNotification } from '../../av-moderation/actions';
|
|
|
|
import { shouldShowModeratedNotification } from '../../av-moderation/functions';
|
2021-09-15 08:28:44 +00:00
|
|
|
import { isModerationNotificationDisplayed } from '../../notifications';
|
2021-06-23 11:23:44 +00:00
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
2017-01-11 18:14:00 +00:00
|
|
|
SET_AUDIO_MUTED,
|
2017-07-24 13:56:57 +00:00
|
|
|
SET_AUDIO_AVAILABLE,
|
2021-11-30 20:08:25 +00:00
|
|
|
SET_AUDIO_UNMUTE_PERMISSIONS,
|
2017-01-11 18:14:00 +00:00
|
|
|
SET_CAMERA_FACING_MODE,
|
2017-06-28 14:15:46 +00:00
|
|
|
SET_VIDEO_AVAILABLE,
|
2017-04-03 08:57:01 +00:00
|
|
|
SET_VIDEO_MUTED,
|
2021-11-30 20:08:25 +00:00
|
|
|
SET_VIDEO_UNMUTE_PERMISSIONS,
|
2018-04-07 07:52:38 +00:00
|
|
|
STORE_VIDEO_TRANSFORM,
|
2017-04-03 08:57:01 +00:00
|
|
|
TOGGLE_CAMERA_FACING_MODE
|
2016-10-05 14:36:59 +00:00
|
|
|
} from './actionTypes';
|
2019-11-26 10:57:03 +00:00
|
|
|
import {
|
|
|
|
MEDIA_TYPE,
|
2021-06-23 11:23:44 +00:00
|
|
|
type MediaType,
|
2019-11-26 10:57:03 +00:00
|
|
|
VIDEO_MUTISM_AUTHORITY
|
|
|
|
} from './constants';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2017-07-24 13:56:57 +00:00
|
|
|
/**
|
|
|
|
* Action to adjust the availability of the local audio.
|
|
|
|
*
|
|
|
|
* @param {boolean} available - True if the local audio is to be marked as
|
|
|
|
* available or false if the local audio is not available.
|
|
|
|
* @returns {{
|
2018-04-07 07:52:38 +00:00
|
|
|
* type: SET_AUDIO_AVAILABLE,
|
|
|
|
* available: boolean
|
|
|
|
* }}
|
2017-07-24 13:56:57 +00:00
|
|
|
*/
|
|
|
|
export function setAudioAvailable(available: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_AUDIO_AVAILABLE,
|
|
|
|
available
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-01-17 14:32:20 +00:00
|
|
|
* Action to set the muted state of the local audio.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-01-17 14:32:20 +00:00
|
|
|
* @param {boolean} muted - True if the local audio is to be muted or false if
|
|
|
|
* the local audio is to be unmuted.
|
2017-08-14 13:27:24 +00:00
|
|
|
* @param {boolean} ensureTrack - True if we want to ensure that a new track is
|
|
|
|
* created if missing.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {{
|
2017-07-16 08:44:07 +00:00
|
|
|
* type: SET_AUDIO_MUTED,
|
2017-08-14 13:27:24 +00:00
|
|
|
* ensureTrack: boolean,
|
2017-07-16 08:44:07 +00:00
|
|
|
* muted: boolean
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2017-08-14 13:27:24 +00:00
|
|
|
export function setAudioMuted(muted: boolean, ensureTrack: boolean = false) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2017-01-11 18:14:00 +00:00
|
|
|
type: SET_AUDIO_MUTED,
|
2017-08-14 13:27:24 +00:00
|
|
|
ensureTrack,
|
2016-10-05 14:36:59 +00:00
|
|
|
muted
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
/**
|
|
|
|
* Action to disable/enable the audio mute icon.
|
|
|
|
*
|
|
|
|
* @param {boolean} blocked - True if the audio mute icon needs to be disabled.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function setAudioUnmutePermissions(blocked: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_AUDIO_UNMUTE_PERMISSIONS,
|
|
|
|
blocked
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-01-17 14:32:20 +00:00
|
|
|
* Action to set the facing mode of the local camera.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-01-17 14:32:20 +00:00
|
|
|
* @param {CAMERA_FACING_MODE} cameraFacingMode - The camera facing mode to set.
|
2016-10-05 14:36:59 +00:00
|
|
|
* @returns {{
|
2017-07-16 08:44:07 +00:00
|
|
|
* type: SET_CAMERA_FACING_MODE,
|
|
|
|
* cameraFacingMode: CAMERA_FACING_MODE
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
export function setCameraFacingMode(cameraFacingMode: string) {
|
2016-10-05 14:36:59 +00:00
|
|
|
return {
|
2017-01-11 18:14:00 +00:00
|
|
|
type: SET_CAMERA_FACING_MODE,
|
2016-10-05 14:36:59 +00:00
|
|
|
cameraFacingMode
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-28 14:15:46 +00:00
|
|
|
/**
|
|
|
|
* Action to adjust the availability of the local video.
|
|
|
|
*
|
|
|
|
* @param {boolean} available - True if the local video is to be marked as
|
|
|
|
* available or false if the local video is not available.
|
|
|
|
* @returns {{
|
2017-07-16 08:44:07 +00:00
|
|
|
* type: SET_VIDEO_AVAILABLE,
|
|
|
|
* available: boolean
|
|
|
|
* }}
|
2017-06-28 14:15:46 +00:00
|
|
|
*/
|
|
|
|
export function setVideoAvailable(available: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_VIDEO_AVAILABLE,
|
|
|
|
available
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-17 14:32:20 +00:00
|
|
|
/**
|
|
|
|
* Action to set the muted state of the local video.
|
|
|
|
*
|
|
|
|
* @param {boolean} muted - True if the local video is to be muted or false if
|
|
|
|
* the local video is to be unmuted.
|
2019-11-26 10:57:03 +00:00
|
|
|
* @param {MEDIA_TYPE} mediaType - The type of media.
|
2017-08-02 15:00:51 +00:00
|
|
|
* @param {number} authority - The {@link VIDEO_MUTISM_AUTHORITY} which is
|
|
|
|
* muting/unmuting the local video.
|
2017-08-14 13:27:24 +00:00
|
|
|
* @param {boolean} ensureTrack - True if we want to ensure that a new track is
|
|
|
|
* created if missing.
|
2017-08-02 15:00:51 +00:00
|
|
|
* @returns {Function}
|
2017-01-17 14:32:20 +00:00
|
|
|
*/
|
2017-08-02 15:00:51 +00:00
|
|
|
export function setVideoMuted(
|
|
|
|
muted: boolean,
|
2021-06-23 11:23:44 +00:00
|
|
|
mediaType: MediaType = MEDIA_TYPE.VIDEO,
|
2017-08-14 13:27:24 +00:00
|
|
|
authority: number = VIDEO_MUTISM_AUTHORITY.USER,
|
|
|
|
ensureTrack: boolean = false) {
|
2019-03-19 15:42:25 +00:00
|
|
|
return (dispatch: Dispatch<any>, getState: Function) => {
|
2021-06-23 11:23:44 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
// check for A/V Moderation when trying to unmute
|
|
|
|
if (!muted && shouldShowModeratedNotification(MEDIA_TYPE.VIDEO, state)) {
|
2021-09-15 08:28:44 +00:00
|
|
|
if (!isModerationNotificationDisplayed(MEDIA_TYPE.VIDEO, state)) {
|
|
|
|
ensureTrack && dispatch(showModeratedNotification(MEDIA_TYPE.VIDEO));
|
|
|
|
}
|
2021-06-23 11:23:44 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const oldValue = state['features/base/media'].video.muted;
|
2017-08-02 15:00:51 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
const newValue = muted ? oldValue | authority : oldValue & ~authority;
|
|
|
|
|
|
|
|
return dispatch({
|
|
|
|
type: SET_VIDEO_MUTED,
|
2019-11-26 10:57:03 +00:00
|
|
|
authority,
|
|
|
|
mediaType,
|
2017-08-14 13:27:24 +00:00
|
|
|
ensureTrack,
|
2017-08-02 15:00:51 +00:00
|
|
|
muted: newValue
|
|
|
|
});
|
2017-01-17 14:32:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-30 20:08:25 +00:00
|
|
|
/**
|
|
|
|
* Action to disable/enable the video mute icon.
|
|
|
|
*
|
|
|
|
* @param {boolean} blocked - True if the video mute icon needs to be disabled.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function setVideoUnmutePermissions(blocked: boolean) {
|
|
|
|
return {
|
|
|
|
type: SET_VIDEO_UNMUTE_PERMISSIONS,
|
|
|
|
blocked
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:52:38 +00:00
|
|
|
/**
|
|
|
|
* Creates an action to store the last video {@link Transform} applied to a
|
|
|
|
* stream.
|
|
|
|
*
|
|
|
|
* @param {string} streamId - The ID of the stream.
|
|
|
|
* @param {Object} transform - The {@code Transform} to store.
|
|
|
|
* @returns {{
|
|
|
|
* type: STORE_VIDEO_TRANSFORM,
|
|
|
|
* streamId: string,
|
|
|
|
* transform: Object
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function storeVideoTransform(streamId: string, transform: Object) {
|
|
|
|
return {
|
|
|
|
type: STORE_VIDEO_TRANSFORM,
|
|
|
|
streamId,
|
|
|
|
transform
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
2017-04-03 08:57:01 +00:00
|
|
|
* Toggles the camera facing mode. Most commonly, for example, mobile devices
|
|
|
|
* such as phones have a front/user-facing and a back/environment-facing
|
|
|
|
* cameras. In contrast to setCameraFacingMode, allows the toggling to be
|
|
|
|
* optimally and/or natively implemented without the overhead of separate reads
|
|
|
|
* and writes of the current/effective camera facing mode.
|
2016-10-05 14:36:59 +00:00
|
|
|
*
|
2017-04-03 08:57:01 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: TOGGLE_CAMERA_FACING_MODE
|
|
|
|
* }}
|
2016-10-05 14:36:59 +00:00
|
|
|
*/
|
|
|
|
export function toggleCameraFacingMode() {
|
2017-04-03 08:57:01 +00:00
|
|
|
return {
|
|
|
|
type: TOGGLE_CAMERA_FACING_MODE
|
2016-10-05 14:36:59 +00:00
|
|
|
};
|
|
|
|
}
|