2021-03-15 15:32:51 +01:00
|
|
|
// @flow
|
|
|
|
import * as PAGES from 'constants/pages';
|
2021-03-15 15:58:21 +01:00
|
|
|
import * as PUBLISH_MODES from 'constants/publish_types';
|
2021-03-15 15:32:51 +01:00
|
|
|
import React from 'react';
|
|
|
|
import Page from 'component/page';
|
|
|
|
import Spinner from 'component/spinner';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import ChannelSelector from 'component/channelSelector';
|
|
|
|
import Yrbl from 'component/yrbl';
|
|
|
|
import { Lbry } from 'lbry-redux';
|
|
|
|
import { toHex } from 'util/hex';
|
|
|
|
import { FormField } from 'component/common/form';
|
2021-03-15 15:58:21 +01:00
|
|
|
import CopyableText from 'component/copyableText';
|
|
|
|
import Card from 'component/common/card';
|
|
|
|
import ClaimList from 'component/claimList';
|
2021-03-15 15:32:51 +01:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
channels: Array<ChannelClaim>,
|
|
|
|
fetchingChannels: boolean,
|
|
|
|
activeChannelClaim: ?ChannelClaim,
|
2021-03-24 01:49:29 +01:00
|
|
|
pendingClaims: Array<Claim>,
|
2021-03-15 15:32:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function LivestreamSetupPage(props: Props) {
|
2021-03-24 01:49:29 +01:00
|
|
|
const { channels, fetchingChannels, activeChannelClaim, pendingClaims } = props;
|
2021-03-15 15:32:51 +01:00
|
|
|
|
|
|
|
const [sigData, setSigData] = React.useState({ signature: undefined, signing_ts: undefined });
|
|
|
|
|
|
|
|
const hasChannels = channels && channels.length > 0;
|
|
|
|
const activeChannelClaimStr = JSON.stringify(activeChannelClaim);
|
|
|
|
const streamKey = createStreamKey();
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (activeChannelClaimStr) {
|
|
|
|
const channelClaim = JSON.parse(activeChannelClaimStr);
|
|
|
|
|
|
|
|
// ensure we have a channel
|
|
|
|
if (channelClaim.claim_id) {
|
|
|
|
Lbry.channel_sign({
|
|
|
|
channel_id: channelClaim.claim_id,
|
|
|
|
hexdata: toHex(channelClaim.name),
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
setSigData(data);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
setSigData({ signature: null, signing_ts: null });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [activeChannelClaimStr, setSigData]);
|
|
|
|
|
|
|
|
function createStreamKey() {
|
|
|
|
if (!activeChannelClaim || !sigData.signature || !sigData.signing_ts) return null;
|
|
|
|
return `${activeChannelClaim.claim_id}?d=${toHex(activeChannelClaim.name)}&s=${sigData.signature}&t=${
|
|
|
|
sigData.signing_ts
|
|
|
|
}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [livestreamClaims, setLivestreamClaims] = React.useState([]);
|
2021-03-24 01:49:29 +01:00
|
|
|
// $FlowFixMe
|
|
|
|
const pendingLiveStreamClaims = pendingClaims.filter((claim) => !(claim && claim.value && claim.value.source));
|
|
|
|
const totalLivestreamClaims = pendingLiveStreamClaims.concat(livestreamClaims);
|
2021-03-15 15:32:51 +01:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (!activeChannelClaimStr) return;
|
|
|
|
|
|
|
|
const channelClaim = JSON.parse(activeChannelClaimStr);
|
|
|
|
|
|
|
|
Lbry.claim_search({
|
|
|
|
channel_ids: [channelClaim.claim_id],
|
2021-03-17 19:57:27 +01:00
|
|
|
has_no_source: true,
|
2021-03-15 15:32:51 +01:00
|
|
|
claim_type: ['stream'],
|
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
if (res && res.items && res.items.length > 0) {
|
|
|
|
setLivestreamClaims(res.items.reverse());
|
|
|
|
} else {
|
2021-03-17 22:00:58 +01:00
|
|
|
setLivestreamClaims([]);
|
2021-03-15 15:32:51 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
2021-03-17 22:00:58 +01:00
|
|
|
setLivestreamClaims([]);
|
2021-03-15 15:32:51 +01:00
|
|
|
});
|
|
|
|
}, [activeChannelClaimStr]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
{fetchingChannels && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner delayed />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!fetchingChannels && !hasChannels && (
|
|
|
|
<Yrbl
|
|
|
|
type="happy"
|
|
|
|
title={__("You haven't created a channel yet, let's fix that!")}
|
|
|
|
actions={
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button button="primary" navigate={`/$/${PAGES.CHANNEL_NEW}`} label={__('Create A Channel')} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2021-03-15 15:58:21 +01:00
|
|
|
<div className="card-stack">
|
|
|
|
{!fetchingChannels && activeChannelClaim && (
|
|
|
|
<>
|
|
|
|
<ChannelSelector hideAnon />
|
|
|
|
|
2021-03-24 01:49:29 +01:00
|
|
|
{streamKey && totalLivestreamClaims.length > 0 && (
|
2021-03-15 15:58:21 +01:00
|
|
|
<Card
|
|
|
|
title={__('Your stream key')}
|
|
|
|
actions={
|
|
|
|
<>
|
|
|
|
<CopyableText
|
|
|
|
primaryButton
|
|
|
|
name="stream-server"
|
|
|
|
label={__('Stream server')}
|
|
|
|
copyable="rtmp://stream.odysee.com/live"
|
|
|
|
snackMessage={__('Copied')}
|
|
|
|
/>
|
|
|
|
<CopyableText
|
|
|
|
primaryButton
|
|
|
|
name="livestream-key"
|
|
|
|
label={__('Stream key')}
|
|
|
|
copyable={streamKey}
|
|
|
|
snackMessage={__('Copied')}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
2021-03-15 15:32:51 +01:00
|
|
|
/>
|
2021-03-15 15:58:21 +01:00
|
|
|
)}
|
2021-03-15 15:32:51 +01:00
|
|
|
|
2021-03-24 01:49:29 +01:00
|
|
|
{totalLivestreamClaims.length > 0 ? (
|
2021-03-15 15:58:21 +01:00
|
|
|
<ClaimList
|
|
|
|
header={__('Your livestream uploads')}
|
2021-03-24 01:49:29 +01:00
|
|
|
uris={totalLivestreamClaims.map((claim) => claim.permanent_url)}
|
2021-03-15 15:32:51 +01:00
|
|
|
/>
|
2021-03-15 15:58:21 +01:00
|
|
|
) : (
|
|
|
|
<Yrbl
|
|
|
|
className="livestream__publish-intro"
|
|
|
|
title={__('No livestream publishes found')}
|
|
|
|
subtitle={__('You need to upload your livestream details before you can go live.')}
|
|
|
|
actions={
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button
|
|
|
|
button="primary"
|
|
|
|
navigate={`/$/${PAGES.UPLOAD}?type=${PUBLISH_MODES.LIVESTREAM.toLowerCase()}`}
|
|
|
|
label={__('Create A Livestream')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2021-03-15 15:32:51 +01:00
|
|
|
/>
|
2021-03-15 15:58:21 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
{/* Debug Stuff */}
|
|
|
|
{streamKey && false && (
|
|
|
|
<div style={{ marginTop: 'var(--spacing-l)' }}>
|
|
|
|
<h3>Debug Info</h3>
|
|
|
|
|
|
|
|
{/* Channel ID */}
|
|
|
|
<FormField
|
|
|
|
name={'channelId'}
|
|
|
|
label={'Channel ID'}
|
|
|
|
type={'text'}
|
|
|
|
defaultValue={activeChannelClaim.claim_id}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/* Signature */}
|
|
|
|
<FormField
|
|
|
|
name={'signature'}
|
|
|
|
label={'Signature'}
|
|
|
|
type={'text'}
|
|
|
|
defaultValue={sigData.signature}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/* Signature TS */}
|
|
|
|
<FormField
|
|
|
|
name={'signaturets'}
|
|
|
|
label={'Signature Timestamp'}
|
|
|
|
type={'text'}
|
|
|
|
defaultValue={sigData.signing_ts}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/* Hex Data */}
|
|
|
|
<FormField
|
|
|
|
name={'datahex'}
|
|
|
|
label={'Hex Data'}
|
|
|
|
type={'text'}
|
|
|
|
defaultValue={toHex(activeChannelClaim.name)}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/* Channel Public Key */}
|
|
|
|
<FormField
|
|
|
|
name={'channelpublickey'}
|
|
|
|
label={'Public Key'}
|
|
|
|
type={'text'}
|
|
|
|
defaultValue={activeChannelClaim.value.public_key}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-03-15 15:32:51 +01:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|