2016-04-21 11:51:27 +02:00
|
|
|
var videoStyle = {
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
backgroundColor: '#000'
|
|
|
|
};
|
|
|
|
|
|
|
|
var WatchPage = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
},
|
2016-05-05 10:12:23 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-05-05 12:55:15 +02:00
|
|
|
downloadStarted: false,
|
2016-05-05 10:12:23 +02:00
|
|
|
readyToPlay: false,
|
|
|
|
loadStatusMessage: "Requesting stream",
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
lbry.getStream(this.props.name);
|
|
|
|
this.updateLoadStatus();
|
2016-05-05 14:10:19 +02:00
|
|
|
},
|
|
|
|
reloadIfNeeded: function() {
|
|
|
|
// Fallback option for loading problems: every 15 seconds, if the video hasn't reported being
|
|
|
|
// playable yet, ask it to reload.
|
|
|
|
if (!this.state.readyToPlay) {
|
|
|
|
this._video.load()
|
2016-05-11 09:17:42 +02:00
|
|
|
setTimeout(() => { this.reloadIfNeeded() }, 15000);
|
2016-05-05 14:10:19 +02:00
|
|
|
}
|
2016-05-05 10:12:23 +02:00
|
|
|
},
|
2016-05-05 12:55:15 +02:00
|
|
|
onCanPlay: function() {
|
|
|
|
this.setState({
|
|
|
|
readyToPlay: true
|
|
|
|
});
|
|
|
|
},
|
2016-05-05 10:12:23 +02:00
|
|
|
updateLoadStatus: function() {
|
|
|
|
lbry.getFileStatus(this.props.name, (status) => {
|
2016-05-05 12:55:15 +02:00
|
|
|
if (!status || status.code != 'running' || status.written_bytes == 0) {
|
|
|
|
// Download hasn't started yet, so update status message (if available) then try again
|
|
|
|
if (status) {
|
|
|
|
this.setState({
|
|
|
|
loadStatusMessage: status.message
|
|
|
|
});
|
|
|
|
}
|
2016-05-05 10:12:23 +02:00
|
|
|
setTimeout(() => { this.updateLoadStatus() }, 250);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
2016-05-05 12:55:15 +02:00
|
|
|
loadStatusMessage: "Buffering",
|
|
|
|
downloadStarted: true,
|
2016-05-05 10:12:23 +02:00
|
|
|
});
|
2016-05-05 14:10:19 +02:00
|
|
|
setTimeout(() => { this.reloadIfNeeded() }, 15000);
|
2016-05-05 10:12:23 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-04-21 11:51:27 +02:00
|
|
|
render: function() {
|
2016-05-05 12:55:15 +02:00
|
|
|
if (!this.state.downloadStarted) {
|
|
|
|
var video = null;
|
2016-05-05 10:12:23 +02:00
|
|
|
} else {
|
2016-05-05 12:55:15 +02:00
|
|
|
// If the download has started, render the <video> behind the scenes so it can start loading.
|
|
|
|
// When the video is actually ready to play, the loading text is hidden and the video shown.
|
|
|
|
var video = <video src={"/view?name=" + this.props.name} style={videoStyle}
|
|
|
|
className={this.state.readyToPlay ? '' : 'hidden'} controls
|
2016-05-05 14:10:19 +02:00
|
|
|
onCanPlay={this.onCanPlay} ref={(video) => {this._video = video}}/>;
|
2016-05-05 10:12:23 +02:00
|
|
|
}
|
2016-05-05 12:55:15 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<div className={this.state.readyToPlay ? 'hidden' : ''}>
|
|
|
|
<h3>Loading lbry://{this.props.name}</h3>
|
|
|
|
{this.state.loadStatusMessage}...
|
|
|
|
</div>
|
|
|
|
{video}
|
|
|
|
</main>
|
|
|
|
);
|
2016-04-21 11:51:27 +02:00
|
|
|
}
|
|
|
|
});
|