Moar fixes for v30 (#2368)
* fix: document viewer * fix: allow paid content on desktop * change: add back sleep for appending video player
This commit is contained in:
parent
21895e8ce4
commit
93ce4299a4
3 changed files with 32 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import type { Claim } from 'types/claim';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import LoadingScreen from 'component/common/loading-screen';
|
import LoadingScreen from 'component/common/loading-screen';
|
||||||
|
@ -14,6 +15,7 @@ import ThreeViewer from 'component/viewers/threeViewer';
|
||||||
type Props = {
|
type Props = {
|
||||||
mediaType: string,
|
mediaType: string,
|
||||||
poster?: string,
|
poster?: string,
|
||||||
|
claim: Claim,
|
||||||
source: {
|
source: {
|
||||||
stream: string => void,
|
stream: string => void,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
|
@ -150,7 +152,9 @@ class FileRender extends React.PureComponent<Props> {
|
||||||
if (!viewer && readableFiles.includes(mediaType)) {
|
if (!viewer && readableFiles.includes(mediaType)) {
|
||||||
viewer = <DocumentViewer source={{ stream, fileType, contentType }} theme={currentTheme} />;
|
viewer = <DocumentViewer source={{ stream, fileType, contentType }} theme={currentTheme} />;
|
||||||
}
|
}
|
||||||
// temp workaround
|
|
||||||
|
// @if TARGET='web'
|
||||||
|
// temp workaround to disabled paid content on web
|
||||||
if (claim && claim.value.stream.metadata.fee && claim.value.stream.metadata.fee.amount > 0) {
|
if (claim && claim.value.stream.metadata.fee && claim.value.stream.metadata.fee.amount > 0) {
|
||||||
const paidMessage = __(
|
const paidMessage = __(
|
||||||
'Currently, only free content is available on lbry.tv. Try viewing it in the desktop app.'
|
'Currently, only free content is available on lbry.tv. Try viewing it in the desktop app.'
|
||||||
|
@ -158,6 +162,8 @@ class FileRender extends React.PureComponent<Props> {
|
||||||
const paid = <LoadingScreen status={paidMessage} spinner={false} />;
|
const paid = <LoadingScreen status={paidMessage} spinner={false} />;
|
||||||
return paid;
|
return paid;
|
||||||
}
|
}
|
||||||
|
// @endif
|
||||||
|
|
||||||
// Message Error
|
// Message Error
|
||||||
const unsupportedMessage = __("Sorry, looks like we can't preview this file.");
|
const unsupportedMessage = __("Sorry, looks like we can't preview this file.");
|
||||||
const unsupported = <LoadingScreen status={unsupportedMessage} spinner={false} />;
|
const unsupported = <LoadingScreen status={unsupportedMessage} spinner={false} />;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import 'babel-polyfill';
|
||||||
import type { Claim } from 'types/claim';
|
import type { Claim } from 'types/claim';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
|
@ -107,7 +108,7 @@ class MediaPlayer extends React.PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playMedia() {
|
async playMedia() {
|
||||||
const container = this.mediaContainer.current;
|
const container = this.mediaContainer.current;
|
||||||
const {
|
const {
|
||||||
downloadCompleted,
|
downloadCompleted,
|
||||||
|
@ -121,7 +122,6 @@ class MediaPlayer extends React.PureComponent<Props, State> {
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
|
|
||||||
const renderMediaCallback = error => {
|
const renderMediaCallback = error => {
|
||||||
if (error) this.setState({ unplayable: true });
|
if (error) this.setState({ unplayable: true });
|
||||||
};
|
};
|
||||||
|
@ -147,6 +147,10 @@ class MediaPlayer extends React.PureComponent<Props, State> {
|
||||||
currentMediaContainer.removeChild(currentMediaContainer.firstChild);
|
currentMediaContainer.removeChild(currentMediaContainer.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A slight delay is a hacky way to improve support for videos that aren't web-optimized
|
||||||
|
// Works... slightly better than not having it ¯\_(ツ)_/¯
|
||||||
|
await this.sleep(400);
|
||||||
|
|
||||||
player.append(
|
player.append(
|
||||||
{
|
{
|
||||||
name: fileName,
|
name: fileName,
|
||||||
|
@ -195,6 +199,10 @@ class MediaPlayer extends React.PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
|
sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
refreshMetadata() {
|
refreshMetadata() {
|
||||||
const { onStartCb } = this.props;
|
const { onStartCb } = this.props;
|
||||||
this.setState({ hasMetadata: true });
|
this.setState({ hasMetadata: true });
|
||||||
|
@ -354,7 +362,7 @@ class MediaPlayer extends React.PureComponent<Props, State> {
|
||||||
{loadingStatus && <LoadingScreen status={loadingStatus} spinner={isLoading} />}
|
{loadingStatus && <LoadingScreen status={loadingStatus} spinner={isLoading} />}
|
||||||
{isFileReady && <FileRender claim={claim} source={fileSource} mediaType={mediaType} />}
|
{isFileReady && <FileRender claim={claim} source={fileSource} mediaType={mediaType} />}
|
||||||
<div
|
<div
|
||||||
className='content__view--container'
|
className="content__view--container"
|
||||||
style={{ opacity: isLoading ? 0 : 1 }}
|
style={{ opacity: isLoading ? 0 : 1 }}
|
||||||
ref={this.mediaContainer}
|
ref={this.mediaContainer}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -32,21 +32,24 @@ class DocumentViewer extends React.PureComponent<Props, State> {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { source } = this.props;
|
const { source } = this.props;
|
||||||
const stream = source.stream('utf8');
|
|
||||||
|
|
||||||
let data = '';
|
if (source && source.stream) {
|
||||||
|
const stream = source.stream('utf8');
|
||||||
|
|
||||||
stream.on('data', chunk => {
|
let data = '';
|
||||||
data += chunk;
|
|
||||||
});
|
|
||||||
|
|
||||||
stream.on('end', () => {
|
stream.on('data', chunk => {
|
||||||
this.setState({ content: data, loading: false });
|
data += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('error', () => {
|
stream.on('end', () => {
|
||||||
this.setState({ error: true, loading: false });
|
this.setState({ content: data, loading: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stream.on('error', () => {
|
||||||
|
this.setState({ error: true, loading: false });
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDocument() {
|
renderDocument() {
|
||||||
|
|
Loading…
Reference in a new issue