// @flow import * as PAGES from 'constants/pages'; import * as PUBLISH_MODES from 'constants/publish_types'; 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 ClaimPreview from 'component/claimPreview'; import { FormField } from 'component/common/form'; import CopyableText from 'component/copyableText'; import Card from 'component/common/card'; import ClaimList from 'component/claimList'; import livestream from '../livestream'; type Props = { channels: Array, fetchingChannels: boolean, activeChannelClaim: ?ChannelClaim, }; export default function LivestreamSetupPage(props: Props) { const { channels, fetchingChannels, activeChannelClaim } = props; 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) => { console.log(data); setSigData(data); }) .catch((error) => { setSigData({ signature: null, signing_ts: null }); console.error(error); }); } } }, [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 [isFetching, setIsFetching] = React.useState(true); const [isLive, setIsLive] = React.useState(false); const [livestreamClaims, setLivestreamClaims] = React.useState([]); React.useEffect(() => { if (!activeChannelClaimStr) return; const channelClaim = JSON.parse(activeChannelClaimStr); Lbry.claim_search({ channel_ids: [channelClaim.claim_id], has_no_source: true, claim_type: ['stream'], }) .then((res) => { if (res && res.items && res.items.length > 0) { const claim = res.items[res.items.length - 1]; setLivestreamClaims(res.items.reverse()); } else { setIsFetching(false); } }) .catch(() => { setIsFetching(false); }); }, [activeChannelClaimStr]); return ( {fetchingChannels && (
)} {!fetchingChannels && !hasChannels && (