2019-12-30 20:54:53 +01:00
|
|
|
// @flow
|
2021-08-13 05:06:04 +02:00
|
|
|
import { SITE_NAME } from 'config';
|
2022-03-15 17:47:36 +01:00
|
|
|
import React 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';
|
2022-03-15 17:47:36 +01:00
|
|
|
import { formatLbryUrlForWeb, formatLbryChannelName } from 'util/url';
|
2020-09-21 17:34:58 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2022-03-16 16:30:02 +01:00
|
|
|
import Yrbl from 'component/yrbl';
|
2022-03-16 15:28:59 +01:00
|
|
|
// $FlowFixMe cannot resolve ...
|
2022-03-16 18:35:27 +01:00
|
|
|
import useFetchLiveStatus from 'effects/use-fetch-live';
|
2022-03-17 11:53:18 +01:00
|
|
|
import useThumbnail from 'effects/use-thumbnail';
|
2019-12-30 20:54:53 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2022-03-16 18:35:27 +01:00
|
|
|
claimId: ?string,
|
|
|
|
haveClaim: boolean,
|
|
|
|
nullClaim: boolean,
|
|
|
|
canonicalUrl: ?string,
|
|
|
|
txid: ?string,
|
|
|
|
nout: ?string,
|
|
|
|
channelUri: ?string,
|
|
|
|
channelClaimId: ?string,
|
|
|
|
channelTxid: ?string,
|
|
|
|
channelNout: ?string,
|
2020-05-22 03:26:46 +02:00
|
|
|
costInfo: any,
|
|
|
|
streamingUrl: string,
|
|
|
|
isResolvingUri: boolean,
|
2022-03-15 17:47:36 +01:00
|
|
|
blackListedOutpoints: Array<{ txid: string, nout: number }>,
|
|
|
|
isCurrentClaimLive: boolean,
|
|
|
|
isLivestreamClaim: boolean,
|
2022-03-16 15:28:59 +01:00
|
|
|
claimThumbnail?: string,
|
|
|
|
obscurePreview: boolean,
|
2022-03-16 16:30:02 +01:00
|
|
|
activeLivestreamInitialized: boolean,
|
|
|
|
geoRestriction: ?GeoRestriction,
|
2022-03-15 17:47:36 +01:00
|
|
|
doResolveUri: (uri: string) => void,
|
|
|
|
doPlayUri: (uri: string) => void,
|
|
|
|
doFetchCostInfoForUri: (uri: string) => void,
|
|
|
|
doFetchChannelLiveStatus: (string) => void,
|
|
|
|
doCommentSocketConnect: (string, string, string) => void,
|
|
|
|
doCommentSocketDisconnect: (string, string) => void,
|
|
|
|
doFetchActiveLivestreams: () => void,
|
2022-03-22 19:13:19 +01:00
|
|
|
setReferrer: (uri: string) => void,
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
2021-03-24 01:49:29 +01:00
|
|
|
|
|
|
|
export const EmbedContext = React.createContext<any>();
|
2022-03-15 17:47:36 +01:00
|
|
|
|
2022-03-16 18:35:27 +01:00
|
|
|
export default function EmbedWrapperPage(props: Props) {
|
2020-11-10 07:23:08 +01:00
|
|
|
const {
|
|
|
|
uri,
|
2022-03-16 18:35:27 +01:00
|
|
|
claimId,
|
|
|
|
haveClaim,
|
|
|
|
nullClaim,
|
|
|
|
canonicalUrl,
|
|
|
|
txid,
|
|
|
|
nout,
|
|
|
|
channelUri,
|
|
|
|
channelClaimId,
|
|
|
|
channelTxid,
|
|
|
|
channelNout,
|
2020-11-10 07:23:08 +01:00
|
|
|
costInfo,
|
|
|
|
streamingUrl,
|
|
|
|
isResolvingUri,
|
|
|
|
blackListedOutpoints,
|
2022-03-15 17:47:36 +01:00
|
|
|
isCurrentClaimLive,
|
2022-03-16 15:47:06 +01:00
|
|
|
isLivestreamClaim,
|
2022-03-16 15:28:59 +01:00
|
|
|
claimThumbnail,
|
|
|
|
obscurePreview,
|
2022-03-16 16:30:02 +01:00
|
|
|
activeLivestreamInitialized,
|
|
|
|
geoRestriction,
|
2022-03-15 17:47:36 +01:00
|
|
|
doResolveUri,
|
|
|
|
doPlayUri,
|
|
|
|
doFetchCostInfoForUri,
|
|
|
|
doFetchChannelLiveStatus,
|
|
|
|
doCommentSocketConnect,
|
|
|
|
doCommentSocketDisconnect,
|
|
|
|
doFetchActiveLivestreams,
|
2022-03-22 19:13:19 +01:00
|
|
|
setReferrer,
|
2020-11-10 07:23:08 +01:00
|
|
|
} = props;
|
|
|
|
|
2020-09-21 17:34:58 +02:00
|
|
|
const {
|
|
|
|
location: { search },
|
|
|
|
} = useHistory();
|
2022-03-15 17:47:36 +01:00
|
|
|
|
2022-03-16 15:28:59 +01:00
|
|
|
const containerRef = React.useRef<any>();
|
2022-03-16 15:38:34 +01:00
|
|
|
const [livestreamsFetched, setLivestreamsFetched] = React.useState(false);
|
2022-03-16 15:28:59 +01:00
|
|
|
|
2022-03-16 18:35:27 +01:00
|
|
|
const channelUrl = channelUri && formatLbryChannelName(channelUri);
|
2020-09-21 17:34:58 +02:00
|
|
|
const urlParams = new URLSearchParams(search);
|
2022-03-22 19:13:19 +01:00
|
|
|
const rawReferrerParam = urlParams.get('r');
|
|
|
|
const sanitizedReferrerParam = rawReferrerParam && rawReferrerParam.replace(':', '#');
|
2020-09-21 17:34:58 +02:00
|
|
|
const embedLightBackground = urlParams.get('embedBackgroundLight');
|
2022-03-16 18:35:27 +01:00
|
|
|
const readyToDisplay = isCurrentClaimLive || (haveClaim && streamingUrl);
|
2022-03-16 16:30:02 +01:00
|
|
|
const isLiveClaimFetching = isLivestreamClaim && !activeLivestreamInitialized;
|
2022-03-16 18:35:27 +01:00
|
|
|
const isLiveClaimNotPlaying = isLivestreamClaim && !isLiveClaimFetching && !readyToDisplay;
|
|
|
|
const loading = (!haveClaim && isResolvingUri) || isLiveClaimFetching;
|
|
|
|
const noContentFound = nullClaim && !isResolvingUri;
|
|
|
|
const hasCost = 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 isClaimBlackListed =
|
2022-03-16 18:35:27 +01:00
|
|
|
haveClaim &&
|
2020-11-10 07:23:08 +01:00
|
|
|
blackListedOutpoints &&
|
|
|
|
blackListedOutpoints.some(
|
2021-03-24 01:49:29 +01:00
|
|
|
(outpoint) =>
|
2022-03-16 18:35:27 +01:00
|
|
|
(channelUrl && outpoint.txid === channelTxid && outpoint.nout === channelNout) ||
|
|
|
|
(outpoint.txid === txid && outpoint.nout === nout)
|
2020-11-10 07:23:08 +01:00
|
|
|
);
|
2022-03-16 15:28:59 +01:00
|
|
|
|
2022-03-17 11:53:18 +01:00
|
|
|
const thumbnail = useThumbnail(claimThumbnail, containerRef);
|
2022-03-16 15:28:59 +01:00
|
|
|
|
2022-03-22 19:13:19 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!sanitizedReferrerParam) setReferrer(uri);
|
|
|
|
}, [sanitizedReferrerParam, setReferrer, uri]);
|
|
|
|
|
2022-03-16 15:28:59 +01:00
|
|
|
React.useEffect(() => {
|
2022-03-16 15:47:06 +01:00
|
|
|
if (doFetchActiveLivestreams && isLivestreamClaim) {
|
2022-03-16 15:38:34 +01:00
|
|
|
doFetchActiveLivestreams();
|
|
|
|
setLivestreamsFetched(true);
|
|
|
|
}
|
2022-03-16 15:47:06 +01:00
|
|
|
}, [doFetchActiveLivestreams, isLivestreamClaim]);
|
2022-03-15 17:47:36 +01:00
|
|
|
|
2022-03-16 12:35:58 +01:00
|
|
|
// Establish web socket connection for viewer count.
|
|
|
|
React.useEffect(() => {
|
2022-03-16 15:47:06 +01:00
|
|
|
if (!isLivestreamClaim || !claimId || !channelUrl || !canonicalUrl) return;
|
2022-03-16 12:35:58 +01:00
|
|
|
|
|
|
|
const channelName = formatLbryChannelName(channelUrl);
|
|
|
|
|
|
|
|
doCommentSocketConnect(canonicalUrl, channelName, claimId);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
if (claimId) {
|
|
|
|
doCommentSocketDisconnect(claimId, channelName);
|
|
|
|
}
|
|
|
|
};
|
2022-03-16 15:47:06 +01:00
|
|
|
}, [canonicalUrl, channelUrl, claimId, doCommentSocketConnect, doCommentSocketDisconnect, isLivestreamClaim]);
|
2022-03-15 17:47:36 +01:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (doResolveUri && uri && !haveClaim) {
|
|
|
|
doResolveUri(uri);
|
2019-12-30 20:54:53 +01:00
|
|
|
}
|
2022-03-16 15:47:06 +01:00
|
|
|
|
2022-03-16 18:35:27 +01:00
|
|
|
if (uri && haveClaim && !hasCost) {
|
2020-05-21 23:11:56 +02:00
|
|
|
doPlayUri(uri);
|
|
|
|
}
|
2022-03-16 18:35:27 +01:00
|
|
|
}, [doPlayUri, doResolveUri, hasCost, haveClaim, uri]);
|
2020-05-22 03:26:46 +02:00
|
|
|
|
2022-03-15 17:47:36 +01:00
|
|
|
React.useEffect(() => {
|
2020-05-22 03:26:46 +02:00
|
|
|
if (haveClaim && uri && doFetchCostInfoForUri) {
|
|
|
|
doFetchCostInfoForUri(uri);
|
|
|
|
}
|
|
|
|
}, [uri, haveClaim, doFetchCostInfoForUri]);
|
2019-12-30 20:54:53 +01:00
|
|
|
|
2022-03-16 18:35:27 +01:00
|
|
|
useFetchLiveStatus(livestreamsFetched ? channelClaimId : undefined, doFetchChannelLiveStatus);
|
2022-03-15 17:47:36 +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>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-16 16:30:02 +01:00
|
|
|
if (geoRestriction) {
|
|
|
|
return (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Yrbl title={__('Content unavailable')} subtitle={__(geoRestriction.message || '')} type="sad" alwaysShow />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-16 18:35:27 +01:00
|
|
|
if (isLiveClaimNotPlaying) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="embed__inline-button"
|
|
|
|
style={thumbnail && !obscurePreview ? { backgroundImage: `url("${thumbnail}")`, height: '100%' } : {}}
|
|
|
|
>
|
|
|
|
<FileViewerEmbeddedTitle uri={uri} />
|
|
|
|
|
|
|
|
<a target="_blank" rel="noopener noreferrer" href={formatLbryUrlForWeb(uri)}>
|
|
|
|
<Button iconSize={30} title={__('View')} className="button--icon button--view" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:25:48 +01:00
|
|
|
return (
|
2022-03-16 18:35:27 +01:00
|
|
|
<div className={classnames('embed__wrapper', { 'embed__wrapper--light-background': embedLightBackground })}>
|
|
|
|
<EmbedContext.Provider value>
|
|
|
|
{readyToDisplay ? (
|
|
|
|
<FileRender uri={uri} embedded />
|
|
|
|
) : (
|
|
|
|
<div className="embed__loading">
|
|
|
|
<FileViewerEmbeddedTitle uri={uri} />
|
|
|
|
|
|
|
|
<div className="embed__loading-text">
|
|
|
|
{(loading || (!haveClaim && !noContentFound)) && <Spinner delayed light />}
|
|
|
|
|
|
|
|
{noContentFound && <h1>{__('No content found.')}</h1>}
|
|
|
|
|
|
|
|
{hasCost && (
|
|
|
|
<div>
|
|
|
|
<h1>{__('Paid content cannot be embedded.')}</h1>
|
|
|
|
<div className="section__actions--centered">
|
|
|
|
<Button label={__('Watch on %SITE_NAME%', { SITE_NAME })} button="primary" href={contentLink} />
|
2020-05-26 20:29:53 +02:00
|
|
|
</div>
|
2022-03-16 18:35:27 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2020-05-26 18:16:30 +02:00
|
|
|
</div>
|
2022-03-16 18:35:27 +01:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</EmbedContext.Provider>
|
2020-01-31 19:25:48 +01:00
|
|
|
</div>
|
|
|
|
);
|
2022-03-16 18:35:27 +01:00
|
|
|
}
|