2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2017-12-11 18:48:32 +00:00
|
|
|
import {
|
2018-01-03 21:24:07 +00:00
|
|
|
createRemoteVideoMenuButtonEvent,
|
|
|
|
sendAnalytics
|
2018-12-19 18:40:17 +00:00
|
|
|
} from '../../../analytics';
|
|
|
|
import { translate } from '../../../base/i18n';
|
2019-08-30 16:39:06 +00:00
|
|
|
import { IconRemoteControlStart, IconRemoteControlStop } from '../../../base/icons';
|
2017-05-31 15:42:50 +00:00
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
import VideoMenuButton from './VideoMenuButton';
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link RemoteControlButton}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The callback to invoke when the component is clicked.
|
|
|
|
*/
|
|
|
|
onClick: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The ID of the participant linked to the onClick callback.
|
|
|
|
*/
|
|
|
|
participantID: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current status of remote control. Should be a number listed in the
|
|
|
|
* enum REMOTE_CONTROL_MENU_STATES.
|
|
|
|
*/
|
|
|
|
remoteControlState: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
class RemoteControlButton extends Component<Props> {
|
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.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
2017-09-29 21:27:53 +00:00
|
|
|
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:
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = IconRemoteControlStart;
|
2017-05-31 15:42:50 +00:00
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.REQUESTING:
|
2018-11-29 11:36:22 +00:00
|
|
|
className = ' disabled';
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = IconRemoteControlStart;
|
2017-05-31 15:42:50 +00:00
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.STARTED:
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = IconRemoteControlStop;
|
2017-05-31 15:42:50 +00:00
|
|
|
break;
|
|
|
|
case REMOTE_CONTROL_MENU_STATES.NOT_SUPPORTED:
|
|
|
|
|
|
|
|
// Intentionally fall through.
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-01-21 20:46:47 +00:00
|
|
|
<VideoMenuButton
|
2017-05-31 15:42:50 +00:00
|
|
|
buttonText = { t('videothumbnail.remoteControl') }
|
|
|
|
displayClass = { className }
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = { icon }
|
2017-05-31 15:42:50 +00:00
|
|
|
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
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onClick: () => void;
|
|
|
|
|
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;
|
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
// TODO: What do we do in case the state is e.g. "requesting"?
|
|
|
|
if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED
|
|
|
|
|| remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
|
2017-09-29 21:27:53 +00:00
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
const enable
|
|
|
|
= remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
|
2017-09-29 21:27:53 +00:00
|
|
|
|
2018-01-03 21:24:07 +00:00
|
|
|
sendAnalytics(createRemoteVideoMenuButtonEvent(
|
|
|
|
'remote.control.button',
|
2017-09-29 21:27:53 +00:00
|
|
|
{
|
2018-01-03 21:24:07 +00:00
|
|
|
enable,
|
|
|
|
'participant_id': participantID
|
|
|
|
}));
|
2017-09-29 21:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
onClick();
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(RemoteControlButton);
|