2019-12-30 20:54:53 +01:00
|
|
|
// @flow
|
2020-04-14 01:48:11 +02:00
|
|
|
import React, { useEffect } from 'react';
|
2019-12-30 20:54:53 +01:00
|
|
|
import FileRender from 'component/fileRender';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
resolveUri: string => void,
|
|
|
|
claim: Claim,
|
2020-05-21 23:11:56 +02:00
|
|
|
doPlayUri: string => void,
|
2020-05-22 03:26:46 +02:00
|
|
|
costInfo: any,
|
|
|
|
streamingUrl: string,
|
|
|
|
doFetchCostInfoForUri: string => void,
|
|
|
|
isResolvingUri: boolean,
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
2020-01-31 19:25:48 +01:00
|
|
|
// $FlowFixMe apparently flow thinks this is wrong.
|
|
|
|
export const EmbedContext = React.createContext();
|
2019-12-30 20:54:53 +01:00
|
|
|
const EmbedWrapperPage = (props: Props) => {
|
2020-05-22 03:26:46 +02:00
|
|
|
const { resolveUri, claim, uri, doPlayUri, costInfo, streamingUrl, doFetchCostInfoForUri, isResolvingUri } = props;
|
2020-05-21 23:11:56 +02:00
|
|
|
const haveClaim = Boolean(claim);
|
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-01-31 19:25:48 +01:00
|
|
|
return (
|
|
|
|
<div className={'embed__wrapper'}>
|
2020-05-22 03:26:46 +02:00
|
|
|
<EmbedContext.Provider value>
|
|
|
|
{claim && streamingUrl && <FileRender uri={uri} embedded />}
|
|
|
|
{!claim && isResolvingUri && <h1>Loading...</h1>}
|
|
|
|
{!claim && !isResolvingUri && <h1>No content at this link.</h1>}
|
|
|
|
{claim && costInfo && costInfo.cost > 0 && <h1>Paid content cannot be embedded.</h1>}
|
|
|
|
</EmbedContext.Provider>
|
2020-01-31 19:25:48 +01:00
|
|
|
</div>
|
|
|
|
);
|
2019-12-30 20:54:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default EmbedWrapperPage;
|