2022-07-08 10:10:18 +03:00
|
|
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
2023-07-10 00:07:35 +03:00
|
|
|
import { Skeleton, Row, Button, Spin } from 'antd';
|
2023-05-23 04:56:44 +03:00
|
|
|
import MessageFilled from '@ant-design/icons/MessageFilled';
|
2022-12-29 21:14:12 +03:00
|
|
|
import { FC, useEffect, useState } from 'react';
|
2022-10-04 07:06:46 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2023-02-09 05:50:58 +03:00
|
|
|
import classnames from 'classnames';
|
2023-04-27 01:31:23 +03:00
|
|
|
import ActionButtons from './ActionButtons';
|
2022-06-27 09:01:52 +03:00
|
|
|
import { LOCAL_STORAGE_KEYS, getLocalStorage, setLocalStorage } from '../../../utils/localStorage';
|
2023-05-22 00:12:14 +03:00
|
|
|
import { canPushNotificationsBeSupported } from '../../../utils/browserPushNotifications';
|
2022-06-27 09:01:52 +03:00
|
|
|
|
2022-05-04 00:17:05 +03:00
|
|
|
import {
|
|
|
|
clientConfigStateAtom,
|
2022-10-11 02:26:09 +03:00
|
|
|
currentUserAtom,
|
2023-06-26 19:00:27 +03:00
|
|
|
ChatState,
|
|
|
|
chatStateAtom,
|
2022-05-26 06:38:40 +03:00
|
|
|
appStateAtom,
|
|
|
|
isOnlineSelector,
|
2022-07-03 13:36:30 +03:00
|
|
|
isMobileAtom,
|
2022-07-13 00:10:59 +03:00
|
|
|
serverStatusState,
|
2023-05-24 02:32:35 +03:00
|
|
|
isChatAvailableSelector,
|
2023-07-17 23:48:59 +03:00
|
|
|
visibleChatMessagesSelector,
|
2022-05-04 00:17:05 +03:00
|
|
|
} from '../../stores/ClientConfigStore';
|
2022-04-28 19:54:33 +03:00
|
|
|
import { ClientConfig } from '../../../interfaces/client-config.model';
|
2022-10-28 09:20:06 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
import styles from './Content.module.scss';
|
2023-04-27 07:24:26 +03:00
|
|
|
import desktopStyles from './DesktopContent.module.scss';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { OfflineBanner } from '../OfflineBanner/OfflineBanner';
|
2022-05-26 06:38:40 +03:00
|
|
|
import { AppStateOptions } from '../../stores/application-state';
|
2022-07-13 00:10:59 +03:00
|
|
|
import { ServerStatus } from '../../../interfaces/server-status.model';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { Statusbar } from '../Statusbar/Statusbar';
|
2022-09-10 22:08:22 +03:00
|
|
|
import { ChatMessage } from '../../../interfaces/chat-message.model';
|
2022-10-22 08:24:29 +03:00
|
|
|
import { ExternalAction } from '../../../interfaces/external-action';
|
|
|
|
import { Modal } from '../Modal/Modal';
|
2023-02-13 03:55:52 +03:00
|
|
|
import { DesktopContent } from './DesktopContent';
|
|
|
|
import { MobileContent } from './MobileContent';
|
2023-05-23 04:56:44 +03:00
|
|
|
import { ChatModal } from '../../modals/ChatModal/ChatModal';
|
2023-07-10 00:07:35 +03:00
|
|
|
import { Footer } from '../Footer/Footer';
|
2022-04-29 00:36:05 +03:00
|
|
|
|
2022-10-28 09:20:06 +03:00
|
|
|
// Lazy loaded components
|
2023-07-10 00:07:35 +03:00
|
|
|
const ChatContainer = dynamic(
|
|
|
|
() => import('../../chat/ChatContainer/ChatContainer').then(mod => mod.ChatContainer),
|
|
|
|
{
|
|
|
|
ssr: false,
|
|
|
|
},
|
|
|
|
);
|
2022-10-28 09:20:06 +03:00
|
|
|
|
2023-01-10 10:58:41 +03:00
|
|
|
const FollowModal = dynamic(
|
|
|
|
() => import('../../modals/FollowModal/FollowModal').then(mod => mod.FollowModal),
|
|
|
|
{
|
|
|
|
ssr: false,
|
2023-02-10 23:28:27 +03:00
|
|
|
loading: () => <Skeleton loading active paragraph={{ rows: 8 }} />,
|
2023-01-10 10:58:41 +03:00
|
|
|
},
|
2023-01-09 11:53:28 +03:00
|
|
|
);
|
|
|
|
|
2023-01-10 10:58:41 +03:00
|
|
|
const BrowserNotifyModal = dynamic(
|
|
|
|
() =>
|
|
|
|
import('../../modals/BrowserNotifyModal/BrowserNotifyModal').then(
|
|
|
|
mod => mod.BrowserNotifyModal,
|
|
|
|
),
|
|
|
|
{
|
|
|
|
ssr: false,
|
2023-02-10 23:28:27 +03:00
|
|
|
loading: () => <Skeleton loading active paragraph={{ rows: 6 }} />,
|
2023-01-10 10:58:41 +03:00
|
|
|
},
|
2022-10-04 07:06:46 +03:00
|
|
|
);
|
|
|
|
|
2023-01-10 10:58:41 +03:00
|
|
|
const OwncastPlayer = dynamic(
|
|
|
|
() => import('../../video/OwncastPlayer/OwncastPlayer').then(mod => mod.OwncastPlayer),
|
|
|
|
{
|
|
|
|
ssr: false,
|
2023-02-01 10:26:17 +03:00
|
|
|
loading: () => <Skeleton loading active paragraph={{ rows: 12 }} />,
|
2023-01-10 10:58:41 +03:00
|
|
|
},
|
2022-10-28 09:20:06 +03:00
|
|
|
);
|
|
|
|
|
2022-10-22 08:24:29 +03:00
|
|
|
const ExternalModal = ({ externalActionToDisplay, setExternalActionToDisplay }) => {
|
2023-02-14 20:08:54 +03:00
|
|
|
const { title, description, url, html } = externalActionToDisplay;
|
2022-10-22 08:24:29 +03:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title={description || title}
|
|
|
|
url={url}
|
|
|
|
open={!!externalActionToDisplay}
|
|
|
|
height="80vh"
|
|
|
|
handleCancel={() => setExternalActionToDisplay(null)}
|
2023-02-14 20:08:54 +03:00
|
|
|
>
|
|
|
|
{html ? (
|
|
|
|
<div
|
|
|
|
// eslint-disable-next-line react/no-danger
|
|
|
|
dangerouslySetInnerHTML={{ __html: html }}
|
|
|
|
style={{
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
overflow: 'auto',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</Modal>
|
2022-10-22 08:24:29 +03:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const Content: FC = () => {
|
2022-05-26 06:38:40 +03:00
|
|
|
const appState = useRecoilValue<AppStateOptions>(appStateAtom);
|
2022-05-03 03:45:22 +03:00
|
|
|
const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom);
|
2023-06-26 19:00:27 +03:00
|
|
|
const chatState = useRecoilValue<ChatState>(chatStateAtom);
|
2022-10-11 02:26:09 +03:00
|
|
|
const currentUser = useRecoilValue(currentUserAtom);
|
2023-01-21 23:50:30 +03:00
|
|
|
const serverStatus = useRecoilValue<ServerStatus>(serverStatusState);
|
2022-07-08 10:10:18 +03:00
|
|
|
const [isMobile, setIsMobile] = useRecoilState<boolean | undefined>(isMobileAtom);
|
2023-07-17 23:48:59 +03:00
|
|
|
const messages = useRecoilValue<ChatMessage[]>(visibleChatMessagesSelector);
|
2022-05-26 06:38:40 +03:00
|
|
|
const online = useRecoilValue<boolean>(isOnlineSelector);
|
2023-05-24 02:32:35 +03:00
|
|
|
const isChatAvailable = useRecoilValue<boolean>(isChatAvailableSelector);
|
2022-10-11 02:26:09 +03:00
|
|
|
|
2022-08-17 03:49:21 +03:00
|
|
|
const { viewerCount, lastConnectTime, lastDisconnectTime, streamTitle } =
|
2022-07-13 00:10:59 +03:00
|
|
|
useRecoilValue<ServerStatus>(serverStatusState);
|
2022-08-17 03:49:21 +03:00
|
|
|
const {
|
|
|
|
extraPageContent,
|
|
|
|
name,
|
|
|
|
summary,
|
|
|
|
socialHandles,
|
|
|
|
tags,
|
|
|
|
externalActions,
|
|
|
|
offlineMessage,
|
2022-09-11 06:03:58 +03:00
|
|
|
chatDisabled,
|
2022-10-09 01:05:52 +03:00
|
|
|
federation,
|
|
|
|
notifications,
|
2022-08-17 03:49:21 +03:00
|
|
|
} = clientConfig;
|
2022-06-27 09:01:52 +03:00
|
|
|
const [showNotifyReminder, setShowNotifyReminder] = useState(false);
|
2022-10-24 07:59:25 +03:00
|
|
|
const [showNotifyModal, setShowNotifyModal] = useState(false);
|
|
|
|
const [showFollowModal, setShowFollowModal] = useState(false);
|
2022-12-30 03:26:04 +03:00
|
|
|
const { account: fediverseAccount, enabled: fediverseEnabled } = federation;
|
2022-10-09 01:05:52 +03:00
|
|
|
const { browser: browserNotifications } = notifications;
|
|
|
|
const { enabled: browserNotificationsEnabled } = browserNotifications;
|
2023-01-21 23:50:30 +03:00
|
|
|
const { online: isStreamLive } = serverStatus;
|
2022-10-22 08:24:29 +03:00
|
|
|
const [externalActionToDisplay, setExternalActionToDisplay] = useState<ExternalAction>(null);
|
2023-07-04 22:14:21 +03:00
|
|
|
const [currentBrowserWindowUrl, setCurrentBrowserWindowUrl] = useState('');
|
2022-10-22 08:24:29 +03:00
|
|
|
|
2022-12-30 03:26:04 +03:00
|
|
|
const [supportsBrowserNotifications, setSupportsBrowserNotifications] = useState(false);
|
|
|
|
const supportFediverseFeatures = fediverseEnabled;
|
|
|
|
|
2023-05-23 04:56:44 +03:00
|
|
|
const [showChatModal, setShowChatModal] = useState(false);
|
|
|
|
|
2022-10-22 08:24:29 +03:00
|
|
|
const externalActionSelected = (action: ExternalAction) => {
|
|
|
|
const { openExternally, url } = action;
|
2023-07-06 00:02:39 +03:00
|
|
|
|
2023-07-26 21:15:23 +03:00
|
|
|
if (url) {
|
|
|
|
const updatedUrl = new URL(url);
|
|
|
|
updatedUrl.searchParams.append('instance', currentBrowserWindowUrl);
|
|
|
|
|
|
|
|
if (currentUser) {
|
|
|
|
const { displayName } = currentUser;
|
|
|
|
|
|
|
|
// Append url and username to params so the link knows where we came from and who we are.
|
|
|
|
updatedUrl.searchParams.append('username', displayName);
|
|
|
|
}
|
|
|
|
const fullUrl = updatedUrl.toString();
|
|
|
|
// Overwrite URL with the updated one that includes the params.
|
|
|
|
const updatedAction = {
|
|
|
|
...action,
|
|
|
|
url: fullUrl,
|
|
|
|
};
|
|
|
|
|
|
|
|
// apply openExternally only if we don't have an HTML embed
|
|
|
|
if (openExternally) {
|
|
|
|
window.open(fullUrl, '_blank');
|
|
|
|
} else {
|
|
|
|
setExternalActionToDisplay(updatedAction);
|
|
|
|
}
|
2022-10-22 08:24:29 +03:00
|
|
|
} else {
|
2023-07-26 21:15:23 +03:00
|
|
|
setExternalActionToDisplay(action);
|
2022-10-22 08:24:29 +03:00
|
|
|
}
|
|
|
|
};
|
2022-04-28 19:54:33 +03:00
|
|
|
|
2022-06-27 09:01:52 +03:00
|
|
|
const incrementVisitCounter = () => {
|
|
|
|
let visits = parseInt(getLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount), 10);
|
|
|
|
if (Number.isNaN(visits)) {
|
|
|
|
visits = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocalStorage(LOCAL_STORAGE_KEYS.userVisitCount, visits + 1);
|
|
|
|
|
|
|
|
if (visits > 2 && !getLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal)) {
|
|
|
|
setShowNotifyReminder(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const disableNotifyReminderPopup = () => {
|
2022-10-24 07:59:25 +03:00
|
|
|
setShowNotifyModal(false);
|
2022-06-27 09:01:52 +03:00
|
|
|
setShowNotifyReminder(false);
|
|
|
|
setLocalStorage(LOCAL_STORAGE_KEYS.hasDisplayedNotificationModal, true);
|
|
|
|
};
|
|
|
|
|
2022-07-03 13:36:30 +03:00
|
|
|
const checkIfMobile = () => {
|
|
|
|
const w = window.innerWidth;
|
|
|
|
if (isMobile === undefined) {
|
|
|
|
if (w <= 768) setIsMobile(true);
|
|
|
|
else setIsMobile(false);
|
|
|
|
}
|
|
|
|
if (!isMobile && w <= 768) setIsMobile(true);
|
|
|
|
if (isMobile && w > 768) setIsMobile(false);
|
|
|
|
};
|
|
|
|
|
2022-06-27 09:01:52 +03:00
|
|
|
useEffect(() => {
|
|
|
|
incrementVisitCounter();
|
2022-07-03 13:36:30 +03:00
|
|
|
checkIfMobile();
|
|
|
|
window.addEventListener('resize', checkIfMobile);
|
2022-10-22 08:24:29 +03:00
|
|
|
return () => {
|
|
|
|
window.removeEventListener('resize', checkIfMobile);
|
|
|
|
};
|
2022-06-27 09:01:52 +03:00
|
|
|
}, []);
|
|
|
|
|
2022-12-30 03:26:04 +03:00
|
|
|
useEffect(() => {
|
|
|
|
// isPushNotificationSupported relies on `navigator` so that needs to be
|
|
|
|
// fired from this useEffect.
|
2023-05-22 00:12:14 +03:00
|
|
|
setSupportsBrowserNotifications(
|
|
|
|
canPushNotificationsBeSupported() && browserNotificationsEnabled,
|
|
|
|
);
|
2022-12-30 03:26:04 +03:00
|
|
|
}, [browserNotificationsEnabled]);
|
|
|
|
|
2023-07-04 22:14:21 +03:00
|
|
|
useEffect(() => {
|
|
|
|
setCurrentBrowserWindowUrl(window.location.href);
|
|
|
|
}, []);
|
|
|
|
|
2023-06-26 19:00:27 +03:00
|
|
|
const showChat = isChatAvailable && !chatDisabled && chatState === ChatState.VISIBLE;
|
2022-09-11 04:08:51 +03:00
|
|
|
|
2022-04-28 19:54:33 +03:00
|
|
|
return (
|
2023-07-10 00:07:35 +03:00
|
|
|
<div className={styles.main}>
|
|
|
|
<div className={styles.mainColumn}>
|
2023-04-27 01:31:23 +03:00
|
|
|
{appState.appLoading && (
|
2023-06-28 17:52:35 +03:00
|
|
|
<div
|
|
|
|
className={classnames([styles.topSectionElement, styles.centerSpinner])}
|
|
|
|
style={{ height: '30vh' }}
|
|
|
|
>
|
|
|
|
<Spin delay={2} size="large" tip="One moment..." />
|
|
|
|
</div>
|
2023-04-27 01:31:23 +03:00
|
|
|
)}
|
|
|
|
<Row>
|
2023-07-10 00:07:35 +03:00
|
|
|
{online && (
|
|
|
|
<OwncastPlayer
|
|
|
|
source="/hls/stream.m3u8"
|
|
|
|
online={online}
|
|
|
|
title={streamTitle || name}
|
|
|
|
className={styles.topSectionElement}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!online && !appState.appLoading && (
|
|
|
|
<div id="offline-message" style={{ width: '100%' }}>
|
|
|
|
<OfflineBanner
|
|
|
|
showsHeader={false}
|
|
|
|
streamName={name}
|
|
|
|
customText={offlineMessage}
|
|
|
|
notificationsEnabled={supportsBrowserNotifications}
|
|
|
|
fediverseAccount={fediverseAccount}
|
|
|
|
lastLive={lastDisconnectTime}
|
|
|
|
onNotifyClick={() => setShowNotifyModal(true)}
|
|
|
|
onFollowClick={() => setShowFollowModal(true)}
|
|
|
|
className={classnames([styles.topSectionElement, styles.offlineBanner])}
|
2023-02-09 05:50:58 +03:00
|
|
|
/>
|
2023-07-10 00:07:35 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2023-04-27 01:31:23 +03:00
|
|
|
</Row>
|
|
|
|
<Row>
|
2023-07-10 00:07:35 +03:00
|
|
|
{isStreamLive && (
|
|
|
|
<Statusbar
|
|
|
|
online={online}
|
|
|
|
lastConnectTime={lastConnectTime}
|
|
|
|
lastDisconnectTime={lastDisconnectTime}
|
|
|
|
viewerCount={viewerCount}
|
|
|
|
className={classnames(styles.topSectionElement, styles.statusBar)}
|
|
|
|
/>
|
|
|
|
)}
|
2023-04-27 01:31:23 +03:00
|
|
|
</Row>
|
|
|
|
<Row>
|
2023-07-10 00:07:35 +03:00
|
|
|
<ActionButtons
|
|
|
|
supportFediverseFeatures={supportFediverseFeatures}
|
|
|
|
supportsBrowserNotifications={supportsBrowserNotifications}
|
|
|
|
showNotifyReminder={showNotifyReminder}
|
|
|
|
setShowNotifyModal={setShowNotifyModal}
|
|
|
|
disableNotifyReminderPopup={disableNotifyReminderPopup}
|
|
|
|
externalActions={externalActions || []}
|
|
|
|
setExternalActionToDisplay={setExternalActionToDisplay}
|
|
|
|
setShowFollowModal={setShowFollowModal}
|
|
|
|
externalActionSelected={externalActionSelected}
|
|
|
|
/>
|
2023-04-27 01:31:23 +03:00
|
|
|
</Row>
|
2023-02-09 05:50:58 +03:00
|
|
|
|
2023-04-27 01:31:23 +03:00
|
|
|
<Modal
|
|
|
|
title="Browser Notifications"
|
|
|
|
open={showNotifyModal}
|
|
|
|
afterClose={() => disableNotifyReminderPopup()}
|
|
|
|
handleCancel={() => disableNotifyReminderPopup()}
|
|
|
|
>
|
|
|
|
<BrowserNotifyModal />
|
|
|
|
</Modal>
|
|
|
|
<Row>
|
2023-06-28 17:52:35 +03:00
|
|
|
{!name && <Skeleton active loading style={{ marginLeft: '10vw', marginRight: '10vw' }} />}
|
2023-02-09 05:50:58 +03:00
|
|
|
{isMobile ? (
|
2023-07-10 00:07:35 +03:00
|
|
|
<MobileContent
|
|
|
|
name={name}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
socialHandles={socialHandles}
|
|
|
|
extraPageContent={extraPageContent}
|
|
|
|
setShowFollowModal={setShowFollowModal}
|
|
|
|
supportFediverseFeatures={supportFediverseFeatures}
|
|
|
|
online={online}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className={desktopStyles.bottomSectionContent}>
|
|
|
|
<DesktopContent
|
2023-06-14 23:31:10 +03:00
|
|
|
name={name}
|
|
|
|
summary={summary}
|
|
|
|
tags={tags}
|
|
|
|
socialHandles={socialHandles}
|
|
|
|
extraPageContent={extraPageContent}
|
|
|
|
setShowFollowModal={setShowFollowModal}
|
|
|
|
supportFediverseFeatures={supportFediverseFeatures}
|
|
|
|
/>
|
2023-07-10 00:07:35 +03:00
|
|
|
</div>
|
2023-02-09 05:50:58 +03:00
|
|
|
)}
|
2023-04-27 01:31:23 +03:00
|
|
|
</Row>
|
2023-07-10 00:07:35 +03:00
|
|
|
<div style={{ flex: '1 1' }} />
|
|
|
|
<Footer />
|
|
|
|
</div>
|
|
|
|
{showChat && !isMobile && currentUser && (
|
|
|
|
<ChatContainer
|
|
|
|
messages={messages}
|
|
|
|
usernameToHighlight={currentUser.displayName}
|
|
|
|
chatUserId={currentUser.id}
|
|
|
|
isModerator={currentUser.isModerator}
|
|
|
|
chatAvailable={isChatAvailable}
|
|
|
|
showInput={!!currentUser}
|
2023-07-11 09:00:28 +03:00
|
|
|
desktop
|
2023-07-10 00:07:35 +03:00
|
|
|
/>
|
|
|
|
)}
|
2022-10-22 08:24:29 +03:00
|
|
|
{externalActionToDisplay && (
|
|
|
|
<ExternalModal
|
|
|
|
externalActionToDisplay={externalActionToDisplay}
|
|
|
|
setExternalActionToDisplay={setExternalActionToDisplay}
|
|
|
|
/>
|
|
|
|
)}
|
2022-10-24 07:59:25 +03:00
|
|
|
<Modal
|
|
|
|
title={`Follow ${name}`}
|
|
|
|
open={showFollowModal}
|
|
|
|
handleCancel={() => setShowFollowModal(false)}
|
|
|
|
width="550px"
|
|
|
|
>
|
|
|
|
<FollowModal
|
|
|
|
account={fediverseAccount}
|
|
|
|
name={name}
|
|
|
|
handleClose={() => setShowFollowModal(false)}
|
|
|
|
/>
|
|
|
|
</Modal>
|
2023-06-26 19:00:27 +03:00
|
|
|
{isMobile && showChatModal && chatState === ChatState.VISIBLE && (
|
2023-05-23 04:56:44 +03:00
|
|
|
<ChatModal
|
|
|
|
messages={messages}
|
|
|
|
currentUser={currentUser}
|
|
|
|
handleClose={() => setShowChatModal(false)}
|
|
|
|
/>
|
|
|
|
)}
|
2023-05-24 02:32:35 +03:00
|
|
|
{isMobile && isChatAvailable && (
|
2023-05-23 04:56:44 +03:00
|
|
|
<Button
|
|
|
|
id="mobile-chat-button"
|
|
|
|
type="primary"
|
|
|
|
onClick={() => setShowChatModal(true)}
|
|
|
|
className={styles.floatingMobileChatModalButton}
|
|
|
|
>
|
2023-05-24 02:32:35 +03:00
|
|
|
Chat <MessageFilled />
|
2023-05-23 04:56:44 +03:00
|
|
|
</Button>
|
|
|
|
)}
|
2023-07-10 00:07:35 +03:00
|
|
|
</div>
|
2022-04-28 19:54:33 +03:00
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|