2022-09-07 10:00:28 +03:00
|
|
|
import React, { FC, ReactNode, useContext, useEffect, useState } from 'react';
|
2020-10-23 02:18:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Link from 'next/link';
|
2021-02-04 20:17:20 +03:00
|
|
|
import Head from 'next/head';
|
|
|
|
import { differenceInSeconds } from 'date-fns';
|
2020-10-23 02:18:18 +03:00
|
|
|
import { useRouter } from 'next/router';
|
2023-01-11 03:39:12 +03:00
|
|
|
import { Layout, Menu, Alert, Button, Space, Tooltip } from 'antd';
|
2022-09-10 09:23:24 +03:00
|
|
|
|
2020-10-23 03:16:28 +03:00
|
|
|
import classNames from 'classnames';
|
2023-01-16 09:31:36 +03:00
|
|
|
import dynamic from 'next/dynamic';
|
2023-01-10 07:57:29 +03:00
|
|
|
import { upgradeVersionAvailable } from '../../utils/apis';
|
|
|
|
import { parseSecondsToDurationString } from '../../utils/format';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2023-01-10 07:57:29 +03:00
|
|
|
import { OwncastLogo } from '../common/OwncastLogo/OwncastLogo';
|
|
|
|
import { ServerStatusContext } from '../../utils/server-status-context';
|
|
|
|
import { AlertMessageContext } from '../../utils/alert-message-context';
|
2021-02-04 10:24:12 +03:00
|
|
|
|
2023-01-10 07:57:29 +03:00
|
|
|
import { TextFieldWithSubmit } from './TextFieldWithSubmit';
|
|
|
|
import { TEXTFIELD_PROPS_STREAM_TITLE } from '../../utils/config-constants';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ComposeFederatedPost } from './ComposeFederatedPost';
|
2023-01-10 07:57:29 +03:00
|
|
|
import { UpdateArgs } from '../../types/config-section';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2023-01-16 09:31:36 +03:00
|
|
|
// Lazy loaded components
|
|
|
|
|
|
|
|
const SettingOutlined = dynamic(() => import('@ant-design/icons/SettingOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
}); // Lazy loaded components
|
|
|
|
|
|
|
|
const HomeOutlined = dynamic(() => import('@ant-design/icons/HomeOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const LineChartOutlined = dynamic(() => import('@ant-design/icons/LineChartOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ToolOutlined = dynamic(() => import('@ant-design/icons/ToolOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const PlayCircleFilled = dynamic(() => import('@ant-design/icons/PlayCircleFilled'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const MinusSquareFilled = dynamic(() => import('@ant-design/icons/MinusSquareFilled'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const QuestionCircleOutlined = dynamic(() => import('@ant-design/icons/QuestionCircleOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const MessageOutlined = dynamic(() => import('@ant-design/icons/MessageOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ExperimentOutlined = dynamic(() => import('@ant-design/icons/ExperimentOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const EditOutlined = dynamic(() => import('@ant-design/icons/EditOutlined'), {
|
|
|
|
ssr: false,
|
|
|
|
});
|
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export type MainLayoutProps = {
|
|
|
|
children: ReactNode;
|
|
|
|
};
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
export const MainLayout: FC<MainLayoutProps> = ({ children }) => {
|
2020-11-06 05:30:14 +03:00
|
|
|
const context = useContext(ServerStatusContext);
|
2021-02-04 20:17:20 +03:00
|
|
|
const { serverConfig, online, broadcaster, versionNumber } = context || {};
|
2022-01-13 00:52:37 +03:00
|
|
|
const { instanceDetails, chatDisabled, federation } = serverConfig;
|
|
|
|
const { enabled: federationEnabled } = federation;
|
2021-02-02 01:50:02 +03:00
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
const [currentStreamTitle, setCurrentStreamTitle] = useState('');
|
2022-01-13 00:52:37 +03:00
|
|
|
const [postModalDisplayed, setPostModalDisplayed] = useState(false);
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2021-02-04 10:24:12 +03:00
|
|
|
const alertMessage = useContext(AlertMessageContext);
|
2021-02-04 20:17:20 +03:00
|
|
|
|
2020-10-23 02:18:18 +03:00
|
|
|
const router = useRouter();
|
|
|
|
const { route } = router || {};
|
|
|
|
|
|
|
|
const { Header, Footer, Content, Sider } = Layout;
|
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
const [upgradeVersion, setUpgradeVersion] = useState('');
|
2020-11-04 05:15:38 +03:00
|
|
|
const checkForUpgrade = async () => {
|
|
|
|
try {
|
2020-11-06 05:30:14 +03:00
|
|
|
const result = await upgradeVersionAvailable(versionNumber);
|
2020-11-04 05:15:38 +03:00
|
|
|
setUpgradeVersion(result);
|
|
|
|
} catch (error) {
|
2021-02-04 20:17:20 +03:00
|
|
|
console.log('==== error', error);
|
2020-11-04 05:15:38 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-02-17 22:56:34 +03:00
|
|
|
checkForUpgrade();
|
|
|
|
}, [versionNumber]);
|
2020-11-04 05:15:38 +03:00
|
|
|
|
2021-02-02 01:50:02 +03:00
|
|
|
useEffect(() => {
|
2021-02-04 20:17:20 +03:00
|
|
|
setCurrentStreamTitle(instanceDetails.streamTitle);
|
|
|
|
}, [instanceDetails]);
|
2021-02-02 01:50:02 +03:00
|
|
|
|
|
|
|
const handleStreamTitleChanged = ({ value }: UpdateArgs) => {
|
2021-02-02 09:20:59 +03:00
|
|
|
setCurrentStreamTitle(value);
|
2021-02-04 20:17:20 +03:00
|
|
|
};
|
2021-02-02 01:50:02 +03:00
|
|
|
|
2022-01-13 00:52:37 +03:00
|
|
|
const handleCreatePostButtonPressed = () => {
|
|
|
|
setPostModalDisplayed(true);
|
|
|
|
};
|
|
|
|
|
2020-10-23 02:18:18 +03:00
|
|
|
const appClass = classNames({
|
2021-02-04 20:17:20 +03:00
|
|
|
'app-container': true,
|
|
|
|
online,
|
2020-11-06 05:30:14 +03:00
|
|
|
});
|
2020-11-04 05:15:38 +03:00
|
|
|
|
2021-02-13 10:55:59 +03:00
|
|
|
const upgradeVersionString = `${upgradeVersion}` || '';
|
|
|
|
const upgradeMessage = `Upgrade to v${upgradeVersionString}`;
|
2021-08-13 09:46:24 +03:00
|
|
|
const openMenuItems = upgradeVersion ? ['utilities-menu'] : [];
|
2021-06-22 06:19:00 +03:00
|
|
|
|
2021-02-04 10:24:12 +03:00
|
|
|
const clearAlertMessage = () => {
|
|
|
|
alertMessage.setMessage(null);
|
2021-02-04 20:17:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const headerAlertMessage = alertMessage.message ? (
|
|
|
|
<Alert message={alertMessage.message} afterClose={clearAlertMessage} banner closable />
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
// status indicator items
|
|
|
|
const streamDurationString = broadcaster
|
|
|
|
? parseSecondsToDurationString(differenceInSeconds(new Date(), new Date(broadcaster.time)))
|
|
|
|
: '';
|
2022-12-19 22:57:49 +03:00
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
const statusIcon = online ? <PlayCircleFilled /> : <MinusSquareFilled />;
|
|
|
|
const statusMessage = online ? `Online ${streamDurationString}` : 'Offline';
|
|
|
|
|
|
|
|
const statusIndicator = (
|
|
|
|
<div className="online-status-indicator">
|
|
|
|
<span className="status-label">{statusMessage}</span>
|
|
|
|
<span className="status-icon">{statusIcon}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2022-11-18 07:40:57 +03:00
|
|
|
const integrationsMenu = [
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/webhooks">Webhooks</Link>,
|
|
|
|
key: 'webhooks',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/access-tokens">Access Tokens</Link>,
|
|
|
|
key: 'access-tokens',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/actions">External Actions</Link>,
|
|
|
|
key: 'actions',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const chatMenu = [
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/chat/messages">Messages</Link>,
|
|
|
|
key: 'messages',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/chat/users">Users</Link>,
|
|
|
|
key: 'chat-users',
|
|
|
|
},
|
2022-12-12 19:40:43 +03:00
|
|
|
{
|
|
|
|
label: <Link href="/admin/chat/emojis">Emojis</Link>,
|
|
|
|
key: 'emojis',
|
|
|
|
},
|
2022-11-18 07:40:57 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
const utilitiesMenu = [
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/hardware-info">Hardware</Link>,
|
|
|
|
key: 'hardware-info',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/stream-health">Stream Health</Link>,
|
|
|
|
key: 'stream-health',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/logs">Logs</Link>,
|
|
|
|
key: 'logs',
|
|
|
|
},
|
|
|
|
federationEnabled && {
|
|
|
|
label: <Link href="/admin/federation/actions">Social Actions</Link>,
|
|
|
|
key: 'federation-activities',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const configurationMenu = [
|
|
|
|
{
|
2022-12-28 05:48:21 +03:00
|
|
|
label: <Link href="/admin/config/general">General</Link>,
|
2022-11-18 07:40:57 +03:00
|
|
|
key: 'config-public-details',
|
|
|
|
},
|
|
|
|
{
|
2022-12-28 05:48:21 +03:00
|
|
|
label: <Link href="/admin/config/server">Server Setup</Link>,
|
|
|
|
key: 'config-server',
|
2022-11-29 07:22:26 +03:00
|
|
|
},
|
2022-11-18 07:40:57 +03:00
|
|
|
{
|
|
|
|
label: <Link href="/admin/config-video">Video</Link>,
|
|
|
|
key: 'config-video',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/config-chat">Chat</Link>,
|
|
|
|
key: 'config-chat',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/config-federation">Social</Link>,
|
|
|
|
key: 'config-federation',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/config-notify">Notifications</Link>,
|
|
|
|
key: 'config-notify',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const menuItems = [
|
|
|
|
{ label: <Link href="/admin">Home</Link>, icon: <HomeOutlined />, key: 'home' },
|
|
|
|
{
|
|
|
|
label: <Link href="/admin/viewer-info">Viewers</Link>,
|
|
|
|
icon: <LineChartOutlined />,
|
|
|
|
key: 'viewer-info',
|
|
|
|
},
|
|
|
|
!chatDisabled && {
|
|
|
|
label: <Link href="/admin/viewer-info">Chat & Users</Link>,
|
|
|
|
icon: <MessageOutlined />,
|
|
|
|
children: chatMenu,
|
2022-12-17 04:44:48 +03:00
|
|
|
key: 'chat-and-users',
|
2022-11-18 07:40:57 +03:00
|
|
|
},
|
|
|
|
federationEnabled && {
|
|
|
|
key: 'fediverse-followers',
|
|
|
|
label: <Link href="/admin/federation/followers">Followers</Link>,
|
|
|
|
icon: (
|
|
|
|
<img
|
|
|
|
alt="fediverse icon"
|
2023-01-13 00:53:09 +03:00
|
|
|
src="/img/fediverse-black.png"
|
2022-12-13 04:38:43 +03:00
|
|
|
width="17rem"
|
2022-11-18 07:40:57 +03:00
|
|
|
style={{ opacity: 0.6, position: 'relative', top: '-1px' }}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'configuration',
|
|
|
|
label: 'Configuration',
|
|
|
|
icon: <SettingOutlined />,
|
|
|
|
children: configurationMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'utilities',
|
|
|
|
label: 'Utilities',
|
|
|
|
icon: <ToolOutlined />,
|
|
|
|
children: utilitiesMenu,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'integrations',
|
|
|
|
label: 'Integrations',
|
|
|
|
icon: <ExperimentOutlined />,
|
|
|
|
children: integrationsMenu,
|
|
|
|
},
|
|
|
|
upgradeVersion && {
|
|
|
|
key: 'upgrade',
|
|
|
|
label: <Link href="/upgrade">{upgradeMessage}</Link>,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'help',
|
2022-12-27 22:39:16 +03:00
|
|
|
label: <Link href="/admin/help">Help</Link>,
|
2022-11-18 07:40:57 +03:00
|
|
|
icon: <QuestionCircleOutlined />,
|
|
|
|
},
|
|
|
|
];
|
2020-10-23 02:18:18 +03:00
|
|
|
return (
|
|
|
|
<Layout className={appClass}>
|
2020-11-17 01:19:15 +03:00
|
|
|
<Head>
|
|
|
|
<title>Owncast Admin</title>
|
2021-02-02 01:50:02 +03:00
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon/favicon-32x32.png" />
|
2020-11-17 01:19:15 +03:00
|
|
|
</Head>
|
2021-02-02 01:50:02 +03:00
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<Sider width={240} className="side-nav">
|
2022-03-08 02:59:58 +03:00
|
|
|
<h1 className="owncast-title">
|
|
|
|
<span className="logo-container">
|
2022-05-12 09:31:31 +03:00
|
|
|
<OwncastLogo variant="simple" />
|
2022-03-08 02:59:58 +03:00
|
|
|
</span>
|
|
|
|
<span className="title-label">Owncast Admin</span>
|
|
|
|
</h1>
|
2020-10-23 02:18:18 +03:00
|
|
|
<Menu
|
2021-02-04 20:17:20 +03:00
|
|
|
defaultSelectedKeys={[route.substring(1) || 'home']}
|
2021-08-13 09:46:24 +03:00
|
|
|
defaultOpenKeys={openMenuItems}
|
2020-10-23 02:18:18 +03:00
|
|
|
mode="inline"
|
2021-02-13 10:55:59 +03:00
|
|
|
className="menu-container"
|
2022-11-18 07:40:57 +03:00
|
|
|
items={menuItems}
|
|
|
|
/>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Sider>
|
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<Layout className="layout-main">
|
|
|
|
<Header className="layout-header">
|
2022-01-13 00:52:37 +03:00
|
|
|
<Space direction="horizontal">
|
2022-12-19 22:57:49 +03:00
|
|
|
<Tooltip title="Compose post to your social followers">
|
2022-01-13 00:52:37 +03:00
|
|
|
<Button
|
2022-12-19 22:57:49 +03:00
|
|
|
type="link"
|
2022-01-13 00:52:37 +03:00
|
|
|
icon={<EditOutlined />}
|
2022-12-19 22:57:49 +03:00
|
|
|
size="small"
|
2022-01-13 00:52:37 +03:00
|
|
|
onClick={handleCreatePostButtonPressed}
|
2022-12-19 22:57:49 +03:00
|
|
|
style={{ display: federationEnabled ? 'block' : 'none', margin: '10px' }}
|
|
|
|
>
|
|
|
|
Compose Post
|
|
|
|
</Button>
|
2022-01-13 00:52:37 +03:00
|
|
|
</Tooltip>
|
|
|
|
</Space>
|
2021-02-04 20:17:20 +03:00
|
|
|
<div className="global-stream-title-container">
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="streamTitle"
|
|
|
|
{...TEXTFIELD_PROPS_STREAM_TITLE}
|
2022-12-19 22:57:49 +03:00
|
|
|
placeholder="What are you streaming now? (Stream title)"
|
2021-02-04 20:17:20 +03:00
|
|
|
value={currentStreamTitle}
|
|
|
|
initialValue={instanceDetails.streamTitle}
|
|
|
|
onChange={handleStreamTitleChanged}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-12-19 22:57:49 +03:00
|
|
|
<Space direction="horizontal">{statusIndicator}</Space>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Header>
|
2021-02-04 10:24:12 +03:00
|
|
|
|
|
|
|
{headerAlertMessage}
|
2020-10-29 20:16:13 +03:00
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<Content className="main-content-container">{children}</Content>
|
|
|
|
|
|
|
|
<Footer className="footer-container">
|
2021-03-04 11:53:50 +03:00
|
|
|
<a href="https://owncast.online/?source=admin" target="_blank" rel="noopener noreferrer">
|
2021-02-26 23:38:55 +03:00
|
|
|
About Owncast v{versionNumber}
|
|
|
|
</a>
|
2020-10-29 20:16:13 +03:00
|
|
|
</Footer>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Layout>
|
2022-01-13 00:52:37 +03:00
|
|
|
|
|
|
|
<ComposeFederatedPost
|
2022-11-02 00:50:23 +03:00
|
|
|
open={postModalDisplayed}
|
2022-01-13 00:52:37 +03:00
|
|
|
handleClose={() => setPostModalDisplayed(false)}
|
|
|
|
/>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Layout>
|
|
|
|
);
|
2022-09-07 10:00:28 +03:00
|
|
|
};
|
2020-10-23 02:18:18 +03:00
|
|
|
|
|
|
|
MainLayout.propTypes = {
|
|
|
|
children: PropTypes.element.isRequired,
|
2021-02-04 20:17:20 +03:00
|
|
|
};
|