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';
|
2022-01-13 00:52:37 +03:00
|
|
|
import { Layout, Menu, Popover, Alert, Typography, Button, Space, Tooltip } from 'antd';
|
2020-10-23 02:18:18 +03:00
|
|
|
import {
|
|
|
|
SettingOutlined,
|
|
|
|
HomeOutlined,
|
|
|
|
LineChartOutlined,
|
2020-11-17 01:36:06 +03:00
|
|
|
ToolOutlined,
|
2020-10-23 02:18:18 +03:00
|
|
|
PlayCircleFilled,
|
2020-10-23 03:16:28 +03:00
|
|
|
MinusSquareFilled,
|
2020-12-30 16:47:19 +03:00
|
|
|
QuestionCircleOutlined,
|
2021-01-14 03:28:05 +03:00
|
|
|
MessageOutlined,
|
|
|
|
ExperimentOutlined,
|
2022-01-13 00:52:37 +03:00
|
|
|
EditOutlined,
|
2020-10-23 02:18:18 +03:00
|
|
|
} from '@ant-design/icons';
|
2022-09-10 09:23:24 +03:00
|
|
|
|
2020-10-23 03:16:28 +03:00
|
|
|
import classNames from 'classnames';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { upgradeVersionAvailable } from '../utils/apis';
|
|
|
|
import { parseSecondsToDurationString } from '../utils/format';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
import { OwncastLogo } from './common/OwncastLogo/OwncastLogo';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { ServerStatusContext } from '../utils/server-status-context';
|
|
|
|
import { AlertMessageContext } from '../utils/alert-message-context';
|
2021-02-04 10:24:12 +03:00
|
|
|
|
2022-09-07 10:00:28 +03:00
|
|
|
import { TextFieldWithSubmit } from './config/TextFieldWithSubmit';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { TEXTFIELD_PROPS_STREAM_TITLE } from '../utils/config-constants';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { ComposeFederatedPost } from './ComposeFederatedPost';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { UpdateArgs } from '../types/config-section';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
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;
|
|
|
|
const { SubMenu } = Menu;
|
|
|
|
|
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
|
|
|
|
|
|
|
const upgradeMenuItemStyle = upgradeVersion ? 'block' : 'none';
|
2021-02-13 10:55:59 +03:00
|
|
|
const upgradeVersionString = `${upgradeVersion}` || '';
|
|
|
|
const upgradeMessage = `Upgrade to v${upgradeVersionString}`;
|
2021-07-20 08:02:02 +03:00
|
|
|
const chatMenuItemStyle = chatDisabled ? 'none' : 'block';
|
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)))
|
|
|
|
: '';
|
|
|
|
const currentThumbnail = online ? (
|
2022-01-13 00:52:37 +03:00
|
|
|
<img src="/thumbnail.jpg" className="online-thumbnail" alt="current thumbnail" width="1rem" />
|
2021-02-04 20:17:20 +03:00
|
|
|
) : null;
|
|
|
|
const statusIcon = online ? <PlayCircleFilled /> : <MinusSquareFilled />;
|
|
|
|
const statusMessage = online ? `Online ${streamDurationString}` : 'Offline';
|
2021-02-27 00:50:20 +03:00
|
|
|
const popoverTitle = <Typography.Text>Thumbnail</Typography.Text>;
|
2021-02-04 20:17:20 +03:00
|
|
|
|
|
|
|
const statusIndicator = (
|
|
|
|
<div className="online-status-indicator">
|
|
|
|
<span className="status-label">{statusMessage}</span>
|
|
|
|
<span className="status-icon">{statusIcon}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
const statusIndicatorWithThumb = online ? (
|
2021-02-27 00:50:20 +03:00
|
|
|
<Popover content={currentThumbnail} title={popoverTitle} trigger="hover">
|
2021-02-04 20:17:20 +03:00
|
|
|
{statusIndicator}
|
|
|
|
</Popover>
|
|
|
|
) : (
|
|
|
|
statusIndicator
|
|
|
|
);
|
|
|
|
|
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"
|
2020-10-23 02:18:18 +03:00
|
|
|
>
|
|
|
|
<Menu.Item key="home" icon={<HomeOutlined />}>
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin">Home</Link>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Menu.Item>
|
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<Menu.Item key="viewer-info" icon={<LineChartOutlined />} title="Current stream">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/viewer-info">Viewers</Link>
|
2020-11-29 05:07:19 +03:00
|
|
|
</Menu.Item>
|
2020-10-29 20:16:13 +03:00
|
|
|
|
2021-06-22 06:19:00 +03:00
|
|
|
<SubMenu
|
|
|
|
key="chat-config"
|
2021-07-20 08:02:02 +03:00
|
|
|
title="Chat & Users"
|
2021-06-22 06:19:00 +03:00
|
|
|
icon={<MessageOutlined />}
|
|
|
|
style={{ display: chatMenuItemStyle }}
|
|
|
|
>
|
2021-07-20 08:02:02 +03:00
|
|
|
<Menu.Item key="messages" title="Chat utilities">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/chat/messages">Messages</Link>
|
2021-06-22 06:19:00 +03:00
|
|
|
</Menu.Item>
|
|
|
|
|
2021-07-20 08:02:02 +03:00
|
|
|
<Menu.Item key="chat-users" title="Chat utilities">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/chat/users">Users</Link>
|
2021-06-22 06:19:00 +03:00
|
|
|
</Menu.Item>
|
|
|
|
</SubMenu>
|
2021-02-02 01:50:02 +03:00
|
|
|
|
2022-01-13 00:52:37 +03:00
|
|
|
<Menu.Item
|
|
|
|
style={{ display: federationEnabled ? 'block' : 'none' }}
|
|
|
|
key="federation-followers"
|
|
|
|
title="Fediverse followers"
|
|
|
|
icon={
|
|
|
|
<img
|
|
|
|
alt="fediverse icon"
|
|
|
|
src="/admin/fediverse-white.png"
|
|
|
|
width="15rem"
|
|
|
|
style={{ opacity: 0.6, position: 'relative', top: '-1px' }}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/federation/followers">Followers</Link>
|
2022-01-13 00:52:37 +03:00
|
|
|
</Menu.Item>
|
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<SubMenu key="configuration" title="Configuration" icon={<SettingOutlined />}>
|
2020-12-31 05:07:15 +03:00
|
|
|
<Menu.Item key="config-public-details">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-public-details">General</Link>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Menu.Item>
|
2021-02-02 01:50:02 +03:00
|
|
|
|
2020-12-31 05:07:15 +03:00
|
|
|
<Menu.Item key="config-server-details">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-server-details">Server Setup</Link>
|
2020-10-29 20:16:13 +03:00
|
|
|
</Menu.Item>
|
2020-12-31 05:07:15 +03:00
|
|
|
<Menu.Item key="config-video">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-video">Video</Link>
|
2020-12-31 05:07:15 +03:00
|
|
|
</Menu.Item>
|
2021-06-22 06:19:00 +03:00
|
|
|
<Menu.Item key="config-chat">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-chat">Chat</Link>
|
2021-06-22 06:19:00 +03:00
|
|
|
</Menu.Item>
|
2022-03-08 01:41:30 +03:00
|
|
|
<Menu.Item key="config-federation">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-federation">Social</Link>
|
2022-01-13 00:52:37 +03:00
|
|
|
</Menu.Item>
|
2022-03-23 18:57:09 +03:00
|
|
|
<Menu.Item key="config-notify">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-notify">Notifications</Link>
|
2022-03-23 18:57:09 +03:00
|
|
|
</Menu.Item>
|
2022-01-13 00:52:37 +03:00
|
|
|
|
2020-12-31 05:07:15 +03:00
|
|
|
<Menu.Item key="config-storage">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/config-storage">S3 Storage</Link>
|
2020-10-29 20:16:13 +03:00
|
|
|
</Menu.Item>
|
2020-11-01 05:29:06 +03:00
|
|
|
</SubMenu>
|
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<SubMenu key="utilities-menu" icon={<ToolOutlined />} title="Utilities">
|
2020-11-01 05:29:06 +03:00
|
|
|
<Menu.Item key="hardware-info">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/hardware-info">Hardware</Link>
|
2020-11-01 05:29:06 +03:00
|
|
|
</Menu.Item>
|
2022-03-17 03:54:34 +03:00
|
|
|
<Menu.Item key="stream-health">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/stream-health">Stream Health</Link>
|
2022-03-17 03:54:34 +03:00
|
|
|
</Menu.Item>
|
2020-10-30 04:01:38 +03:00
|
|
|
<Menu.Item key="logs">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/logs">Logs</Link>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Menu.Item>
|
2022-03-07 04:24:01 +03:00
|
|
|
<Menu.Item
|
|
|
|
key="federation-activities"
|
|
|
|
title="Social Actions"
|
|
|
|
style={{ display: federationEnabled ? 'block' : 'none' }}
|
|
|
|
>
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/federation/actions">Social Actions</Link>
|
2022-01-13 00:52:37 +03:00
|
|
|
</Menu.Item>
|
2020-11-04 05:15:38 +03:00
|
|
|
<Menu.Item key="upgrade" style={{ display: upgradeMenuItemStyle }}>
|
2021-02-13 10:55:59 +03:00
|
|
|
<Link href="/upgrade">{upgradeMessage}</Link>
|
2020-11-03 05:40:12 +03:00
|
|
|
</Menu.Item>
|
2021-01-14 03:28:05 +03:00
|
|
|
</SubMenu>
|
2021-02-04 20:17:20 +03:00
|
|
|
<SubMenu key="integrations-menu" icon={<ExperimentOutlined />} title="Integrations">
|
2021-01-14 03:28:05 +03:00
|
|
|
<Menu.Item key="webhooks">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/webhooks">Webhooks</Link>
|
2021-01-14 03:28:05 +03:00
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="access-tokens">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/access-tokens">Access Tokens</Link>
|
2021-01-14 03:28:05 +03:00
|
|
|
</Menu.Item>
|
2021-03-16 01:27:19 +03:00
|
|
|
<Menu.Item key="actions">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/actions">External Actions</Link>
|
2021-03-16 01:27:19 +03:00
|
|
|
</Menu.Item>
|
2020-10-23 02:18:18 +03:00
|
|
|
</SubMenu>
|
2021-02-04 20:17:20 +03:00
|
|
|
<Menu.Item key="help" icon={<QuestionCircleOutlined />} title="Help">
|
2022-04-20 05:57:27 +03:00
|
|
|
<Link href="/admin/help">Help</Link>
|
2020-12-29 17:54:05 +03:00
|
|
|
</Menu.Item>
|
2020-10-23 02:18:18 +03:00
|
|
|
</Menu>
|
|
|
|
</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">
|
|
|
|
<Tooltip title="Compose post to your followers">
|
|
|
|
<Button
|
|
|
|
type="primary"
|
|
|
|
shape="circle"
|
|
|
|
icon={<EditOutlined />}
|
|
|
|
size="large"
|
|
|
|
onClick={handleCreatePostButtonPressed}
|
|
|
|
style={{ display: federationEnabled ? 'block' : 'none' }}
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
</Space>
|
2021-02-04 20:17:20 +03:00
|
|
|
<div className="global-stream-title-container">
|
|
|
|
<TextFieldWithSubmit
|
|
|
|
fieldName="streamTitle"
|
|
|
|
{...TEXTFIELD_PROPS_STREAM_TITLE}
|
2021-02-15 09:20:25 +03:00
|
|
|
placeholder="What are you streaming now"
|
2021-02-04 20:17:20 +03:00
|
|
|
value={currentStreamTitle}
|
|
|
|
initialValue={instanceDetails.streamTitle}
|
|
|
|
onChange={handleStreamTitleChanged}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-01-13 00:52:37 +03:00
|
|
|
<Space direction="horizontal">{statusIndicatorWithThumb}</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
|
|
|
|
visible={postModalDisplayed}
|
|
|
|
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
|
|
|
};
|