-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Yesmunt
committed
Aug 6, 2019
1 parent
0b897c3
commit cb7fb90
Showing
13 changed files
with
157 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { connect } from 'react-redux'; | ||
import { makeSelectClaimForUri, makeSelectContentTypeForUri } from 'lbry-redux'; | ||
import AppViewer from './view'; | ||
|
||
const select = (state, props) => ({ | ||
claim: makeSelectClaimForUri(props.uri)(state), | ||
contentType: makeSelectContentTypeForUri(props.uri)(state), | ||
}); | ||
|
||
const perform = dispatch => ({}); | ||
|
||
export default connect( | ||
select, | ||
perform | ||
)(AppViewer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// @flow | ||
import React, { useState, useEffect } from 'react'; | ||
import LoadingScreen from 'component/common/loading-screen'; | ||
|
||
type Props = { | ||
source: string, | ||
claim: StreamClaim, | ||
contentType: string, | ||
}; | ||
|
||
const SANDBOX_TYPES = ['application/x-lbry', 'application/x-ext-lbry']; | ||
|
||
// This server exists in src/platforms/electron/startSandBox.js | ||
const SANDBOX_SET_BASE_URL = 'http://localhost:5278/set/'; | ||
const SANDBOX_CONTENT_BASE_URL = 'http://localhost:5278'; | ||
|
||
function AppViewer(props: Props) { | ||
const { claim, contentType } = props; | ||
const [loading, setLoading] = useState(true); | ||
const [appUrl, setAppUrl] = useState(false); | ||
|
||
const outpoint = `${claim.txid}:${claim.nout}`; | ||
useEffect(() => { | ||
if (SANDBOX_TYPES.indexOf(contentType) > -1) { | ||
fetch(`${SANDBOX_SET_BASE_URL}${outpoint}`) | ||
.then(res => res.text()) | ||
.then(url => { | ||
const appUrl = `${SANDBOX_CONTENT_BASE_URL}${url}`; | ||
setAppUrl(appUrl); | ||
setLoading(false); | ||
}) | ||
.catch(err => { | ||
setLoading(false); | ||
}); | ||
} else { | ||
setLoading(false); | ||
} | ||
}, [outpoint, contentType, setAppUrl, setLoading]); | ||
|
||
return ( | ||
<div className="file-render__viewer"> | ||
{!appUrl && ( | ||
<LoadingScreen status={loading ? __('Almost there') : __('Unable to view this file')} spinner={loading} /> | ||
)} | ||
{appUrl && ( | ||
<webview | ||
title="" | ||
sandbox="allow-scripts allow-forms allow-pointer-lock" | ||
src={appUrl} | ||
autosize="on" | ||
style={{ border: 0, width: '100%', height: '100%' }} | ||
useragent="Mozilla/5.0 AppleWebKit/537 Chrome/60 Safari/537" | ||
enableremotemodule="false" | ||
webpreferences="sandbox=true,contextIsolation=true,webviewTag=false,enableRemoteModule=false,devTools=false" | ||
/> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default AppViewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @flow | ||
import React from 'react'; | ||
|
||
type Props = { | ||
source: string, | ||
}; | ||
|
||
function ImageViewer(props: Props) { | ||
const { source } = props; | ||
return ( | ||
<div className="file-render__viewer"> | ||
<img src={source} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default ImageViewer; |
Oops, something went wrong.