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

134 lines
4.9 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 Glyphicon from 'react-bootstrap/lib/Glyphicon';
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
2015-07-08 22:54:07 +02:00
import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
2015-07-14 11:11:28 +02:00
import AclProxy from '../acl_proxy';
2015-11-10 19:33:08 +01:00
import { getLangText } from '../../utils/lang_utils.js';
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-08 22:54:07 +02:00
let MediaContainer = React.createClass({
propTypes: {
2015-08-11 17:12:12 +02:00
content: React.PropTypes.object,
currentUser: React.PropTypes.object,
2015-08-11 17:12:12 +02:00
refreshObject: React.PropTypes.func
},
getInitialState() {
return {
timerId: null
};
2015-08-11 17:12:12 +02:00
},
componentDidMount() {
if (!this.props.content.digital_work) {
return;
}
const isEncoding = this.props.content.digital_work.isEncoding;
2015-08-11 17:12:12 +02:00
if (this.props.content.digital_work.mime === 'video' && typeof isEncoding === 'number' && isEncoding !== 100 && !this.state.timerId) {
let timerId = window.setInterval(this.props.refreshObject, 10000);
this.setState({timerId: timerId});
}
},
componentWillUpdate() {
if (this.props.content.digital_work.isEncoding === 100) {
window.clearInterval(this.state.timerId);
}
},
componentWillUnmount() {
window.clearInterval(this.state.timerId);
2015-07-08 22:54:07 +02:00
},
render() {
const { content, currentUser } = this.props;
// 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);
2015-11-10 19:33:08 +01:00
let thumbnail = content.thumbnail.thumbnail_sizes && content.thumbnail.thumbnail_sizes['600x600'] ?
content.thumbnail.thumbnail_sizes['600x600'] : content.thumbnail.url_safe;
let mimetype = content.digital_work.mime;
2015-07-08 22:54:07 +02:00
let embed = null;
let extraData = null;
2015-11-10 19:33:08 +01:00
let isEmbedDisabled = mimetype === 'video' && content.digital_work.isEncoding !== undefined && content.digital_work.isEncoding !== 100;
2015-07-08 22:54:07 +02:00
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={
2015-12-16 17:49:47 +01:00
<Button
bsSize="xsmall"
className="ascribe-margin-1px"
disabled={isEmbedDisabled}>
{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>
}/>
);
}
return (
<div>
2015-07-15 12:18:29 +02:00
<MediaPlayer
mimetype={mimetype}
preview={thumbnail}
2015-11-10 19:33:08 +01:00
url={content.digital_work.url}
extraData={extraData}
2015-11-10 19:33:08 +01:00
encodingStatus={content.digital_work.isEncoding} />
<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">
<Button
bsSize="xsmall"
className="ascribe-margin-1px"
href={content.digital_work.url}
target="_blank">
{getLangText('Download')} .{mimetype} <Glyphicon glyph="cloud-download"/>
2015-07-14 11:11:28 +02:00
</Button>
</AclProxy>
2015-07-08 22:54:07 +02:00
{embed}
</p>
</div>
);
}
});
export default MediaContainer;