lbry-desktop/ui/component/livestreamLayout/view.jsx

120 lines
3.8 KiB
React
Raw Normal View History

// @flow
import { lazyImport } from 'util/lazyImport';
2021-04-23 21:59:48 +02:00
import { useIsMobile } from 'effects/use-screensize';
import FileTitleSection from 'component/fileTitleSection';
import LivestreamLink from 'component/livestreamLink';
import React from 'react';
import { PRIMARY_PLAYER_WRAPPER_CLASS } from 'page/file/view';
import FileRenderInitiator from 'component/fileRenderInitiator';
import LivestreamIframeRender from './iframe-render';
import Button from 'component/button';
import * as ICONS from 'constants/icons';
import SwipeableDrawer from 'component/swipeableDrawer';
const LivestreamChatLayout = lazyImport(() => import('component/livestreamChatLayout' /* webpackChunkName: "chat" */));
type Props = {
activeStreamUri: boolean | string,
claim: ?StreamClaim,
hideComments: boolean,
isCurrentClaimLive: boolean,
release: any,
showLivestream: boolean,
showScheduledInfo: boolean,
uri: string,
};
export default function LivestreamLayout(props: Props) {
const {
activeStreamUri,
claim,
hideComments,
isCurrentClaimLive,
release,
showLivestream,
showScheduledInfo,
uri,
} = props;
2021-04-23 21:59:48 +02:00
const isMobile = useIsMobile();
const [showChat, setShowChat] = React.useState(undefined);
const drawerWasToggled = showChat !== undefined;
if (!claim || !claim.signing_channel) return null;
const { name: channelName, claim_id: channelClaimId } = claim.signing_channel;
2021-03-18 18:21:49 +01:00
return (
<>
<div className="section card-stack">
<React.Suspense fallback={null}>
{isMobile && isCurrentClaimLive ? (
<div className={PRIMARY_PLAYER_WRAPPER_CLASS}>
{/* Mobile needs to handle the livestream player like any video player */}
<FileRenderInitiator uri={uri} />
</div>
) : (
<LivestreamIframeRender
channelClaimId={channelClaimId}
release={release}
showLivestream={showLivestream}
showScheduledInfo={showScheduledInfo}
/>
)}
</React.Suspense>
{hideComments && !showScheduledInfo && (
<div className="help--notice">
2021-07-26 16:27:39 +02:00
{channelName
? __('%channel% has disabled chat for this stream. Enjoy the stream!', { channel: channelName })
2021-07-26 16:27:39 +02:00
: __('This channel has disabled chat for this stream. Enjoy the stream!')}
</div>
)}
{!activeStreamUri && !showScheduledInfo && !isCurrentClaimLive && (
2021-03-18 18:21:49 +01:00
<div className="help--notice">
2021-07-26 16:27:39 +02:00
{channelName
? __("%channelName% isn't live right now, but the chat is! Check back later to watch the stream.", {
channelName,
})
: __("This channel isn't live right now, but the chat is! Check back later to watch the stream.")}
2021-03-18 18:21:49 +01:00
</div>
)}
2021-04-23 21:59:48 +02:00
{activeStreamUri && (
<LivestreamLink
title={__("Click here to access the stream that's currently active")}
claimUri={activeStreamUri}
/>
)}
{isMobile && !hideComments && (
<React.Suspense fallback={null}>
<SwipeableDrawer
open={Boolean(showChat)}
toggleDrawer={() => setShowChat(!showChat)}
title={__('Live Chat')}
didInitialDisplay={drawerWasToggled}
>
<LivestreamChatLayout uri={uri} hideHeader />
</SwipeableDrawer>
</React.Suspense>
)}
2021-04-23 21:59:48 +02:00
{isMobile && (
<Button
className="swipeable-drawer__expand-button"
label="Open Live Chat"
button="primary"
icon={ICONS.CHAT}
onClick={() => setShowChat(!showChat)}
/>
)}
<FileTitleSection uri={uri} livestream isLive={showLivestream} />
</div>
</>
);
}