2021-03-10 19:34:21 +01:00
|
|
|
// @flow
|
2022-02-02 13:48:24 +01:00
|
|
|
import 'scss/component/_swipeable-drawer.scss';
|
|
|
|
|
2022-02-16 13:49:17 +01:00
|
|
|
// $FlowFixMe
|
|
|
|
import { Global } from '@emotion/react';
|
|
|
|
|
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>,
|
2022-02-07 14:04:25 +01:00
|
|
|
activeViewers?: number,
|
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,
|
2022-02-07 14:04:25 +01:00
|
|
|
activeViewers,
|
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 (
|
|
|
|
<>
|
2022-02-16 13:49:17 +01:00
|
|
|
{!isMobile && <GlobalStyles />}
|
|
|
|
|
2021-03-10 19:34:21 +01:00
|
|
|
<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 */}
|
2022-02-24 16:20:07 +01:00
|
|
|
<FileRenderInitiator uri={claim.canonical_url} />
|
2022-02-01 21:30:57 +01:00
|
|
|
</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-07 14:04:25 +01:00
|
|
|
activeViewers={activeViewers}
|
2022-02-02 13:48:24 +01:00
|
|
|
/>
|
|
|
|
}
|
2022-02-07 14:04:25 +01:00
|
|
|
hasSubtitle={activeViewers}
|
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-04 21:59:11 +01:00
|
|
|
setCustomViewMode={(mode) => setChatViewMode(mode)}
|
2022-02-02 13:45:16 +01:00
|
|
|
/>
|
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) => {
|
2022-02-07 14:04:25 +01:00
|
|
|
const { superChats, chatViewMode, setChatViewMode, activeViewers } = chatSelectorProps;
|
2022-02-02 13:48:24 +01:00
|
|
|
const { superChatsFiatAmount, superChatsLBCAmount } = getTipValues(superChats);
|
|
|
|
|
2022-02-07 14:04:25 +01:00
|
|
|
const titleProps = { chatViewMode, activeViewers };
|
|
|
|
|
2022-02-02 13:48:24 +01:00
|
|
|
if (!superChats) {
|
2022-02-07 14:04:25 +01:00
|
|
|
return <ChatDrawerTitle {...titleProps} />;
|
2022-02-02 13:48:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<MenuButton>
|
2022-02-07 14:04:25 +01:00
|
|
|
<div className="swipeable-drawer__menu">
|
|
|
|
<ChatDrawerTitle {...titleProps} />
|
|
|
|
|
2022-02-02 13:48:24 +01:00
|
|
|
<Icon icon={ICONS.DOWN} />
|
2022-02-07 14:04:25 +01:00
|
|
|
</div>
|
2022-02-02 13:48:24 +01:00
|
|
|
</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>
|
|
|
|
);
|
|
|
|
};
|
2022-02-07 14:04:25 +01:00
|
|
|
|
|
|
|
const ChatDrawerTitle = (titleProps: any) => {
|
|
|
|
const { chatViewMode, activeViewers } = titleProps;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="swipeable-drawer__title-menu">
|
|
|
|
<span className="swipeable-drawer__title">
|
|
|
|
{chatViewMode === VIEW_MODES.CHAT ? __('Live Chat') : __('HyperChats')}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{activeViewers && (
|
|
|
|
<span className="swipeable-drawer__subtitle">{__('%view_count% viewers', { view_count: activeViewers })}</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2022-02-16 13:49:17 +01:00
|
|
|
|
|
|
|
const GlobalStyles = () => (
|
|
|
|
<Global
|
|
|
|
styles={{
|
|
|
|
body: {
|
|
|
|
'scrollbar-width': '0px',
|
|
|
|
|
|
|
|
'&::-webkit-scrollbar': {
|
|
|
|
width: '0px',
|
|
|
|
height: '0px',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|