// @flow import * as PAGES from 'constants/pages'; import * as ICONS from 'constants/icons'; import { useHistory } from 'react-router'; import I18nMessage from 'component/i18nMessage'; import React from 'react'; import Page from 'component/page'; import Button from 'component/button'; import Yrbl from 'component/yrbl'; import Lbry from 'lbry'; import { toHex } from 'util/hex'; import { FormField } from 'component/common/form'; import CopyableText from 'component/copyableText'; import Card from 'component/common/card'; import ClaimList from 'component/claimList'; import { LIVESTREAM_RTMP_URL } from 'constants/livestream'; import { ENABLE_NO_SOURCE_CLAIMS } from 'config'; import classnames from 'classnames'; import LivestreamForm from 'component/publish/livestream/livestreamForm'; import Icon from 'component/common/icon'; import { useIsMobile } from 'effects/use-screensize'; import YrblWalletEmpty from 'component/yrblWalletEmpty'; type Props = { hasChannels: boolean, fetchingChannels: boolean, activeChannelClaim: ?ChannelClaim, pendingClaims: Array, doNewLivestream: (string) => void, fetchNoSourceClaims: (string) => void, clearPublish: () => void, myLivestreamClaims: Array, channelId: ?string, channelName: ?string, user: ?User, balance: number, editingURI: ?string, }; export default function LivestreamSetupPage(props: Props) { const LIVESTREAM_CLAIM_POLL_IN_MS = 60000; const { hasChannels, fetchingChannels, activeChannelClaim, pendingClaims, doNewLivestream, fetchNoSourceClaims, clearPublish, myLivestreamClaims, channelId, channelName, user, balance, editingURI, } = props; const isMobile = useIsMobile(); const { location: { search }, } = useHistory(); const urlParams = new URLSearchParams(search); const urlTab = urlParams.get('t'); const urlSource = urlParams.get('s'); const [sigData, setSigData] = React.useState({ signature: undefined, signing_ts: undefined }); const { odysee_live_disabled: liveDisabled } = user || {}; const livestreamEnabled = Boolean(ENABLE_NO_SOURCE_CLAIMS && user && !liveDisabled); const [isClear, setIsClear] = React.useState(false); function createStreamKey() { if (!channelId || !channelName || !sigData.signature || !sigData.signing_ts) return null; return `${channelId}?d=${toHex(channelName)}&s=${sigData.signature}&t=${sigData.signing_ts}`; } const formTitle = !editingURI ? __('Go Live') : __('Edit Livestream'); const streamKey = createStreamKey(); const pendingLength = pendingClaims.length; const totalLivestreamClaims = pendingClaims.concat(myLivestreamClaims); const helpText = (

{__( `Create a Livestream by first submitting your livestream details and waiting for approval confirmation. This can be done well in advance and will take a few minutes.` )}{' '} {__( `Scheduled livestreams will appear at the top of your channel page and for your followers. Regular livestreams will only appear once you are actually live.` )}{' '} {__( `Once the your livestream is confirmed, configure your streaming software (OBS, Restream, etc) and input the server URL along with the stream key in it.` )}

{__(`To ensure the best streaming experience with OBS, open settings -> output`)}

{__(`Select advanced mode from the dropdown at the top.`)}

{__(`Ensure the following settings are selected under the streaming tab:`)}

  • {__(`Bitrate: 1000 to 2500 kbps`)}
  • {__(`Keyframes: 2`)}
  • {__(`Profile: High`)}
  • {__(`Tune: Zerolatency`)}

{__(`If using other streaming software, make sure the bitrate is below 4500 kbps or the stream will not work.`)}

{__(`For streaming from your mobile device, we recommend PRISM Live Studio from the app store.`)}

{__( `After your stream:\nClick the Update button on the content page. This will allow you to select a replay or upload your own edited MP4. Replays are limited to 4 hours and may take a few minutes to show (use the Check For Replays button).` )}

{__(`Click Save, then confirm, and you are done!`)}

{__( `Note: If you don't plan on publishing your replay, you'll want to delete your livestream and then start with a fresh one next time.` )}

); function createNewLivestream() { setTab('Publish'); doNewLivestream(`/$/${PAGES.UPLOAD}`); } React.useEffect(() => { // ensure we have a channel if (channelId && channelName) { Lbry.channel_sign({ channel_id: channelId, hexdata: toHex(channelName), }) .then((data) => { setSigData(data); }) .catch((error) => { setSigData({ signature: null, signing_ts: null }); }); } }, [channelName, channelId, setSigData]); React.useEffect(() => { let checkClaimsInterval; if (!channelId) return; if (!checkClaimsInterval) { fetchNoSourceClaims(channelId); checkClaimsInterval = setInterval(() => fetchNoSourceClaims(channelId), LIVESTREAM_CLAIM_POLL_IN_MS); } return () => { if (checkClaimsInterval) { clearInterval(checkClaimsInterval); } }; }, [channelId, pendingLength, fetchNoSourceClaims]); const filterPending = (claims: Array) => { return claims.filter((claim) => { return !pendingClaims.some((pending) => pending.permanent_url === claim.permanent_url); }); }; const upcomingStreams = filterPending(myLivestreamClaims).filter((claim) => { return Number(claim.value.release_time) * 1000 > Date.now(); }); const pastStreams = filterPending(myLivestreamClaims).filter((claim) => { return Number(claim.value.release_time) * 1000 <= Date.now(); }); type HeaderProps = { title: string, hideBtn?: boolean, }; const ListHeader = (props: HeaderProps) => { const { title, hideBtn = false } = props; return (
{title} {!hideBtn && !isMobile && (
); }; const [tab, setTab] = React.useState(urlTab || 'Publish'); React.useEffect(() => { if (editingURI) { setTab('Publish'); } }, [editingURI]); React.useEffect(() => { if (urlTab) { setTab(urlTab); } }, [urlTab]); const HeaderMenu = (e) => { return ( <>