2022-05-26 06:38:40 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { useRecoilValue } from 'recoil';
|
2023-01-01 03:08:54 +03:00
|
|
|
import { useRouter } from 'next/router';
|
2022-05-26 06:38:40 +03:00
|
|
|
import {
|
2022-05-26 08:52:27 +03:00
|
|
|
clientConfigStateAtom,
|
2022-05-26 06:38:40 +03:00
|
|
|
ClientConfigStore,
|
|
|
|
isOnlineSelector,
|
|
|
|
serverStatusState,
|
|
|
|
} from '../../../components/stores/ClientConfigStore';
|
2022-09-07 10:00:28 +03:00
|
|
|
import { OfflineBanner } from '../../../components/ui/OfflineBanner/OfflineBanner';
|
|
|
|
import { Statusbar } from '../../../components/ui/Statusbar/Statusbar';
|
|
|
|
import { OwncastPlayer } from '../../../components/video/OwncastPlayer/OwncastPlayer';
|
2022-05-26 08:52:27 +03:00
|
|
|
import { ClientConfig } from '../../../interfaces/client-config.model';
|
2022-05-26 06:38:40 +03:00
|
|
|
import { ServerStatus } from '../../../interfaces/server-status.model';
|
2022-05-17 08:55:22 +03:00
|
|
|
|
|
|
|
export default function VideoEmbed() {
|
2022-05-26 06:38:40 +03:00
|
|
|
const status = useRecoilValue<ServerStatus>(serverStatusState);
|
2022-05-26 08:52:27 +03:00
|
|
|
const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom);
|
|
|
|
|
|
|
|
const { name } = clientConfig;
|
2022-05-26 06:38:40 +03:00
|
|
|
|
2022-10-09 01:05:52 +03:00
|
|
|
const { offlineMessage } = clientConfig;
|
2022-05-26 06:38:40 +03:00
|
|
|
const { viewerCount, lastConnectTime, lastDisconnectTime } = status;
|
|
|
|
const online = useRecoilValue<boolean>(isOnlineSelector);
|
2023-01-01 03:08:54 +03:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* router.query isn't initialized until hydration
|
|
|
|
* (see https://github.com/vercel/next.js/discussions/11484)
|
|
|
|
* but router.asPath is initialized earlier, so we parse the
|
|
|
|
* query parameters ourselves
|
|
|
|
*/
|
|
|
|
const path = router.asPath.split('?')[1] ?? '';
|
|
|
|
const query = path.split('&').reduce((currQuery, part) => {
|
|
|
|
const [key, value] = part.split('=');
|
|
|
|
return { ...currQuery, [key]: value };
|
|
|
|
}, {} as Record<string, string>);
|
|
|
|
|
|
|
|
const initiallyMuted = query.initiallyMuted === 'true';
|
|
|
|
|
2022-05-17 08:55:22 +03:00
|
|
|
return (
|
2022-05-26 06:38:40 +03:00
|
|
|
<>
|
|
|
|
<ClientConfigStore />
|
|
|
|
<div className="video-embed">
|
2023-01-01 03:08:54 +03:00
|
|
|
{online && (
|
|
|
|
<OwncastPlayer
|
|
|
|
source="/hls/stream.m3u8"
|
|
|
|
online={online}
|
|
|
|
initiallyMuted={initiallyMuted}
|
|
|
|
/>
|
|
|
|
)}
|
2022-10-09 01:05:52 +03:00
|
|
|
{!online && (
|
|
|
|
<OfflineBanner
|
|
|
|
streamName={name}
|
|
|
|
customText={offlineMessage}
|
|
|
|
notificationsEnabled={false}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{online && (
|
|
|
|
<Statusbar
|
|
|
|
online={online}
|
|
|
|
lastConnectTime={lastConnectTime}
|
|
|
|
lastDisconnectTime={lastDisconnectTime}
|
|
|
|
viewerCount={viewerCount}
|
|
|
|
/>
|
|
|
|
)}
|
2022-05-26 06:38:40 +03:00
|
|
|
</div>
|
|
|
|
</>
|
2022-05-17 08:55:22 +03:00
|
|
|
);
|
|
|
|
}
|