bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/external-video-player/modal/component.jsx

143 lines
3.8 KiB
React
Raw Normal View History

import React, { Component } from 'react';
2022-02-15 23:54:55 +08:00
import { withModalMounter } from '/imports/ui/components/common/modal/service';
import { defineMessages, injectIntl } from 'react-intl';
import { isUrlValid } from '../service';
import Settings from '/imports/ui/services/settings';
import Styled from './styles';
const intlMessages = defineMessages({
start: {
id: 'app.externalVideo.start',
description: 'Share external video',
},
urlError: {
id: 'app.externalVideo.urlError',
description: 'Not a video URL error',
},
input: {
id: 'app.externalVideo.input',
description: 'Video URL',
},
2019-03-12 00:14:34 +08:00
urlInput: {
id: 'app.externalVideo.urlInput',
description: 'URL input field placeholder',
},
title: {
id: 'app.externalVideo.title',
description: 'Modal title',
},
close: {
id: 'app.externalVideo.close',
description: 'Close',
},
2019-03-15 21:04:19 +08:00
note: {
id: 'app.externalVideo.noteLabel',
description: 'provides hint about Shared External videos',
2019-03-15 21:04:19 +08:00
},
});
class ExternalVideoModal extends Component {
constructor(props) {
super(props);
2019-07-13 04:08:55 +08:00
const { videoUrl } = props;
2019-01-15 03:10:08 +08:00
this.state = {
2019-07-13 04:08:55 +08:00
url: videoUrl,
sharing: videoUrl,
};
this.startWatchingHandler = this.startWatchingHandler.bind(this);
this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this);
this.renderUrlError = this.renderUrlError.bind(this);
this.updateVideoUrlHandler = this.updateVideoUrlHandler.bind(this);
}
startWatchingHandler() {
const {
startWatching,
closeModal,
} = this.props;
const { url } = this.state;
2019-05-02 04:09:49 +08:00
startWatching(url.trim());
closeModal();
}
updateVideoUrlHandler(ev) {
this.setState({ url: ev.target.value });
}
renderUrlError() {
2019-01-15 03:10:08 +08:00
const { intl } = this.props;
const { url } = this.state;
const { animations } = Settings.application;
2019-01-15 03:10:08 +08:00
const valid = (!url || url.length <= 3) || isUrlValid(url);
return (
!valid
? (
<Styled.UrlError animations={animations}>
{intl.formatMessage(intlMessages.urlError)}
</Styled.UrlError>
)
: null
);
}
render() {
2019-09-11 02:04:42 +08:00
const { intl, closeModal } = this.props;
const { url, sharing } = this.state;
const { animations } = Settings.application;
const startDisabled = !isUrlValid(url);
return (
<Styled.ExternalVideoModal
onRequestClose={closeModal}
contentLabel={intl.formatMessage(intlMessages.title)}
title={intl.formatMessage(intlMessages.title)}
>
<Styled.Content>
<Styled.VideoUrl animations={animations}>
<label htmlFor="video-modal-input">
{intl.formatMessage(intlMessages.input)}
<input
2023-03-10 03:44:47 +08:00
autoFocus
id="video-modal-input"
onChange={this.updateVideoUrlHandler}
name="video-modal-input"
2019-03-12 00:14:34 +08:00
placeholder={intl.formatMessage(intlMessages.urlInput)}
disabled={sharing}
aria-describedby="exernal-video-note"
2022-11-04 00:06:25 +08:00
onPaste={(e) => { e.stopPropagation(); }}
2022-11-04 03:24:00 +08:00
onCut={(e) => { e.stopPropagation(); }}
onCopy={(e) => { e.stopPropagation(); }}
/>
</label>
<Styled.ExternalVideoNote id="external-video-note">
2019-03-15 21:04:19 +08:00
{intl.formatMessage(intlMessages.note)}
</Styled.ExternalVideoNote>
</Styled.VideoUrl>
<div>
{this.renderUrlError()}
</div>
<Styled.StartButton
label={intl.formatMessage(intlMessages.start)}
onClick={this.startWatchingHandler}
disabled={startDisabled}
2022-01-20 21:03:18 +08:00
data-test="startNewVideo"
2022-06-07 01:33:15 +08:00
color="primary"
/>
</Styled.Content>
</Styled.ExternalVideoModal>
);
}
}
export default injectIntl(withModalMounter(ExternalVideoModal));