add pdf-viewer
reduce lbry.getMedia calls update fileRender logic
This commit is contained in:
parent
6b8546789a
commit
03c9e53dd2
7 changed files with 57 additions and 22 deletions
|
@ -14,7 +14,7 @@ export default appState => {
|
||||||
defaultHeight: height,
|
defaultHeight: height,
|
||||||
});
|
});
|
||||||
|
|
||||||
let windowConfiguration = {
|
const windowConfiguration = {
|
||||||
backgroundColor: '#44b098',
|
backgroundColor: '#44b098',
|
||||||
minWidth: 950,
|
minWidth: 950,
|
||||||
minHeight: 600,
|
minHeight: 600,
|
||||||
|
@ -26,17 +26,13 @@ export default appState => {
|
||||||
// If state is undefined, create window as maximized.
|
// If state is undefined, create window as maximized.
|
||||||
width: windowState.width === undefined ? width : windowState.width,
|
width: windowState.width === undefined ? width : windowState.width,
|
||||||
height: windowState.height === undefined ? height : windowState.height,
|
height: windowState.height === undefined ? height : windowState.height,
|
||||||
};
|
|
||||||
|
|
||||||
// Disable renderer process's webSecurity on development to enable CORS.
|
|
||||||
windowConfiguration = isDev
|
|
||||||
? {
|
|
||||||
...windowConfiguration,
|
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
webSecurity: false,
|
// Disable renderer process's webSecurity on development to enable CORS.
|
||||||
|
webSecurity: !isDev,
|
||||||
|
plugins: true,
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
: windowConfiguration;
|
|
||||||
|
|
||||||
const rendererURL = isDev
|
const rendererURL = isDev
|
||||||
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
|
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import LoadingScreen from 'component/common/loading-screen';
|
import LoadingScreen from 'component/common/loading-screen';
|
||||||
// import ThreeViewer from 'component/threeViewer';
|
import PdfViewer from 'component/viewers/pdfViewer';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
mediaType: string,
|
mediaType: string,
|
||||||
source: {
|
source: {
|
||||||
filePath: string,
|
filePath: string,
|
||||||
fileType: string,
|
fileType: string,
|
||||||
|
downloadPath: string,
|
||||||
},
|
},
|
||||||
currentTheme: string,
|
currentTheme: string,
|
||||||
};
|
};
|
||||||
|
@ -23,7 +24,14 @@ class FileRender extends React.PureComponent<Props> {
|
||||||
// Add routes to viewer...
|
// Add routes to viewer...
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewer = mediaType && source && mediaTypes[mediaType];
|
// Supported fileType
|
||||||
|
const fileTypes = {
|
||||||
|
pdf: <PdfViewer {...viewerProps} />,
|
||||||
|
// Add routes to viewer...
|
||||||
|
};
|
||||||
|
|
||||||
|
const { fileType } = source;
|
||||||
|
const viewer = mediaType && source && (mediaTypes[mediaType] || fileTypes[fileType]);
|
||||||
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} />;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import LoadingScreen from 'component/common/loading-screen';
|
||||||
|
|
||||||
class VideoPlayer extends React.PureComponent {
|
class VideoPlayer extends React.PureComponent {
|
||||||
static MP3_CONTENT_TYPES = ['audio/mpeg3', 'audio/mpeg'];
|
static MP3_CONTENT_TYPES = ['audio/mpeg3', 'audio/mpeg'];
|
||||||
static FILE_MEDIA_TYPES = ['3D-file', 'e-book', 'comic-book'];
|
static FILE_MEDIA_TYPES = ['e-book', 'comic-book', 'document', '3D-file'];
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -192,6 +192,7 @@ class VideoPlayer extends React.PureComponent {
|
||||||
}
|
}
|
||||||
// File to render
|
// File to render
|
||||||
const fileSource = {
|
const fileSource = {
|
||||||
|
downloadPath,
|
||||||
filePath: url,
|
filePath: url,
|
||||||
fileType: path.extname(filename).substring(1),
|
fileType: path.extname(filename).substring(1),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Lbry } from 'lbry-redux';
|
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import type { Claim } from 'types/claim';
|
import type { Claim } from 'types/claim';
|
||||||
|
import LoadingScreen from 'component/common/loading-screen';
|
||||||
import VideoPlayer from './internal/player';
|
import VideoPlayer from './internal/player';
|
||||||
import VideoPlayButton from './internal/play-button';
|
import VideoPlayButton from './internal/play-button';
|
||||||
import LoadingScreen from 'component/common/loading-screen';
|
|
||||||
|
|
||||||
const SPACE_BAR_KEYCODE = 32;
|
const SPACE_BAR_KEYCODE = 32;
|
||||||
|
|
||||||
|
@ -40,6 +39,7 @@ type Props = {
|
||||||
obscureNsfw: boolean,
|
obscureNsfw: boolean,
|
||||||
play: string => void,
|
play: string => void,
|
||||||
searchBarFocused: boolean,
|
searchBarFocused: boolean,
|
||||||
|
mediaType: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Video extends React.PureComponent<Props> {
|
class Video extends React.PureComponent<Props> {
|
||||||
|
@ -123,12 +123,12 @@ class Video extends React.PureComponent<Props> {
|
||||||
mediaPosition,
|
mediaPosition,
|
||||||
className,
|
className,
|
||||||
obscureNsfw,
|
obscureNsfw,
|
||||||
|
mediaType,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const isPlaying = playingUri === uri;
|
const isPlaying = playingUri === uri;
|
||||||
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
||||||
const shouldObscureNsfw = obscureNsfw && metadata && metadata.nsfw;
|
const shouldObscureNsfw = obscureNsfw && metadata && metadata.nsfw;
|
||||||
const mediaType = (fileInfo && Lbry.getMediaType(null, fileInfo.file_name)) || Lbry.getMediaType(contentType);
|
|
||||||
|
|
||||||
let loadStatusMessage = '';
|
let loadStatusMessage = '';
|
||||||
|
|
||||||
|
|
24
src/renderer/component/viewers/pdfViewer.jsx
Normal file
24
src/renderer/component/viewers/pdfViewer.jsx
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// @flow
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
source: {
|
||||||
|
fileType: string,
|
||||||
|
filePath: string,
|
||||||
|
downloadPath: string,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
class PdfViewer extends React.PureComponent<Props> {
|
||||||
|
render() {
|
||||||
|
const { source } = this.props;
|
||||||
|
return (
|
||||||
|
<webview
|
||||||
|
className="file-render__viewer"
|
||||||
|
src={`chrome://pdf-viewer/index.html?src=file://${source.downloadPath}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PdfViewer;
|
|
@ -28,6 +28,7 @@ type Props = {
|
||||||
metadata: {
|
metadata: {
|
||||||
title: string,
|
title: string,
|
||||||
thumbnail: string,
|
thumbnail: string,
|
||||||
|
file_name: string,
|
||||||
nsfw: boolean,
|
nsfw: boolean,
|
||||||
},
|
},
|
||||||
contentType: string,
|
contentType: string,
|
||||||
|
@ -49,7 +50,7 @@ type Props = {
|
||||||
|
|
||||||
class FilePage extends React.Component<Props> {
|
class FilePage extends React.Component<Props> {
|
||||||
static PLAYABLE_MEDIA_TYPES = ['audio', 'video'];
|
static PLAYABLE_MEDIA_TYPES = ['audio', 'video'];
|
||||||
static PREVIEW_MEDIA_TYPES = ['text', 'image', '3D-file'];
|
static PREVIEW_MEDIA_TYPES = ['text', 'image', 'document', '3D-file'];
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -110,15 +111,17 @@ class FilePage extends React.Component<Props> {
|
||||||
navigate,
|
navigate,
|
||||||
autoplay,
|
autoplay,
|
||||||
costInfo,
|
costInfo,
|
||||||
|
fileInfo,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// File info
|
// File info
|
||||||
const { title, thumbnail, filename } = metadata;
|
const { title, thumbnail } = metadata;
|
||||||
const { height, channel_name: channelName, value } = claim;
|
const { height, channel_name: channelName, value } = claim;
|
||||||
const { PLAYABLE_MEDIA_TYPES, PREVIEW_MEDIA_TYPES } = FilePage;
|
const { PLAYABLE_MEDIA_TYPES, PREVIEW_MEDIA_TYPES } = FilePage;
|
||||||
const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id);
|
const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id);
|
||||||
const shouldObscureThumbnail = obscureNsfw && metadata.nsfw;
|
const shouldObscureThumbnail = obscureNsfw && metadata.nsfw;
|
||||||
const mediaType = Lbry.getMediaType(contentType, filename);
|
const fileName = fileInfo ? fileInfo.file_name : null;
|
||||||
|
const mediaType = fileName ? Lbry.getMediaType(null, fileName) : Lbry.getMediaType(contentType);
|
||||||
const showFile =
|
const showFile =
|
||||||
PLAYABLE_MEDIA_TYPES.includes(mediaType) || PREVIEW_MEDIA_TYPES.includes(mediaType);
|
PLAYABLE_MEDIA_TYPES.includes(mediaType) || PREVIEW_MEDIA_TYPES.includes(mediaType);
|
||||||
const channelClaimId =
|
const channelClaimId =
|
||||||
|
@ -154,7 +157,7 @@ class FilePage extends React.Component<Props> {
|
||||||
</section>
|
</section>
|
||||||
) : (
|
) : (
|
||||||
<section className="card">
|
<section className="card">
|
||||||
{showFile && <Video className="content__embedded" uri={uri} />}
|
{showFile && <Video className="content__embedded" uri={uri} mediaType={mediaType} />}
|
||||||
{!showFile &&
|
{!showFile &&
|
||||||
(thumbnail ? (
|
(thumbnail ? (
|
||||||
<Thumbnail shouldObscure={shouldObscureThumbnail} src={thumbnail} />
|
<Thumbnail shouldObscure={shouldObscureThumbnail} src={thumbnail} />
|
||||||
|
@ -164,7 +167,9 @@ class FilePage extends React.Component<Props> {
|
||||||
'content__empty--nsfw': shouldObscureThumbnail,
|
'content__empty--nsfw': shouldObscureThumbnail,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className="card__media-text">{__('This content is not playable.')}</div>
|
<div className="card__media-text">
|
||||||
|
{__("Sorry, looks like we can't preview this file.")}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<div className="card__content">
|
<div className="card__content">
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
.file-render__viewer {
|
.file-render__viewer {
|
||||||
|
margin: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: black;
|
background: black;
|
||||||
|
|
Loading…
Reference in a new issue