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';
|
|
|
|
|
|
|
|
import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
|
|
|
|
|
2015-07-14 11:11:28 +02:00
|
|
|
import AclProxy from '../acl_proxy';
|
|
|
|
|
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,
|
|
|
|
refreshObject: React.PropTypes.func
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
return {timerId: null};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (!this.props.content.digital_work) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let isEncoding = this.props.content.digital_work.isEncoding;
|
|
|
|
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() {
|
2015-07-21 15:52:58 +02:00
|
|
|
let thumbnail = this.props.content.thumbnail.thumbnail_sizes && this.props.content.thumbnail.thumbnail_sizes['600x600'] ?
|
|
|
|
this.props.content.thumbnail.thumbnail_sizes['600x600'] : this.props.content.thumbnail.url_safe;
|
2015-07-08 22:54:07 +02:00
|
|
|
let mimetype = this.props.content.digital_work.mime;
|
|
|
|
let embed = null;
|
|
|
|
let extraData = null;
|
2015-07-15 12:18:29 +02:00
|
|
|
let isEmbedDisabled = mimetype === 'video' && this.props.content.digital_work.isEncoding !== undefined && this.props.content.digital_work.isEncoding !== 100;
|
2015-07-08 22:54:07 +02:00
|
|
|
|
|
|
|
if (this.props.content.digital_work.encoding_urls) {
|
|
|
|
extraData = this.props.content.digital_work.encoding_urls.map(e => { return { url: e.url, type: e.label }; });
|
|
|
|
}
|
|
|
|
|
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-07-15 12:18:29 +02:00
|
|
|
<Button bsSize="xsmall" className="ascribe-margin-1px" disabled={isEmbedDisabled ? '"disabled"' : ''}>
|
2015-07-08 22:54:07 +02:00
|
|
|
Embed
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
panel={
|
|
|
|
<pre className="">
|
2015-08-07 14:23:59 +02:00
|
|
|
{'<iframe width="560" height="' + height + '" src="https://embed.ascribe.io/content/'
|
2015-07-15 12:18:29 +02:00
|
|
|
+ this.props.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
|
2015-07-15 11:47:14 +02:00
|
|
|
mimetype={mimetype}
|
|
|
|
preview={thumbnail}
|
|
|
|
url={this.props.content.digital_work.url}
|
2015-07-15 12:21:31 +02:00
|
|
|
extraData={extraData}
|
|
|
|
encodingStatus={this.props.content.digital_work.isEncoding} />
|
2015-07-08 22:54:07 +02:00
|
|
|
<p className="text-center">
|
2015-07-14 11:11:28 +02:00
|
|
|
<AclProxy
|
2015-07-23 15:18:58 +02:00
|
|
|
show={['video', 'audio', 'image'].indexOf(mimetype) === -1 || this.props.content.acl.acl_download}
|
2015-07-14 11:11:28 +02:00
|
|
|
aclObject={this.props.content.acl}
|
|
|
|
aclName="acl_download">
|
|
|
|
<Button bsSize="xsmall" className="ascribe-margin-1px" href={this.props.content.digital_work.url} target="_blank">
|
|
|
|
Download <Glyphicon glyph="cloud-download"/>
|
|
|
|
</Button>
|
|
|
|
</AclProxy>
|
2015-07-08 22:54:07 +02:00
|
|
|
{embed}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default MediaContainer;
|