| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 | // @flow
import PropTypes from 'prop-types';
import React from 'react';
import { connect } from 'react-redux';
import UIEvents from '../../../../../service/UI/UIEvents';
import {
    ACTION_SHORTCUT_TRIGGERED,
    VIDEO_MUTE,
    createShortcutEvent,
    sendAnalytics
} from '../../../analytics';
import { translate } from '../../../base/i18n';
import { MEDIA_TYPE } from '../../../base/media';
import { isLocalTrackMuted } from '../../../base/tracks';
import AbstractVideoMuteButton from './AbstractVideoMuteButton';
import ToolbarButton from '../ToolbarButton';
declare var APP: Object;
/**
 * Component that renders a toolbar button for toggling video mute.
 *
 * @extends AbstractVideoMuteButton
 */
export class VideoMuteButton extends AbstractVideoMuteButton {
    /**
     * Default values for {@code VideoMuteButton} component's properties.
     *
     * @static
     */
    static defaultProps = {
        tooltipPosition: 'top'
    };
    /**
     * {@code VideoMuteButton} component's property types.
     *
     * @static
     */
    static propTypes = {
        ...AbstractVideoMuteButton.propTypes,
        /**
         * The {@code JitsiConference} for the current conference.
         */
        _conference: PropTypes.object,
        /**
         * Invoked to obtain translated strings.
         */
        t: PropTypes.func,
        /**
         * Where the tooltip should display, relative to the button.
         */
        tooltipPosition: PropTypes.string
    };
    /**
     * Initializes a new {@code VideoMuteButton} instance.
     *
     * @param {Props} props - The read-only React {@code Component} props with
     * which the new instance is to be initialized.
     */
    constructor(props: Object) {
        super(props);
        // Bind event handlers so they are only bound once per instance.
        this._onShortcutToggleVideo = this._onShortcutToggleVideo.bind(this);
    }
    /**
     * Sets a keyboard shortcuts for toggling video mute.
     *
     * @inheritdoc
     * @returns {void}
     */
    componentDidMount() {
        APP.keyboardshortcut.registerShortcut(
            'V',
            null,
            this._onShortcutToggleVideo,
            'keyboardShortcuts.videoMute');
    }
    /**
     * Removes the registered keyboard shortcut handler.
     *
     * @inheritdoc
     * @returns {void}
     */
    componentWillUnmount() {
        APP.keyboardshortcut.unregisterShortcut('V');
    }
    /**
     * Implements React's {@link Component#render()}.
     *
     * @inheritdoc
     * @returns {ReactElement}
     */
    render() {
        const { _conference, _videoMuted, t, tooltipPosition } = this.props;
        return (
            <ToolbarButton
                accessibilityLabel = 'Video mute'
                iconName = { _videoMuted && _conference
                    ? 'icon-camera-disabled toggled'
                    : 'icon-camera' }
                onClick = { this._onToolbarToggleVideo }
                tooltip = { t('toolbar.videomute') }
                tooltipPosition = { tooltipPosition } />
        );
    }
    _doToggleVideo: () => void;
    /**
     * Emits an event to signal video mute should be toggled.
     *
     * @private
     * @returns {void}
     */
    _doToggleVideo() {
        APP.UI.emitEvent(UIEvents.VIDEO_MUTED, !this.props._videoMuted);
    }
    _onShortcutToggleVideo: () => void;
    /**
     * Creates an analytics keyboard shortcut event for and dispatches an action
     * for toggling video mute.
     *
     * @private
     * @returns {void}
     */
    _onShortcutToggleVideo() {
        sendAnalytics(createShortcutEvent(
            VIDEO_MUTE,
            ACTION_SHORTCUT_TRIGGERED,
            { enable: !this.props._videoMuted }));
        this._doToggleVideo();
    }
    _onToolbarToggleVideo: () => void;
}
/**
 * Maps (parts of) the Redux state to the associated props for the
 * {@code AudioMuteButton} component.
 *
 * @param {Object} state - The Redux state.
 * @private
 * @returns {{
 *     _conference: Object,
 *     _videoMuted: boolean,
 * }}
 */
function _mapStateToProps(state) {
    const tracks = state['features/base/tracks'];
    return {
        _conference: state['features/base/conference'].conference,
        _videoMuted: isLocalTrackMuted(tracks, MEDIA_TYPE.VIDEO)
    };
}
export default translate(connect(_mapStateToProps)(VideoMuteButton));
 |