2017-09-27 21:23:31 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-31 15:42:50 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2017-10-10 23:43:22 +00:00
|
|
|
import { sendEvent } from '../../analytics';
|
2017-05-31 15:42:50 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
|
|
|
|
import RemoteVideoMenuButton from './RemoteVideoMenuButton';
|
|
|
|
|
|
|
|
// TODO: Move these enums into the store after further reactification of the
|
|
|
|
// non-react RemoteVideo component.
|
|
|
|
export const REMOTE_CONTROL_MENU_STATES = {
|
|
|
|
NOT_SUPPORTED: 0,
|
|
|
|
NOT_STARTED: 1,
|
|
|
|
REQUESTING: 2,
|
|
|
|
STARTED: 3
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays a button showing the
|
|
|
|
* current state of remote control for a participant and can start or stop a
|
|
|
|
* remote control session.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class RemoteControlButton extends Component {
|
|
|
|
/**
|
|
|
|
* {@code RemoteControlButton} component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The callback to invoke when the component is clicked.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
onClick: PropTypes.func,
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the participant linked to the onClick callback.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
participantID: PropTypes.string,
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current status of remote control. Should be a number listed in
|
|
|
|
* the enum REMOTE_CONTROL_MENU_STATES.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
remoteControlState: PropTypes.number,
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
2017-09-27 21:23:31 +00:00
|
|
|
t: PropTypes.func
|
2017-05-31 15:42:50 +00:00
|
|
|
};
|
|
|
|
|
2017-09-29 21:27:53 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code RemoteControlButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only React Component props with which
|
|
|
|
* the new instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onClick = this._onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {null|ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
participantID,
|
|
|
|
remoteControlState,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let className, icon;
|
|
|
|
|
|
|
|
switch (remoteControlState) {
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.NOT_STARTED:
|
|
|
|
className = 'requestRemoteControlLink';
|
|
|
|
icon = 'fa fa-play';
|
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.REQUESTING:
|
|
|
|
className = 'requestRemoteControlLink disabled';
|
|
|
|
icon = 'remote-control-spinner fa fa-spinner fa-spin';
|
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.STARTED:
|
|
|
|
className = 'requestRemoteControlLink';
|
|
|
|
icon = 'fa fa-stop';
|
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.NOT_SUPPORTED:
|
|
|
|
|
|
|
|
// Intentionally fall through.
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RemoteVideoMenuButton
|
|
|
|
buttonText = { t('videothumbnail.remoteControl') }
|
|
|
|
displayClass = { className }
|
|
|
|
iconClass = { icon }
|
|
|
|
id = { `remoteControl_${participantID}` }
|
2017-09-29 21:27:53 +00:00
|
|
|
onClick = { this._onClick } />
|
2017-05-31 15:42:50 +00:00
|
|
|
);
|
|
|
|
}
|
2017-09-29 21:27:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends analytics event for pressing the button and executes the passed
|
|
|
|
* onClick handler.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onClick() {
|
|
|
|
const { onClick, participantID, remoteControlState } = this.props;
|
|
|
|
|
|
|
|
let eventName;
|
|
|
|
|
|
|
|
if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
|
|
|
|
eventName = 'stop';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
|
|
|
|
eventName = 'start';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventName) {
|
2017-10-10 23:43:22 +00:00
|
|
|
sendEvent(
|
2017-09-29 21:27:53 +00:00
|
|
|
`remotevideomenu.remotecontrol.${eventName}`,
|
|
|
|
{
|
|
|
|
value: 1,
|
|
|
|
label: participantID
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(RemoteControlButton);
|