jiti-meet/react/features/video-menu/actions.any.js

96 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-12-19 18:40:17 +00:00
// @flow
2021-02-26 21:26:09 +00:00
import { getLogger } from 'jitsi-meet-logger';
import type { Dispatch } from 'redux';
2018-12-19 18:40:17 +00:00
2020-05-20 10:57:03 +00:00
import UIEvents from '../../../service/UI/UIEvents';
import {
AUDIO_MUTE,
createRemoteMuteConfirmedEvent,
createToolbarEvent,
sendAnalytics,
VIDEO_MUTE
} from '../analytics';
import {
MEDIA_TYPE,
setAudioMuted,
setVideoMuted,
VIDEO_MUTISM_AUTHORITY
} from '../base/media';
import {
getLocalParticipant,
muteRemoteParticipant
} from '../base/participants';
2018-12-19 18:40:17 +00:00
declare var APP: Object;
2021-02-26 21:26:09 +00:00
const logger = getLogger(__filename);
/**
* Mutes the local participant.
*
* @param {boolean} enable - Whether to mute or unmute.
* @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
* @returns {Function}
*/
export function muteLocal(enable: boolean, mediaType: MEDIA_TYPE) {
return (dispatch: Dispatch<any>) => {
const isAudio = mediaType === MEDIA_TYPE.AUDIO;
if (!isAudio && mediaType !== MEDIA_TYPE.VIDEO) {
2021-02-26 21:26:09 +00:00
logger.error(`Unsupported media type: ${mediaType}`);
return;
}
sendAnalytics(createToolbarEvent(isAudio ? AUDIO_MUTE : VIDEO_MUTE, { enable }));
dispatch(isAudio ? setAudioMuted(enable, /* ensureTrack */ true)
: setVideoMuted(enable, mediaType, VIDEO_MUTISM_AUTHORITY.USER, /* ensureTrack */ true));
// FIXME: The old conference logic as well as the shared video feature
// still rely on this event being emitted.
typeof APP === 'undefined'
|| APP.UI.emitEvent(isAudio ? UIEvents.AUDIO_MUTED : UIEvents.VIDEO_MUTED, enable, true);
};
}
/**
* Mutes the remote participant with the given ID.
*
* @param {string} participantId - ID of the participant to mute.
* @param {MEDIA_TYPE} mediaType - The type of the media channel to mute.
* @returns {Function}
*/
export function muteRemote(participantId: string, mediaType: MEDIA_TYPE) {
return (dispatch: Dispatch<any>) => {
if (mediaType !== MEDIA_TYPE.AUDIO && mediaType !== MEDIA_TYPE.VIDEO) {
2021-02-26 21:26:09 +00:00
logger.error(`Unsupported media type: ${mediaType}`);
return;
}
sendAnalytics(createRemoteMuteConfirmedEvent(participantId, mediaType));
dispatch(muteRemoteParticipant(participantId, mediaType));
};
}
/**
* Mutes all participants.
*
* @param {Array<string>} exclude - Array of participant IDs to not mute.
* @param {MEDIA_TYPE} mediaType - The media type to mute.
* @returns {Function}
*/
export function muteAllParticipants(exclude: Array<string>, mediaType: MEDIA_TYPE) {
return (dispatch: Dispatch<any>, getState: Function) => {
const state = getState();
const localId = getLocalParticipant(state).id;
const participantIds = state['features/base/participants']
.map(p => p.id);
/* eslint-disable no-confusing-arrow */
participantIds
.filter(id => !exclude.includes(id))
.map(id => id === localId ? muteLocal(true, mediaType) : muteRemote(id, mediaType))
.map(dispatch);
/* eslint-enable no-confusing-arrow */
};
}