2021-03-10 19:34:21 +01:00
|
|
|
// @flow
|
2022-02-02 13:48:24 +01:00
|
|
|
import 'scss/component/_swipeable-drawer.scss';
|
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
import { lazyImport } from 'util/lazyImport';
|
2021-04-23 21:59:48 +02:00
|
|
|
import { useIsMobile } from 'effects/use-screensize';
|
2022-02-02 13:45:16 +01:00
|
|
|
import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button';
|
2022-01-14 21:24:16 +01:00
|
|
|
import FileTitleSection from 'component/fileTitleSection';
|
2021-12-16 22:59:13 +01:00
|
|
|
import LivestreamLink from 'component/livestreamLink';
|
2022-01-14 21:24:16 +01:00
|
|
|
import React from 'react';
|
2022-02-01 21:30:57 +01:00
|
|
|
import { PRIMARY_PLAYER_WRAPPER_CLASS } from 'page/file/view';
|
|
|
|
import FileRenderInitiator from 'component/fileRenderInitiator';
|
|
|
|
import LivestreamIframeRender from './iframe-render';
|
2022-02-02 13:44:33 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import SwipeableDrawer from 'component/swipeableDrawer';
|
2022-02-02 13:48:24 +01:00
|
|
|
import { DrawerExpandButton } from 'component/swipeableDrawer/view';
|
2022-02-02 13:45:16 +01:00
|
|
|
import LivestreamMenu from 'component/livestreamChatLayout/livestream-menu';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
|
|
|
import { getTipValues } from 'util/livestream';
|
2021-10-18 17:54:59 +02:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
const LivestreamChatLayout = lazyImport(() => import('component/livestreamChatLayout' /* webpackChunkName: "chat" */));
|
2021-03-10 19:34:21 +01:00
|
|
|
|
2022-02-02 13:45:16 +01:00
|
|
|
const VIEW_MODES = {
|
|
|
|
CHAT: 'chat',
|
|
|
|
SUPERCHAT: 'sc',
|
|
|
|
};
|
|
|
|
|
2021-03-10 19:34:21 +01:00
|
|
|
type Props = {
|
2022-01-14 21:24:16 +01:00
|
|
|
activeStreamUri: boolean | string,
|
2021-03-10 19:34:21 +01:00
|
|
|
claim: ?StreamClaim,
|
2021-12-16 22:59:13 +01:00
|
|
|
hideComments: boolean,
|
2022-01-14 21:24:16 +01:00
|
|
|
isCurrentClaimLive: boolean,
|
2021-12-16 22:59:13 +01:00
|
|
|
release: any,
|
|
|
|
showLivestream: boolean,
|
|
|
|
showScheduledInfo: boolean,
|
2022-01-14 21:24:16 +01:00
|
|
|
uri: string,
|
2022-02-02 13:45:16 +01:00
|
|
|
superChats: Array<Comment>,
|
2021-03-10 19:34:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function LivestreamLayout(props: Props) {
|
2021-12-16 22:59:13 +01:00
|
|
|
const {
|
2022-01-14 21:24:16 +01:00
|
|
|
activeStreamUri,
|
2021-12-16 22:59:13 +01:00
|
|
|
claim,
|
|
|
|
hideComments,
|
2022-01-14 21:24:16 +01:00
|
|
|
isCurrentClaimLive,
|
2021-12-16 22:59:13 +01:00
|
|
|
release,
|
|
|
|
showLivestream,
|
|
|
|
showScheduledInfo,
|
2022-01-14 21:24:16 +01:00
|
|
|
uri,
|
2022-02-02 13:45:16 +01:00
|
|
|
superChats,
|
2021-12-16 22:59:13 +01:00
|
|
|
} = props;
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
const isMobile = useIsMobile();
|
2021-03-10 19:34:21 +01:00
|
|
|
|
2022-02-02 13:44:33 +01:00
|
|
|
const [showChat, setShowChat] = React.useState(undefined);
|
2022-02-02 13:45:16 +01:00
|
|
|
const [superchatsHidden, setSuperchatsHidden] = React.useState(false);
|
|
|
|
const [chatViewMode, setChatViewMode] = React.useState(VIEW_MODES.CHAT);
|
2022-02-02 13:44:33 +01:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
if (!claim || !claim.signing_channel) return null;
|
2021-03-10 19:34:21 +01:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
const { name: channelName, claim_id: channelClaimId } = claim.signing_channel;
|
2021-03-18 18:21:49 +01:00
|
|
|
|
2021-03-10 19:34:21 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="section card-stack">
|
2022-02-01 21:30:57 +01:00
|
|
|
<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>
|
2021-03-10 19:34:21 +01:00
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
{hideComments && !showScheduledInfo && (
|
2021-06-03 17:55:16 +02:00
|
|
|
<div className="help--notice">
|
2021-07-26 16:27:39 +02:00
|
|
|
{channelName
|
2021-09-15 04:08:41 +02:00
|
|
|
? __('%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!')}
|
2021-06-03 17:55:16 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
{!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
|
|
|
|
2021-12-22 17:12:44 +01:00
|
|
|
{activeStreamUri && (
|
|
|
|
<LivestreamLink
|
|
|
|
title={__("Click here to access the stream that's currently active")}
|
|
|
|
claimUri={activeStreamUri}
|
|
|
|
/>
|
|
|
|
)}
|
2021-12-16 22:59:13 +01:00
|
|
|
|
2022-01-14 21:24:16 +01:00
|
|
|
{isMobile && !hideComments && (
|
|
|
|
<React.Suspense fallback={null}>
|
2022-02-02 13:44:33 +01:00
|
|
|
<SwipeableDrawer
|
|
|
|
open={Boolean(showChat)}
|
|
|
|
toggleDrawer={() => setShowChat(!showChat)}
|
2022-02-02 13:48:24 +01:00
|
|
|
title={
|
|
|
|
<ChatModeSelector
|
|
|
|
superChats={superChats}
|
|
|
|
chatViewMode={chatViewMode}
|
|
|
|
setChatViewMode={(mode) => setChatViewMode(mode)}
|
|
|
|
/>
|
|
|
|
}
|
2022-02-02 13:45:16 +01:00
|
|
|
actions={
|
|
|
|
<LivestreamMenu
|
|
|
|
noSuperchats={!superChats || superChats.length === 0}
|
|
|
|
superchatsHidden={superchatsHidden}
|
|
|
|
toggleSuperchats={() => setSuperchatsHidden(!superchatsHidden)}
|
2022-02-02 13:48:24 +01:00
|
|
|
isMobile
|
2022-02-02 13:45:16 +01:00
|
|
|
/>
|
|
|
|
}
|
2022-02-02 13:44:33 +01:00
|
|
|
>
|
2022-02-02 13:45:16 +01:00
|
|
|
<LivestreamChatLayout
|
|
|
|
uri={uri}
|
|
|
|
hideHeader
|
|
|
|
superchatsHidden={superchatsHidden}
|
|
|
|
customViewMode={chatViewMode}
|
|
|
|
/>
|
2022-02-02 13:44:33 +01:00
|
|
|
</SwipeableDrawer>
|
2021-04-23 21:59:48 +02:00
|
|
|
|
2022-02-02 13:48:24 +01:00
|
|
|
<DrawerExpandButton label={__('Open Live Chat')} toggleDrawer={() => setShowChat(!showChat)} />
|
|
|
|
</React.Suspense>
|
2022-02-02 13:44:33 +01:00
|
|
|
)}
|
|
|
|
|
2021-12-16 22:59:13 +01:00
|
|
|
<FileTitleSection uri={uri} livestream isLive={showLivestream} />
|
2021-03-10 19:34:21 +01:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2022-02-02 13:48:24 +01:00
|
|
|
|
|
|
|
const ChatModeSelector = (chatSelectorProps: any) => {
|
|
|
|
const { superChats, chatViewMode, setChatViewMode } = chatSelectorProps;
|
|
|
|
const { superChatsFiatAmount, superChatsLBCAmount } = getTipValues(superChats);
|
|
|
|
|
|
|
|
if (!superChats) {
|
|
|
|
return __('Live Chat');
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton>
|
|
|
|
<span className="swipeable-drawer__title-menu">
|
|
|
|
{chatViewMode === VIEW_MODES.CHAT ? __('Live Chat') : __('Super Chats')}
|
|
|
|
<Icon icon={ICONS.DOWN} />
|
|
|
|
</span>
|
|
|
|
</MenuButton>
|
|
|
|
|
|
|
|
<MenuList className="menu__list--header">
|
|
|
|
<MenuItem className="menu__link" onSelect={() => setChatViewMode(VIEW_MODES.CHAT)}>
|
|
|
|
{__('Live Chat')}
|
|
|
|
</MenuItem>
|
|
|
|
|
|
|
|
<MenuItem className="menu__link" onSelect={() => setChatViewMode(VIEW_MODES.SUPERCHAT)}>
|
|
|
|
<div className="recommended-content__toggles">
|
|
|
|
<CreditAmount amount={superChatsLBCAmount || 0} size={8} /> /
|
|
|
|
<CreditAmount amount={superChatsFiatAmount || 0} size={8} isFiat /> {__('Tipped')}
|
|
|
|
</div>
|
|
|
|
</MenuItem>
|
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
|
|
|
);
|
|
|
|
};
|