2019-12-30 20:54:53 +01:00
|
|
|
// @flow
|
2021-08-13 05:06:04 +02:00
|
|
|
import { SITE_NAME } from 'config';
|
2020-04-14 01:48:11 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2020-09-21 17:34:58 +02:00
|
|
|
import classnames from 'classnames';
|
2021-07-06 11:02:05 +02:00
|
|
|
import FileRender from 'component/fileRender';
|
2020-05-26 18:16:30 +02:00
|
|
|
import FileViewerEmbeddedTitle from 'component/fileViewerEmbeddedTitle';
|
|
|
|
import Spinner from 'component/spinner';
|
2020-05-26 20:29:53 +02:00
|
|
|
import Button from 'component/button';
|
2020-11-10 07:23:08 +01:00
|
|
|
import Card from 'component/common/card';
|
2020-05-26 20:29:53 +02:00
|
|
|
import { formatLbryUrlForWeb } from 'util/url';
|
2020-09-21 17:34:58 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2019-12-30 20:54:53 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2021-03-24 01:49:29 +01:00
|
|
|
resolveUri: (string) => void,
|
2019-12-30 20:54:53 +01:00
|
|
|
claim: Claim,
|
2021-03-24 01:49:29 +01:00
|
|
|
doPlayUri: (string) => void,
|
2020-05-22 03:26:46 +02:00
|
|
|
costInfo: any,
|
|
|
|
streamingUrl: string,
|
2021-03-24 01:49:29 +01:00
|
|
|
doFetchCostInfoForUri: (string) => void,
|
2020-05-22 03:26:46 +02:00
|
|
|
isResolvingUri: boolean,
|
2020-11-10 07:23:08 +01:00
|
|
|
blackListedOutpoints: Array<{
|
|
|
|
txid: string,
|
|
|
|
nout: number,
|
|
|
|
}>,
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
2021-03-24 01:49:29 +01:00
|
|
|
|
|
|
|
export const EmbedContext = React.createContext<any>();
|
2019-12-30 20:54:53 +01:00
|
|
|
const EmbedWrapperPage = (props: Props) => {
|
2020-11-10 07:23:08 +01:00
|
|
|
const {
|
|
|
|
resolveUri,
|
|
|
|
claim,
|
|
|
|
uri,
|
|
|
|
doPlayUri,
|
|
|
|
costInfo,
|
|
|
|
streamingUrl,
|
|
|
|
doFetchCostInfoForUri,
|
|
|
|
isResolvingUri,
|
|
|
|
blackListedOutpoints,
|
|
|
|
} = props;
|
|
|
|
|
2020-09-21 17:34:58 +02:00
|
|
|
const {
|
|
|
|
location: { search },
|
|
|
|
} = useHistory();
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const embedLightBackground = urlParams.get('embedBackgroundLight');
|
2020-05-21 23:11:56 +02:00
|
|
|
const haveClaim = Boolean(claim);
|
2020-05-26 18:16:30 +02:00
|
|
|
const readyToDisplay = claim && streamingUrl;
|
|
|
|
const loading = !claim && isResolvingUri;
|
|
|
|
const noContentFound = !claim && !isResolvingUri;
|
|
|
|
const isPaidContent = costInfo && costInfo.cost > 0;
|
2020-05-26 20:29:53 +02:00
|
|
|
const contentLink = formatLbryUrlForWeb(uri);
|
2020-11-10 07:23:08 +01:00
|
|
|
const signingChannel = claim && claim.signing_channel;
|
|
|
|
const isClaimBlackListed =
|
|
|
|
claim &&
|
|
|
|
blackListedOutpoints &&
|
|
|
|
blackListedOutpoints.some(
|
2021-03-24 01:49:29 +01:00
|
|
|
(outpoint) =>
|
2020-11-10 07:23:08 +01:00
|
|
|
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
|
|
|
|
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
|
|
|
|
);
|
2020-01-31 20:33:40 +01:00
|
|
|
|
2019-12-30 20:54:53 +01:00
|
|
|
useEffect(() => {
|
2020-05-21 23:11:56 +02:00
|
|
|
if (resolveUri && uri && !haveClaim) {
|
2019-12-30 20:54:53 +01:00
|
|
|
resolveUri(uri);
|
|
|
|
}
|
2020-05-22 03:26:46 +02:00
|
|
|
if (uri && haveClaim && costInfo && costInfo.cost === 0) {
|
2020-05-21 23:11:56 +02:00
|
|
|
doPlayUri(uri);
|
|
|
|
}
|
2020-05-22 03:26:46 +02:00
|
|
|
}, [resolveUri, uri, doPlayUri, haveClaim, costInfo]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (haveClaim && uri && doFetchCostInfoForUri) {
|
|
|
|
doFetchCostInfoForUri(uri);
|
|
|
|
}
|
|
|
|
}, [uri, haveClaim, doFetchCostInfoForUri]);
|
2019-12-30 20:54:53 +01:00
|
|
|
|
2020-11-10 07:23:08 +01:00
|
|
|
if (isClaimBlackListed) {
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
title={uri}
|
|
|
|
subtitle={__(
|
|
|
|
'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this content from our applications.'
|
|
|
|
)}
|
|
|
|
actions={
|
|
|
|
<div className="section__actions">
|
2021-11-30 07:11:46 +01:00
|
|
|
<Button button="link" href="https://odysee.com/@OdyseeHelp:b/copyright:f" label={__('Read More')} />
|
2020-11-10 07:23:08 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:25:48 +01:00
|
|
|
return (
|
2020-09-21 17:34:58 +02:00
|
|
|
<div
|
|
|
|
className={classnames('embed__wrapper', {
|
|
|
|
'embed__wrapper--light-background': embedLightBackground,
|
|
|
|
})}
|
|
|
|
>
|
2020-05-22 03:26:46 +02:00
|
|
|
<EmbedContext.Provider value>
|
2020-05-26 18:16:30 +02:00
|
|
|
{readyToDisplay ? (
|
2021-07-06 11:02:05 +02:00
|
|
|
<FileRender uri={uri} embedded />
|
2020-05-26 18:16:30 +02:00
|
|
|
) : (
|
|
|
|
<div className="embed__loading">
|
|
|
|
<FileViewerEmbeddedTitle uri={uri} />
|
|
|
|
|
|
|
|
<div className="embed__loading-text">
|
2020-05-26 18:26:55 +02:00
|
|
|
{loading && <Spinner delayed light />}
|
|
|
|
{noContentFound && <h1>{__('No content found.')}</h1>}
|
2020-05-26 20:29:53 +02:00
|
|
|
{isPaidContent && (
|
|
|
|
<div>
|
|
|
|
<h1>{__('Paid content cannot be embedded.')}</h1>
|
|
|
|
<div className="section__actions--centered">
|
2021-08-13 05:06:04 +02:00
|
|
|
<Button label={__('Watch on %SITE_NAME%', { SITE_NAME })} button="primary" href={contentLink} />
|
2020-05-26 20:29:53 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-05-26 18:16:30 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
2020-05-22 03:26:46 +02:00
|
|
|
</EmbedContext.Provider>
|
2020-01-31 19:25:48 +01:00
|
|
|
</div>
|
|
|
|
);
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default EmbedWrapperPage;
|