jiti-meet/react/features/remote-video-menu/components/web/RemoteVideoMenuTriggerButto...

300 lines
8.7 KiB
JavaScript
Raw Normal View History

// @flow
import React, { Component } from 'react';
2019-08-30 16:39:06 +00:00
import { Icon, IconMenuThumb } from '../../../base/icons';
import { MEDIA_TYPE } from '../../../base/media';
2020-11-14 04:09:25 +00:00
import { getLocalParticipant, getParticipantById, PARTICIPANT_ROLE } from '../../../base/participants';
2018-12-19 18:40:17 +00:00
import { Popover } from '../../../base/popover';
import { connect } from '../../../base/redux';
import { isRemoteTrackMuted } from '../../../base/tracks';
2020-11-14 04:09:25 +00:00
import { requestRemoteControl, stopController } from '../../../remote-control';
import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
import MuteEveryoneElseButton from './MuteEveryoneElseButton';
2020-11-14 04:09:25 +00:00
import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
import {
GrantModeratorButton,
MuteButton,
KickButton,
2019-10-07 12:35:04 +00:00
PrivateMessageMenuButton,
RemoteControlButton,
RemoteVideoMenu,
VolumeSlider
} from './';
declare var $: Object;
declare var interfaceConfig: Object;
/**
* The type of the React {@code Component} props of
* {@link RemoteVideoMenuTriggerButton}.
*/
type Props = {
/**
* Whether or not to display the kick button.
*/
_disableKick: boolean,
/**
* Whether or not to display the remote mute buttons.
*/
_disableRemoteMute: Boolean,
/**
* Whether or not the participant is currently muted.
*/
_isAudioMuted: boolean,
/**
* Whether or not the participant is a conference moderator.
*/
_isModerator: boolean,
/**
2020-11-14 04:09:25 +00:00
* The position relative to the trigger the remote menu should display
* from. Valid values are those supported by AtlasKit
* {@code InlineDialog}.
*/
2020-11-14 04:09:25 +00:00
_menuPosition: string,
/**
* Whether to display the Popover as a drawer.
*/
_overflowDrawer: boolean,
/**
2020-11-14 04:09:25 +00:00
* The current state of the participant's remote control session.
*/
2020-11-14 04:09:25 +00:00
_remoteControlState: number,
/**
2020-11-14 04:09:25 +00:00
* The redux dispatch function.
*/
2020-11-14 04:09:25 +00:00
dispatch: Function,
/**
2020-11-14 04:09:25 +00:00
* A value between 0 and 1 indicating the volume of the participant's
* audio element.
*/
initialVolumeValue: ?number,
/**
2020-11-14 04:09:25 +00:00
* Callback to invoke when changing the level of the participant's
* audio element.
*/
2020-11-14 04:09:25 +00:00
onVolumeChange: Function,
/**
2020-11-14 04:09:25 +00:00
* The ID for the participant on which the remote video menu will act.
*/
2020-11-14 04:09:25 +00:00
participantID: string,
};
/**
* React {@code Component} for displaying an icon associated with opening the
* the {@code RemoteVideoMenu}.
*
* @extends {Component}
*/
class RemoteVideoMenuTriggerButton extends Component<Props> {
/**
* The internal reference to topmost DOM/HTML element backing the React
* {@code Component}. Accessed directly for associating an element as
* the trigger for a popover.
*
* @private
* @type {HTMLDivElement}
*/
_rootElement = null;
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
* @returns {ReactElement}
*/
render() {
const content = this._renderRemoteVideoMenu();
if (!content) {
return null;
}
return (
<Popover
content = { content }
overflowDrawer = { this.props._overflowDrawer }
2020-11-14 04:09:25 +00:00
position = { this.props._menuPosition }>
<span
className = 'popover-trigger remote-video-menu-trigger'>
2019-08-30 16:39:06 +00:00
<Icon
size = '1em'
src = { IconMenuThumb }
title = 'Remote user controls' />
</span>
</Popover>
);
}
/**
* Creates a new {@code RemoteVideoMenu} with buttons for interacting with
* the remote participant.
*
* @private
* @returns {ReactElement}
*/
_renderRemoteVideoMenu() {
const {
_disableKick,
_disableRemoteMute,
_isAudioMuted,
_isModerator,
2020-11-14 04:09:25 +00:00
dispatch,
initialVolumeValue,
onVolumeChange,
2020-11-14 04:09:25 +00:00
_remoteControlState,
participantID
} = this.props;
const buttons = [];
if (_isModerator) {
if (!_disableRemoteMute) {
buttons.push(
<MuteButton
isAudioMuted = { _isAudioMuted }
key = 'mute'
participantID = { participantID } />
);
buttons.push(
<MuteEveryoneElseButton
key = 'mute-others'
participantID = { participantID } />
);
}
buttons.push(
<GrantModeratorButton
key = 'grant-moderator'
participantID = { participantID } />
);
if (!_disableKick) {
buttons.push(
<KickButton
key = 'kick'
participantID = { participantID } />
);
}
}
2020-11-14 04:09:25 +00:00
if (_remoteControlState) {
let onRemoteControlToggle = null;
if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
onRemoteControlToggle = () => dispatch(stopController(true));
} else if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
onRemoteControlToggle = () => dispatch(requestRemoteControl(participantID));
}
buttons.push(
<RemoteControlButton
key = 'remote-control'
onClick = { onRemoteControlToggle }
participantID = { participantID }
2020-11-14 04:09:25 +00:00
remoteControlState = { _remoteControlState } />
);
}
2019-10-07 12:35:04 +00:00
buttons.push(
<PrivateMessageMenuButton
key = 'privateMessage'
participantID = { participantID } />
);
if (onVolumeChange && initialVolumeValue && !isNaN(initialVolumeValue)) {
buttons.push(
<VolumeSlider
initialValue = { initialVolumeValue }
key = 'volume-slider'
onChange = { onVolumeChange } />
);
}
if (buttons.length > 0) {
return (
<RemoteVideoMenu id = { participantID }>
{ buttons }
</RemoteVideoMenu>
);
}
return null;
}
}
/**
* Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
*
* @param {Object} state - The Redux state.
* @param {Object} ownProps - The own props of the component.
* @private
* @returns {Props}
*/
function _mapStateToProps(state, ownProps) {
const { participantID } = ownProps;
const tracks = state['features/base/tracks'];
const localParticipant = getLocalParticipant(state);
const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
const { disableKick } = remoteVideoMenu;
2020-11-14 04:09:25 +00:00
let _remoteControlState = null;
const participant = getParticipantById(state, participantID);
const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
const { active, controller } = state['features/remote-control'];
const { requestedParticipant, controlled } = controller;
const activeParticipant = requestedParticipant || controlled;
const { overflowDrawer } = state['features/toolbox'];
2020-11-14 04:09:25 +00:00
if (_supportsRemoteControl
&& ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
if (requestedParticipant === participantID) {
_remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
} else if (controlled) {
_remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
} else {
_remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
}
}
const currentLayout = getCurrentLayout(state);
let _menuPosition;
switch (currentLayout) {
case LAYOUTS.TILE_VIEW:
2021-01-14 16:12:08 +00:00
_menuPosition = 'left-start';
2020-11-14 04:09:25 +00:00
break;
case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
2021-01-14 16:12:08 +00:00
_menuPosition = 'left-end';
2020-11-14 04:09:25 +00:00
break;
default:
2021-01-14 16:12:08 +00:00
_menuPosition = 'auto';
2020-11-14 04:09:25 +00:00
}
return {
_isAudioMuted: isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID) || false,
_isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
_disableKick: Boolean(disableKick),
2020-11-14 04:09:25 +00:00
_disableRemoteMute: Boolean(disableRemoteMute),
_remoteControlState,
_menuPosition,
_overflowDrawer: overflowDrawer
};
}
export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);