2018-06-11 00:41:25 -06:00
|
|
|
// @flow
|
2019-01-15 23:33:06 -05:00
|
|
|
import { remote } from 'electron';
|
2020-08-12 11:44:28 -04:00
|
|
|
import React from 'react';
|
2020-01-06 13:32:35 -05:00
|
|
|
import classnames from 'classnames';
|
2020-04-01 14:43:50 -04:00
|
|
|
import * as RENDER_MODES from 'constants/file_render_modes';
|
2019-04-03 00:56:58 -05:00
|
|
|
import VideoViewer from 'component/viewers/videoViewer';
|
2019-08-05 23:25:33 -04:00
|
|
|
import ImageViewer from 'component/viewers/imageViewer';
|
|
|
|
import AppViewer from 'component/viewers/appViewer';
|
2019-09-05 20:26:03 -04:00
|
|
|
import { withRouter } from 'react-router-dom';
|
2019-08-02 02:28:14 -04:00
|
|
|
import fs from 'fs';
|
2019-04-03 00:56:58 -05:00
|
|
|
|
2019-11-07 14:39:22 -05:00
|
|
|
import DocumentViewer from 'component/viewers/documentViewer';
|
|
|
|
import PdfViewer from 'component/viewers/pdfViewer';
|
2019-11-26 14:08:34 -05:00
|
|
|
import HtmlViewer from 'component/viewers/htmlViewer';
|
2020-04-01 14:43:50 -04:00
|
|
|
|
2019-11-26 14:08:34 -05:00
|
|
|
// @if TARGET='app'
|
2020-04-01 14:43:50 -04:00
|
|
|
// should match
|
2019-11-26 14:08:34 -05:00
|
|
|
import DocxViewer from 'component/viewers/docxViewer';
|
2019-11-07 14:39:22 -05:00
|
|
|
import ComicBookViewer from 'component/viewers/comicBookViewer';
|
|
|
|
import ThreeViewer from 'component/viewers/threeViewer';
|
2019-03-08 14:20:17 -05:00
|
|
|
// @endif
|
2018-06-11 00:41:25 -06:00
|
|
|
|
|
|
|
type Props = {
|
2019-08-05 23:25:33 -04:00
|
|
|
uri: string,
|
2019-08-02 02:28:14 -04:00
|
|
|
streamingUrl: string,
|
2020-01-27 16:37:54 -05:00
|
|
|
embedded?: boolean,
|
2019-08-02 02:28:14 -04:00
|
|
|
contentType: string,
|
2019-04-24 10:02:08 -04:00
|
|
|
claim: StreamClaim,
|
2018-06-11 00:41:25 -06:00
|
|
|
currentTheme: string,
|
2019-08-05 23:25:33 -04:00
|
|
|
downloadPath: string,
|
2020-04-01 14:43:50 -04:00
|
|
|
fileExtension: string,
|
2020-01-27 14:32:20 -05:00
|
|
|
autoplay: boolean,
|
2020-04-01 14:43:50 -04:00
|
|
|
renderMode: string,
|
2020-01-31 10:46:50 -05:00
|
|
|
thumbnail: string,
|
2020-05-05 14:02:12 -04:00
|
|
|
desktopPlayStartTime?: number,
|
2020-07-22 16:56:58 -04:00
|
|
|
className?: string,
|
2020-01-27 13:52:25 -05:00
|
|
|
};
|
|
|
|
|
2020-04-29 15:31:11 -04:00
|
|
|
class FileRender extends React.PureComponent<Props> {
|
2019-01-19 13:54:06 -05:00
|
|
|
constructor(props: Props) {
|
2019-01-15 23:33:06 -05:00
|
|
|
super(props);
|
|
|
|
|
2019-01-19 13:54:06 -05:00
|
|
|
(this: any).escapeListener = this.escapeListener.bind(this);
|
2019-01-15 23:33:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
window.addEventListener('keydown', this.escapeListener, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('keydown', this.escapeListener, true);
|
|
|
|
}
|
|
|
|
|
2019-01-19 13:54:06 -05:00
|
|
|
escapeListener(e: SyntheticKeyboardEvent<*>) {
|
2019-01-15 23:33:06 -05:00
|
|
|
if (e.keyCode === 27) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this.exitFullscreen();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exitFullscreen() {
|
|
|
|
remote.getCurrentWindow().setFullScreen(false);
|
|
|
|
}
|
|
|
|
|
2018-06-12 22:06:53 -06:00
|
|
|
renderViewer() {
|
2020-05-05 14:02:12 -04:00
|
|
|
const {
|
|
|
|
currentTheme,
|
|
|
|
contentType,
|
|
|
|
downloadPath,
|
|
|
|
fileExtension,
|
|
|
|
streamingUrl,
|
|
|
|
uri,
|
|
|
|
renderMode,
|
|
|
|
desktopPlayStartTime,
|
|
|
|
} = this.props;
|
2020-04-01 14:43:50 -04:00
|
|
|
const source = streamingUrl;
|
|
|
|
|
|
|
|
switch (renderMode) {
|
|
|
|
case RENDER_MODES.AUDIO:
|
|
|
|
case RENDER_MODES.VIDEO:
|
2020-05-05 14:02:12 -04:00
|
|
|
return (
|
|
|
|
<VideoViewer
|
|
|
|
uri={uri}
|
|
|
|
source={source}
|
|
|
|
contentType={contentType}
|
|
|
|
desktopPlayStartTime={desktopPlayStartTime}
|
|
|
|
/>
|
|
|
|
);
|
2020-04-01 14:43:50 -04:00
|
|
|
case RENDER_MODES.IMAGE:
|
|
|
|
return <ImageViewer uri={uri} source={source} />;
|
|
|
|
case RENDER_MODES.HTML:
|
|
|
|
return <HtmlViewer source={downloadPath || source} />;
|
|
|
|
case RENDER_MODES.DOCUMENT:
|
|
|
|
case RENDER_MODES.MARKDOWN:
|
|
|
|
return (
|
|
|
|
<DocumentViewer
|
|
|
|
source={{
|
|
|
|
// @if TARGET='app'
|
|
|
|
file: options => fs.createReadStream(downloadPath, options),
|
|
|
|
// @endif
|
|
|
|
stream: source,
|
|
|
|
fileExtension,
|
|
|
|
contentType,
|
|
|
|
}}
|
|
|
|
renderMode={renderMode}
|
|
|
|
theme={currentTheme}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case RENDER_MODES.DOCX:
|
|
|
|
return <DocxViewer source={downloadPath} />;
|
|
|
|
case RENDER_MODES.PDF:
|
|
|
|
return <PdfViewer source={downloadPath || source} />;
|
|
|
|
case RENDER_MODES.CAD:
|
2020-04-06 13:59:05 -04:00
|
|
|
return (
|
|
|
|
<ThreeViewer
|
|
|
|
source={{
|
2020-04-16 14:57:03 -05:00
|
|
|
fileType: fileExtension,
|
2020-04-06 13:59:05 -04:00
|
|
|
downloadPath,
|
|
|
|
}}
|
|
|
|
theme={currentTheme}
|
|
|
|
/>
|
|
|
|
);
|
2020-04-01 14:43:50 -04:00
|
|
|
case RENDER_MODES.COMIC:
|
2020-05-08 13:45:48 -05:00
|
|
|
return (
|
|
|
|
<ComicBookViewer
|
|
|
|
source={{
|
|
|
|
// @if TARGET='app'
|
|
|
|
file: options => fs.createReadStream(downloadPath, options),
|
|
|
|
// @endif
|
2020-07-22 16:56:58 -04:00
|
|
|
stream: source,
|
2020-05-08 13:45:48 -05:00
|
|
|
}}
|
|
|
|
theme={currentTheme}
|
2020-07-22 16:56:58 -04:00
|
|
|
/>
|
2020-05-08 13:45:48 -05:00
|
|
|
);
|
2020-04-01 14:43:50 -04:00
|
|
|
case RENDER_MODES.APPLICATION:
|
|
|
|
return <AppViewer uri={uri} />;
|
2018-08-01 22:56:17 -06:00
|
|
|
}
|
2019-03-21 09:59:31 -04:00
|
|
|
|
2020-04-01 14:43:50 -04:00
|
|
|
return null;
|
2018-06-11 00:41:25 -06:00
|
|
|
}
|
2020-04-01 14:43:50 -04:00
|
|
|
|
2018-06-11 00:41:25 -06:00
|
|
|
render() {
|
2020-07-22 16:56:58 -04:00
|
|
|
const { embedded, renderMode, className } = this.props;
|
2020-01-06 13:32:35 -05:00
|
|
|
|
2019-03-26 23:40:02 -05:00
|
|
|
return (
|
2020-01-27 16:37:54 -05:00
|
|
|
<div
|
2020-07-22 16:56:58 -04:00
|
|
|
className={classnames('file-render', className, {
|
2020-04-01 14:43:50 -04:00
|
|
|
'file-render--document': RENDER_MODES.TEXT_MODES.includes(renderMode) && !embedded,
|
2020-04-13 19:48:11 -04:00
|
|
|
'file-render--embed': embedded,
|
2020-10-20 13:10:02 -04:00
|
|
|
'file-render--video': renderMode === RENDER_MODES.VIDEO || renderMode === RENDER_MODES.AUDIO,
|
2020-01-27 16:37:54 -05:00
|
|
|
})}
|
|
|
|
>
|
2020-08-12 11:44:28 -04:00
|
|
|
{this.renderViewer()}
|
2019-03-26 23:40:02 -05:00
|
|
|
</div>
|
|
|
|
);
|
2018-06-11 00:41:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-05 20:26:03 -04:00
|
|
|
export default withRouter(FileRender);
|