2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
2017-02-03 11:25:05 +01:00
|
|
|
import {Icon} from '../component/common.js';
|
|
|
|
import {Link} from '../component/link.js';
|
2016-11-22 21:19:08 +01:00
|
|
|
import lbry from '../lbry.js';
|
2017-01-03 03:21:23 +01:00
|
|
|
import LoadScreen from '../component/load_screen.js'
|
|
|
|
|
2017-01-19 10:50:08 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const VideoStream = require('videostream');
|
|
|
|
|
|
|
|
|
2016-04-21 11:51:27 +02:00
|
|
|
var WatchPage = React.createClass({
|
2017-02-16 08:18:26 +01:00
|
|
|
_isMounted: false,
|
|
|
|
_controlsHideDelay: 3000, // Note: this needs to be shorter than the built-in delay in Electron, or Electron will hide the controls before us
|
|
|
|
_controlsHideTimeout: null,
|
2017-03-08 08:17:16 +01:00
|
|
|
_outpoint: null,
|
2017-02-16 08:18:26 +01:00
|
|
|
|
2016-04-21 11:51:27 +02:00
|
|
|
propTypes: {
|
2017-04-11 03:30:02 +02:00
|
|
|
uri: React.PropTypes.string,
|
2016-04-21 11:51:27 +02:00
|
|
|
},
|
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",
|
2016-06-03 12:05:14 +02:00
|
|
|
mimeType: null,
|
2017-02-16 08:18:26 +01:00
|
|
|
controlsShown: false,
|
2016-05-05 10:12:23 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
2017-04-11 03:30:02 +02:00
|
|
|
lbry.get({uri: this.props.uri}).then((fileInfo) => {
|
2017-03-08 08:17:16 +01:00
|
|
|
this._outpoint = fileInfo.outpoint;
|
|
|
|
this.updateLoadStatus();
|
|
|
|
});
|
2016-05-05 14:10:19 +02:00
|
|
|
},
|
2017-02-03 11:25:05 +01:00
|
|
|
handleBackClicked: function() {
|
|
|
|
history.back();
|
|
|
|
},
|
2017-02-16 08:18:26 +01:00
|
|
|
handleMouseMove: function() {
|
|
|
|
if (this._controlsTimeout) {
|
|
|
|
clearTimeout(this._controlsTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.state.controlsShown) {
|
|
|
|
this.setState({
|
|
|
|
controlsShown: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this._controlsTimeout = setTimeout(() => {
|
|
|
|
if (!this.isMounted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
controlsShown: false,
|
|
|
|
});
|
|
|
|
}, this._controlsHideDelay);
|
|
|
|
},
|
2017-02-23 08:46:19 +01:00
|
|
|
handleMouseLeave: function() {
|
2017-02-16 08:18:26 +01:00
|
|
|
if (this._controlsTimeout) {
|
|
|
|
clearTimeout(this._controlsTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.controlsShown) {
|
|
|
|
this.setState({
|
|
|
|
controlsShown: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2016-05-05 10:12:23 +02:00
|
|
|
updateLoadStatus: function() {
|
2017-03-14 17:30:54 +01:00
|
|
|
lbry.file_list({
|
2017-03-08 08:17:16 +01:00
|
|
|
outpoint: this._outpoint,
|
|
|
|
full_status: true,
|
2017-03-14 17:30:54 +01:00
|
|
|
}).then(([status]) => {
|
|
|
|
if (!status || status.written_bytes == 0) {
|
2016-05-05 12:55:15 +02:00
|
|
|
// Download hasn't started yet, so update status message (if available) then try again
|
2017-03-08 08:17:16 +01:00
|
|
|
// TODO: Would be nice to check if we have the MOOV before starting playing
|
2016-05-05 12:55:15 +02:00
|
|
|
if (status) {
|
|
|
|
this.setState({
|
2017-02-21 05:15:17 +01:00
|
|
|
loadStatusMessage: status.message
|
2016-05-05 12:55:15 +02:00
|
|
|
});
|
|
|
|
}
|
2016-05-05 10:12:23 +02:00
|
|
|
setTimeout(() => { this.updateLoadStatus() }, 250);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
2016-06-03 12:05:14 +02:00
|
|
|
readyToPlay: true,
|
|
|
|
mimeType: status.mime_type,
|
2016-05-13 13:46:39 +02:00
|
|
|
})
|
2017-03-08 08:17:16 +01:00
|
|
|
const mediaFile = {
|
|
|
|
createReadStream: function (opts) {
|
|
|
|
// Return a readable stream that provides the bytes
|
|
|
|
// between offsets "start" and "end" inclusive
|
|
|
|
console.log('Stream between ' + opts.start + ' and ' + opts.end + '.');
|
|
|
|
return fs.createReadStream(status.download_path, opts)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var elem = this.refs.video;
|
|
|
|
var videostream = VideoStream(mediaFile, elem);
|
|
|
|
elem.play();
|
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
|
|
|
return (
|
2016-09-21 07:37:43 +02:00
|
|
|
!this.state.readyToPlay
|
2016-09-24 21:27:07 +02:00
|
|
|
? <LoadScreen message={'Loading video...'} details={this.state.loadStatusMessage} />
|
2017-02-23 08:46:19 +01:00
|
|
|
: <main className="video full-screen" onMouseMove={this.handleMouseMove} onMouseLeave={this.handleMouseLeave}>
|
2017-02-03 11:25:05 +01:00
|
|
|
<video controls width="100%" height="100%" id="video" ref="video"></video>
|
2017-02-16 08:18:26 +01:00
|
|
|
{this.state.controlsShown
|
|
|
|
? <div className="video__overlay">
|
|
|
|
<div className="video__back">
|
|
|
|
<Link icon="icon-arrow-circle-o-left" className="video__back-link" onClick={this.handleBackClicked}/>
|
|
|
|
<div className="video__back-label">
|
|
|
|
<Icon icon="icon-caret-left" className="video__back-label-arrow" />
|
|
|
|
<div className="video__back-label-content">
|
|
|
|
Back to LBRY
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-03 11:25:05 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-16 08:18:26 +01:00
|
|
|
: null}
|
2016-09-21 07:37:43 +02:00
|
|
|
</main>
|
2016-05-05 12:55:15 +02:00
|
|
|
);
|
2016-04-21 11:51:27 +02:00
|
|
|
}
|
|
|
|
});
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
export default WatchPage;
|