2020-04-16 10:47:10 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2020-05-20 08:25:31 +00:00
|
|
|
import { getCurrentConferenceUrl } from '../../../connection';
|
|
|
|
import { translate } from '../../../i18n';
|
|
|
|
import { Icon, IconCopy, IconCheck } from '../../../icons';
|
|
|
|
import { connect } from '../../../redux';
|
2020-07-15 10:07:10 +00:00
|
|
|
import { copyText, getDecodedURI } from '../../../util';
|
2020-04-16 10:47:10 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The meeting url.
|
|
|
|
*/
|
|
|
|
url: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for translation.
|
|
|
|
*/
|
2020-08-30 14:36:52 +00:00
|
|
|
t: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to determine if invitation link should be automatically copied
|
|
|
|
* after creating a meeting.
|
|
|
|
*/
|
|
|
|
_enableAutomaticUrlCopy: boolean,
|
2020-04-16 10:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true it shows the 'copy link' message.
|
|
|
|
*/
|
|
|
|
showCopyLink: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true it shows the 'link copied' message.
|
|
|
|
*/
|
|
|
|
showLinkCopied: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
const COPY_TIMEOUT = 2000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component used to copy meeting url on prejoin page.
|
|
|
|
*/
|
|
|
|
class CopyMeetingUrl extends Component<Props, State> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code Prejoin} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
showCopyLink: false,
|
|
|
|
showLinkCopied: false
|
|
|
|
};
|
|
|
|
this._copyUrl = this._copyUrl.bind(this);
|
|
|
|
this._hideCopyLink = this._hideCopyLink.bind(this);
|
|
|
|
this._hideLinkCopied = this._hideLinkCopied.bind(this);
|
|
|
|
this._showCopyLink = this._showCopyLink.bind(this);
|
|
|
|
this._showLinkCopied = this._showLinkCopied.bind(this);
|
2020-08-30 14:36:52 +00:00
|
|
|
this._copyUrlAutomatically = this._copyUrlAutomatically.bind(this);
|
2020-04-16 10:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_copyUrl: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback invoked to copy the url to clipboard.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_copyUrl() {
|
2020-06-24 07:34:00 +00:00
|
|
|
const success = copyText(this.props.url);
|
2020-04-16 10:47:10 +00:00
|
|
|
|
2020-06-24 07:34:00 +00:00
|
|
|
if (success) {
|
2020-04-16 10:47:10 +00:00
|
|
|
this._showLinkCopied();
|
|
|
|
window.setTimeout(this._hideLinkCopied, COPY_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_hideLinkCopied: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the 'Link copied' message.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_hideLinkCopied() {
|
|
|
|
this.setState({
|
|
|
|
showLinkCopied: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_hideCopyLink: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the 'Copy link' text.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_hideCopyLink() {
|
|
|
|
this.setState({
|
2020-05-20 08:25:31 +00:00
|
|
|
showCopyLink: false,
|
|
|
|
showLinkCopied: false
|
2020-04-16 10:47:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_showCopyLink: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the dark 'Copy link' text on hover.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_showCopyLink() {
|
|
|
|
this.setState({
|
2020-05-20 08:25:31 +00:00
|
|
|
showCopyLink: true,
|
|
|
|
showLinkCopied: false
|
2020-04-16 10:47:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_showLinkCopied: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the green 'Link copied' message.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_showLinkCopied() {
|
|
|
|
this.setState({
|
|
|
|
showLinkCopied: true,
|
|
|
|
showCopyLink: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-08-30 14:36:52 +00:00
|
|
|
_copyUrlAutomatically: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to automatically copy invitation URL.
|
|
|
|
* Document has to be focused in order for this to work.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_copyUrlAutomatically() {
|
|
|
|
navigator.clipboard.writeText(this.props.url)
|
|
|
|
.then(() => {
|
|
|
|
this._showLinkCopied();
|
|
|
|
window.setTimeout(this._hideLinkCopied, COPY_TIMEOUT);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#componentDidMount()}. Invoked
|
|
|
|
* immediately before mounting occurs.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
const { _enableAutomaticUrlCopy } = this.props;
|
|
|
|
|
|
|
|
if (_enableAutomaticUrlCopy) {
|
|
|
|
setTimeout(this._copyUrlAutomatically, 2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { showCopyLink, showLinkCopied } = this.state;
|
|
|
|
const { url, t } = this.props;
|
|
|
|
const { _copyUrl, _showCopyLink, _hideCopyLink } = this;
|
|
|
|
const src = showLinkCopied ? IconCheck : IconCopy;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2020-05-20 08:25:31 +00:00
|
|
|
className = 'copy-meeting'
|
2020-04-16 10:47:10 +00:00
|
|
|
onMouseEnter = { _showCopyLink }
|
|
|
|
onMouseLeave = { _hideCopyLink }>
|
2020-05-20 08:25:31 +00:00
|
|
|
<div
|
|
|
|
className = { `url ${showLinkCopied ? 'done' : ''}` }
|
|
|
|
onClick = { _copyUrl } >
|
2020-06-18 08:50:28 +00:00
|
|
|
<div className = 'copy-meeting-text'>
|
2020-07-15 10:07:10 +00:00
|
|
|
{ !showCopyLink && !showLinkCopied && getDecodedURI(url) }
|
2020-06-18 08:50:28 +00:00
|
|
|
{ showCopyLink && t('prejoin.copyAndShare') }
|
|
|
|
{ showLinkCopied && t('prejoin.linkCopied') }
|
|
|
|
</div>
|
2020-05-20 08:25:31 +00:00
|
|
|
<Icon
|
|
|
|
onClick = { _copyUrl }
|
|
|
|
size = { 24 }
|
|
|
|
src = { src } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-04-16 10:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the React {@code Component} props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
2020-08-30 14:36:52 +00:00
|
|
|
const { enableAutomaticUrlCopy } = state['features/base/config'];
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
return {
|
2020-08-30 14:36:52 +00:00
|
|
|
url: getCurrentConferenceUrl(state),
|
|
|
|
_enableAutomaticUrlCopy: enableAutomaticUrlCopy || false
|
2020-04-16 10:47:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(translate(CopyMeetingUrl));
|