1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00
onion/js/components/ascribe_detail/media_container.js

185 lines
7.2 KiB
JavaScript
Raw Normal View History

2015-07-08 22:54:07 +02:00
'use strict';
import React from 'react';
import Button from 'react-bootstrap/lib/Button';
import ProgressBar from 'react-bootstrap/lib/ProgressBar';
2015-07-08 22:54:07 +02:00
import MediaPlayer from './../ascribe_media/media_player';
2015-11-09 17:46:49 +01:00
import FacebookShareButton from '../ascribe_social_share/facebook_share_button';
2015-11-09 19:01:27 +01:00
import TwitterShareButton from '../ascribe_social_share/twitter_share_button';
2015-11-09 17:46:49 +01:00
2016-02-17 11:38:01 +01:00
import S3DownloadButton from '../ascribe_buttons/s3_download_button';
2015-07-08 22:54:07 +02:00
import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
import AscribeSpinner from '../ascribe_spinner';
2015-07-14 11:11:28 +02:00
import AclProxy from '../acl_proxy';
import AppConstants from '../../constants/application_constants';
2016-02-05 10:38:59 +01:00
import { getLangText } from '../../utils/lang_utils';
import { extractFileExtensionFromUrl } from '../../utils/file_utils';
2016-02-05 10:38:59 +01:00
2015-07-08 22:54:07 +02:00
2015-07-23 15:04:02 +02:00
const EMBED_IFRAME_HEIGHT = {
video: 315,
audio: 62
};
2015-07-23 15:04:02 +02:00
2015-07-08 22:54:07 +02:00
let MediaContainer = React.createClass({
propTypes: {
2016-01-11 17:57:35 +01:00
content: React.PropTypes.object.isRequired,
refreshObject: React.PropTypes.func.isRequired,
currentUser: React.PropTypes.object
2015-08-11 17:12:12 +02:00
},
getInitialState() {
2016-01-11 17:52:32 +01:00
return {
timerId: null
};
2015-08-11 17:12:12 +02:00
},
componentDidMount() {
const { content: { digital_work: digitalWork }, refreshObject } = this.props;
const { timerId } = this.state;
if (digitalWork && (this.isVideoEncoding() || this.isImageEncoding()) && !timerId) {
this.setState({ timerId: window.setInterval(refreshObject, AppConstants.encodeUpdateThreshold) });
2015-08-11 17:12:12 +02:00
}
},
componentWillUpdate() {
const { timerId } = this.state;
if (!(this.isVideoEncoding() || this.isImageEncoding()) && timerId) {
window.clearInterval(timerId);
2015-08-11 17:12:12 +02:00
}
},
componentWillUnmount() {
window.clearInterval(this.state.timerId);
2015-07-08 22:54:07 +02:00
},
isVideoEncoding() {
const { content: { digital_work: digitalWork } } = this.props;
2016-03-10 17:07:11 +01:00
return digitalWork.mime === 'video' && typeof digitalWork.isEncoding === 'number' && digitalWork.isEncoding !== 100;
},
isImageEncoding() {
const { content: { thumbnail, digital_work: digitalWork } } = this.props;
2016-03-10 17:07:11 +01:00
const thumbnailToCheck = thumbnail.thumbnail_sizes && thumbnail.thumbnail_sizes['600x600'] ? thumbnail.thumbnail_sizes['600x600']
: thumbnail.url;
const thumbnailFileExtension = extractFileExtensionFromUrl(thumbnailToCheck);
return digitalWork.mime === 'image' && (thumbnailFileExtension === 'tif' || thumbnailFileExtension === 'tiff');
},
getEncodingMessage() {
if (this.isVideoEncoding()) {
2016-03-10 17:07:11 +01:00
const { content: { digital_work: digitalWork } } = this.props;
return (
<div className="ascribe-detail-header ascribe-media-player">
<p>
<em>We successfully received your video and it is now being encoded.
<br />You can leave this page and check back on the status later.</em>
</p>
<ProgressBar now={digitalWork.isEncoding}
label="%(percent)s%"
className="ascribe-progress-bar" />
</div>
);
} else if (this.isImageEncoding()) {
return (
<div className="ascribe-media-player encoding-image">
<AscribeSpinner color='dark-blue' size='lg' />
<em className="text-center">
{getLangText('We successfully received your image and it is now being encoded.')}
<br />
{getLangText('We will be refreshing this page as soon as encoding has finished.')}
<br />
{getLangText('(You may close this page)')}
</em>
</div>
);
}
},
2015-11-10 19:33:08 +01:00
render() {
const { content, currentUser } = this.props;
const mimetype = content.digital_work.mime;
// Pieces and editions are joined to the user by a foreign key in the database, so
// the information in content will be updated if a user updates their username.
// We also force uniqueness of usernames, so this check is safe to dtermine if the
// content was registered by the current user.
const didUserRegisterContent = currentUser && (currentUser.username === content.user_registered);
const thumbnail = content.thumbnail.thumbnail_sizes && content.thumbnail.thumbnail_sizes['600x600'] ? content.thumbnail.thumbnail_sizes['600x600']
: content.thumbnail.url_safe;
2016-02-05 10:38:59 +01:00
2015-07-08 22:54:07 +02:00
let embed = null;
let extraData = null;
2015-11-10 19:33:08 +01:00
if (content.digital_work.encoding_urls) {
extraData = content.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label }; });
2015-07-08 22:54:07 +02:00
}
2015-07-23 15:04:02 +02:00
if (['video', 'audio'].indexOf(mimetype) > -1) {
let height = EMBED_IFRAME_HEIGHT[mimetype];
2015-07-08 22:54:07 +02:00
embed = (
<CollapsibleButton
button={
2016-01-11 17:52:32 +01:00
<Button
bsSize="xsmall"
className="ascribe-margin-1px"
disabled={this.isVideoEncoding()}>
2016-01-11 17:52:32 +01:00
{getLangText('Embed')}
2015-07-08 22:54:07 +02:00
</Button>
}
panel={
<pre className="">
2015-08-07 14:23:59 +02:00
{'<iframe width="560" height="' + height + '" src="https://embed.ascribe.io/content/'
2015-11-10 19:33:08 +01:00
+ content.bitcoin_id + '" frameborder="0" allowfullscreen></iframe>'}
2015-07-08 22:54:07 +02:00
</pre>
2016-01-11 17:57:35 +01:00
} />
2015-07-08 22:54:07 +02:00
);
}
return (
<div>
2015-07-15 12:18:29 +02:00
<MediaPlayer
mimetype={mimetype}
thumbnail={thumbnail}
2015-11-10 19:33:08 +01:00
url={content.digital_work.url}
extraData={extraData}
encodingMessage={this.getEncodingMessage()} />
<p className="text-center hidden-print">
<span className="ascribe-social-button-list">
<FacebookShareButton />
2015-11-10 19:33:08 +01:00
<TwitterShareButton
text={getLangText('Check out %s ascribed piece', didUserRegisterContent ? 'my latest' : 'this' )} />
</span>
2015-07-14 11:11:28 +02:00
<AclProxy
2015-11-10 19:33:08 +01:00
show={['video', 'audio', 'image'].indexOf(mimetype) === -1 || content.acl.acl_download}
aclObject={content.acl}
2015-07-14 11:11:28 +02:00
aclName="acl_download">
2016-02-17 11:38:01 +01:00
<S3DownloadButton
url={content.digital_work.url}
title={content.title}
artistName={content.artist_name}
fileExtension={extractFileExtensionFromUrl(content.digital_work.url)} />
2015-07-14 11:11:28 +02:00
</AclProxy>
2015-07-08 22:54:07 +02:00
{embed}
</p>
</div>
);
}
});
export default MediaContainer;