2020-11-04 05:15:38 +03:00
|
|
|
import React, { 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';
|
2021-02-27 00:50:20 +03:00
|
|
|
import { Layout, Menu, Popover, Alert, Typography } from 'antd';
|
2020-11-04 05:15:38 +03:00
|
|
|
|
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,
|
2020-10-23 02:18:18 +03:00
|
|
|
} from '@ant-design/icons';
|
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
|
|
|
|
|
|
|
import OwncastLogo from './logo';
|
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
|
|
|
|
2021-02-02 01:50:02 +03:00
|
|
|
import TextFieldWithSubmit from './config/form-textfield-with-submit';
|
2021-02-07 06:38:58 +03:00
|
|
|
import { TEXTFIELD_PROPS_STREAM_TITLE } from '../utils/config-constants';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
2021-02-07 06:38:58 +03:00
|
|
|
import { UpdateArgs } from '../types/config-section';
|
2020-10-23 02:18:18 +03:00
|
|
|
|
|
|
|
export default function MainLayout(props) {
|
|
|
|
const { children } = props;
|
|
|
|
|
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 || {};
|
2021-02-02 01:50:02 +03:00
|
|
|
const { instanceDetails } = serverConfig;
|
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
const [currentStreamTitle, setCurrentStreamTitle] = useState('');
|
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
|
|
|
|
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}`;
|
2020-11-04 05:15:38 +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 ? (
|
2021-02-27 00:50:20 +03:00
|
|
|
<img
|
2021-03-05 11:52:45 +03:00
|
|
|
src="/thumbnail.jpg"
|
2021-02-27 00:50:20 +03:00
|
|
|
className="online-thumbnail"
|
|
|
|
alt="current thumbnail"
|
2021-02-27 00:52:49 +03:00
|
|
|
style={{ width: '10rem' }}
|
|
|
|
/>
|
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">
|
2020-10-23 02:18:18 +03:00
|
|
|
<Menu
|
2021-02-04 20:17:20 +03:00
|
|
|
defaultSelectedKeys={[route.substring(1) || 'home']}
|
|
|
|
defaultOpenKeys={['current-stream-menu', 'utilities-menu', 'configuration']}
|
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
|
|
|
>
|
2021-02-04 20:17:20 +03:00
|
|
|
<h1 className="owncast-title">
|
|
|
|
<span className="logo-container">
|
2020-10-23 02:18:18 +03:00
|
|
|
<OwncastLogo />
|
|
|
|
</span>
|
2021-02-04 20:17:20 +03:00
|
|
|
<span className="title-label">Owncast Admin</span>
|
2020-10-23 02:18:18 +03:00
|
|
|
</h1>
|
|
|
|
<Menu.Item key="home" icon={<HomeOutlined />}>
|
2020-10-23 03:16:28 +03:00
|
|
|
<Link href="/">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">
|
2020-11-29 05:07:19 +03:00
|
|
|
<Link href="/viewer-info">Viewers</Link>
|
|
|
|
</Menu.Item>
|
2020-10-29 20:16:13 +03:00
|
|
|
|
2021-02-04 20:17:20 +03:00
|
|
|
<Menu.Item key="chat" icon={<MessageOutlined />} title="Chat utilities">
|
2020-12-27 12:20:09 +03:00
|
|
|
<Link href="/chat">Chat</Link>
|
|
|
|
</Menu.Item>
|
2021-02-02 01:50:02 +03:00
|
|
|
|
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">
|
2021-02-04 03:06:54 +03:00
|
|
|
<Link href="/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">
|
2021-02-04 03:06:54 +03:00
|
|
|
<Link href="/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">
|
2021-02-04 03:06:54 +03:00
|
|
|
<Link href="/config-video">Video Configuration</Link>
|
2020-12-31 05:07:15 +03:00
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="config-storage">
|
|
|
|
<Link href="/config-storage">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">
|
|
|
|
<Link href="/hardware-info">Hardware</Link>
|
|
|
|
</Menu.Item>
|
2020-10-30 04:01:38 +03:00
|
|
|
<Menu.Item key="logs">
|
|
|
|
<Link href="/logs">Logs</Link>
|
2020-10-23 02:18:18 +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">
|
|
|
|
<Link href="/webhooks">Webhooks</Link>
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item key="access-tokens">
|
|
|
|
<Link href="/access-tokens">Access Tokens</Link>
|
|
|
|
</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">
|
2020-12-29 17:54:05 +03:00
|
|
|
<Link href="/help">Help</Link>
|
|
|
|
</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">
|
|
|
|
<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>
|
|
|
|
|
2020-12-28 12:11:26 +03:00
|
|
|
{statusIndicatorWithThumb}
|
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>
|
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
MainLayout.propTypes = {
|
|
|
|
children: PropTypes.element.isRequired,
|
2021-02-04 20:17:20 +03:00
|
|
|
};
|