2019-05-17 04:11:10 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-10-16 03:07:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2022-02-15 04:20:50 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2021-10-16 03:07:13 +08:00
|
|
|
import PadContainer from '/imports/ui/components/pads/container';
|
|
|
|
import Service from '/imports/ui/components/captions/service';
|
|
|
|
import Styled from './styles';
|
|
|
|
import { PANELS, ACTIONS } from '/imports/ui/components/layout/enums';
|
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2022-05-20 01:28:58 +08:00
|
|
|
import Header from '/imports/ui/components/common/control-header/component';
|
2021-10-16 03:07:13 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
hide: {
|
|
|
|
id: 'app.captions.hide',
|
|
|
|
description: 'Label for hiding closed captions',
|
|
|
|
},
|
|
|
|
takeOwnership: {
|
|
|
|
id: 'app.captions.ownership',
|
|
|
|
description: 'Label for taking ownership of closed captions',
|
|
|
|
},
|
|
|
|
takeOwnershipTooltip: {
|
|
|
|
id: 'app.captions.ownershipTooltip',
|
|
|
|
description: 'Text for button for taking ownership of closed captions',
|
|
|
|
},
|
|
|
|
dictationStart: {
|
|
|
|
id: 'app.captions.dictationStart',
|
|
|
|
description: 'Label for starting speech recognition',
|
|
|
|
},
|
|
|
|
dictationStop: {
|
|
|
|
id: 'app.captions.dictationStop',
|
2024-03-18 21:58:53 +08:00
|
|
|
description: 'Label for stopping speech recognition',
|
2021-10-16 03:07:13 +08:00
|
|
|
},
|
|
|
|
dictationOnDesc: {
|
|
|
|
id: 'app.captions.dictationOnDesc',
|
|
|
|
description: 'Aria description for button that turns on speech recognition',
|
|
|
|
},
|
|
|
|
dictationOffDesc: {
|
|
|
|
id: 'app.captions.dictationOffDesc',
|
|
|
|
description: 'Aria description for button that turns off speech recognition',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
locale: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
ownerId: PropTypes.string.isRequired,
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
dictation: PropTypes.bool.isRequired,
|
|
|
|
dictating: PropTypes.bool.isRequired,
|
|
|
|
isRTL: PropTypes.bool.isRequired,
|
|
|
|
hasPermission: PropTypes.bool.isRequired,
|
|
|
|
layoutContextDispatch: PropTypes.func.isRequired,
|
|
|
|
isResizing: PropTypes.bool.isRequired,
|
|
|
|
};
|
2019-07-06 03:44:12 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
const Captions = ({
|
|
|
|
locale,
|
|
|
|
intl,
|
|
|
|
ownerId,
|
|
|
|
name,
|
|
|
|
dictation,
|
|
|
|
dictating,
|
|
|
|
isRTL,
|
|
|
|
hasPermission,
|
|
|
|
layoutContextDispatch,
|
|
|
|
isResizing,
|
|
|
|
}) => {
|
|
|
|
const { isChrome } = browserInfo;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Styled.Captions isChrome={isChrome}>
|
2022-05-20 01:28:58 +08:00
|
|
|
<Header
|
|
|
|
leftButtonProps={{
|
|
|
|
onClick: () => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'aria-label': intl.formatMessage(intlMessages.hide),
|
|
|
|
label: name,
|
|
|
|
}}
|
|
|
|
customRightButton={Service.amICaptionsOwner(ownerId) ? (
|
|
|
|
<span>
|
2021-10-16 03:07:13 +08:00
|
|
|
<Button
|
2022-05-20 01:28:58 +08:00
|
|
|
onClick={dictating
|
|
|
|
? () => Service.stopDictation(locale)
|
|
|
|
: () => Service.startDictation(locale)}
|
|
|
|
label={dictating
|
|
|
|
? intl.formatMessage(intlMessages.dictationStop)
|
|
|
|
: intl.formatMessage(intlMessages.dictationStart)}
|
|
|
|
aria-describedby="dictationBtnDesc"
|
|
|
|
color={dictating ? 'danger' : 'primary'}
|
|
|
|
disabled={!dictation}
|
2021-10-16 03:07:13 +08:00
|
|
|
/>
|
2022-05-20 01:28:58 +08:00
|
|
|
<div id="dictationBtnDesc" hidden>
|
|
|
|
{dictating
|
|
|
|
? intl.formatMessage(intlMessages.dictationOffDesc)
|
|
|
|
: intl.formatMessage(intlMessages.dictationOnDesc)}
|
|
|
|
</div>
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<Button
|
|
|
|
color="primary"
|
|
|
|
tooltipLabel={intl.formatMessage(intlMessages.takeOwnershipTooltip, { 0: name })}
|
|
|
|
onClick={() => Service.updateCaptionsOwner(locale, name)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.takeOwnership)}
|
|
|
|
label={intl.formatMessage(intlMessages.takeOwnership)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2021-10-16 03:07:13 +08:00
|
|
|
<PadContainer
|
|
|
|
externalId={locale}
|
|
|
|
hasPermission={hasPermission}
|
|
|
|
isResizing={isResizing}
|
|
|
|
isRTL={isRTL}
|
|
|
|
/>
|
|
|
|
</Styled.Captions>
|
|
|
|
);
|
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
Captions.propTypes = propTypes;
|
2019-05-17 04:11:10 +08:00
|
|
|
|
2021-10-16 03:07:13 +08:00
|
|
|
export default injectWbResizeEvent(injectIntl(Captions));
|