Skip to content

Commit

Permalink
hosuekeeping: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
lart2150 committed Nov 6, 2022
1 parent 97d56d1 commit fd14727
Show file tree
Hide file tree
Showing 12 changed files with 445 additions and 430 deletions.
10 changes: 5 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useAuth0 } from '@auth0/auth0-react';
import { lazy, Suspense, useEffect } from 'react';
import {useAuth0} from '@auth0/auth0-react';
import {lazy, Suspense, useEffect} from 'react';
import {BrowserRouter, Routes, Route} from 'react-router-dom';
import Layout from './Layout';

const Home = lazy(() => import('@/pages/Home'));
const Home = lazy(async () => import('@/pages/Home'));

const App = () : JSX.Element => {
const { loginWithRedirect, isAuthenticated, isLoading} = useAuth0();
const {loginWithRedirect, isAuthenticated, isLoading} = useAuth0();
useEffect(() => {
if (!isAuthenticated && !isLoading) {
loginWithRedirect();
}
}, [isAuthenticated, isLoading]);

if (isLoading) {
return <span>Loading....</span>
return <span>Loading....</span>;
}

return (
Expand Down
14 changes: 7 additions & 7 deletions src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {useAuth0} from '@auth0/auth0-react';
import AppBar from '@mui/material/AppBar';
import Button from '@mui/material/Button';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import {Outlet} from 'react-router-dom';
import { useAuth0 } from "@auth0/auth0-react";

const Layout = () : JSX.Element => {
const { logout } = useAuth0();
const {logout} = useAuth0();
return (
<>
<AppBar position="static">
<Toolbar>
<Typography variant="h6">
<Button
color="secondary"
onClick={() => {
logout();
}}
<Button
color="secondary"
onClick={() => {
logout();
}}
>Log Out</Button>
</Typography>
</Toolbar>
Expand Down
13 changes: 7 additions & 6 deletions src/components/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Auth0Provider } from "@auth0/auth0-react";
import { ReactNode, useContext } from "react";
import { tivoContext } from "./TivoContext";
import {Auth0Provider} from '@auth0/auth0-react';
import type {ReactNode} from 'react';
import {useContext} from 'react';
import {tivoContext} from './TivoContext';

type Props = {
children : ReactNode;
Expand All @@ -10,7 +11,7 @@ export const AuthProvider = ({children} : Props) => {
const context = useContext(tivoContext);

if (!context) {
return <>Loading config...</>
return <>Loading config...</>;
}

return <Auth0Provider
Expand All @@ -20,5 +21,5 @@ export const AuthProvider = ({children} : Props) => {
audience={context.audience}
>
{children}
</Auth0Provider>
}
</Auth0Provider>;
};
180 changes: 92 additions & 88 deletions src/components/ChannelComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,149 +1,153 @@
import Typography from '@mui/material/Typography';
import { forwardRef, ReactElement, Ref, useContext, useEffect, useState } from 'react';
import CloseIcon from '@mui/icons-material/Close';

import type { Channel } from '@/types/Tivo';
import Dialog from '@mui/material/Dialog';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import IconButton from '@mui/material/IconButton';
import Button from '@mui/material/Button';
import type { TransitionProps } from '@mui/material/transitions';
import Slide from '@mui/material/Slide';
import VideoJS from './VideoJS';
import Container from '@mui/material/Container';
import { useFetch } from '@/util/api';
import { tivoContext } from './TivoContext';
import Dialog from '@mui/material/Dialog';
import IconButton from '@mui/material/IconButton';
import Slide from '@mui/material/Slide';
import Toolbar from '@mui/material/Toolbar';
import type {TransitionProps} from '@mui/material/transitions';
import Typography from '@mui/material/Typography';
import {forwardRef, useContext, useEffect, useState} from 'react';
import type {ReactElement, Ref} from 'react';
import type videojs from 'video.js';
import {tivoContext} from './TivoContext';
import type {Channel} from '@/types/Tivo';
import {useFetch} from '@/util/api';

type Props = {
openState : boolean;
close : () => void;
channel : Channel | null;
}
};

type Stream = {
hlsSession: {
hlsSession : {
clientUuid : string;
hlsSessionId : string;
playlistUri : string;
type : string;
isLocal : boolean;
}
errorCode : string|undefined;
};
errorCode : string | undefined;

type : string;
IsFinal : boolean;
}
};

const Transition = forwardRef(function Transition(
props: TransitionProps & {
children: ReactElement;
props : TransitionProps & {
children : ReactElement;
},
ref: Ref<unknown>,
) {
return <Slide direction="up" ref={ref} {...props} />;
});
ref : Ref<unknown>,
) {
return <Slide direction="up" ref={ref} {...props}/>;
});

const ChannelComponent = ({openState, close, channel} : Props) : JSX.Element => {
const [stream, setStream] = useState<Stream|null>(null);
const [stream, setStream] = useState<Stream | null>(null);
const fetch = useFetch();
const context = useContext(tivoContext);


const clearSession = async (hlsSessionId : string) => {
return await fetch(`/stream/stop/${encodeURIComponent(hlsSessionId)}`);
}
};

const getSession = async (stbChannelId : string) => {
if (stream && stream.hlsSession?.hlsSessionId) {
clearSession(stream.hlsSession?.hlsSessionId);
if (stream && stream.hlsSession.hlsSessionId) {
clearSession(stream.hlsSession.hlsSessionId);
}
const rsp = await fetch(`/stream/startChannel/${encodeURIComponent(stbChannelId)}`)

const rsp = await fetch(`/stream/startChannel/${encodeURIComponent(stbChannelId)}`);
const strm = await rsp.json();
return strm;
}
};

const closeWindow = () => {
if (stream && stream.hlsSession?.hlsSessionId) {
clearSession(stream.hlsSession?.hlsSessionId);
if (stream && stream.hlsSession.hlsSessionId) {
clearSession(stream.hlsSession.hlsSessionId);
}

setStream(null);
close();
}
};

useEffect(() => {
if (channel?.stbChannelId) {
getSession(channel?.stbChannelId).then(async (newStream) => {
getSession(channel.stbChannelId).then(async newStream => {
await new Promise(r => setTimeout(r, 2000));
setStream(newStream);
});
}

return () => {
if (!stream || !stream.hlsSession?.hlsSessionId) {
if (!stream || !stream.hlsSession.hlsSessionId) {
console.log('skipping unmount clear');
return;
}
clearSession(stream.hlsSession?.hlsSessionId);
}

clearSession(stream.hlsSession.hlsSessionId);
};
}, [channel]);

if (!channel) {
return <></>;
}

return (
<Dialog
fullScreen
open={openState}
onClose={closeWindow}
TransitionComponent={Transition}
>
<AppBar sx={{ position: 'relative' }}>
<Toolbar>
<IconButton
edge="start"
color="inherit"
onClick={closeWindow}
aria-label="close"
>
<CloseIcon />
</IconButton>
<Typography sx={{ ml: 2, flex: 1 }} variant="h6" component="div">
{channel.affiliate}
</Typography>
</Toolbar>
</AppBar>
<Container maxWidth="lg">
{stream && stream.hlsSession?.playlistUri && (
<>
<VideoJS
options={{
controls: true,
preload: 'auto',
autoplay: true,
sources : [{
src: `${(context?.apiBaseUrl ?? '') + stream.hlsSession.playlistUri}`,
type: 'application/x-mpegURL'
}],
playbackRates: [
0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5
],
}}
/>
</>)}
{stream && stream.errorCode === undefined && (
<>
<span>{stream.errorCode}</span>
</>
)}
<Button
variant="contained"
onClick={closeWindow}
>Close</Button>

</Container>
</Dialog>
fullScreen
open={openState}
onClose={closeWindow}
TransitionComponent={Transition}
>
<AppBar sx={{position: 'relative'}}>
<Toolbar>
<IconButton
edge="start"
color="inherit"
onClick={closeWindow}
aria-label="close"
>
<CloseIcon/>
</IconButton>
<Typography sx={{ml: 2, flex: 1}} variant="h6" component="div">
{channel.affiliate}
</Typography>
</Toolbar>
</AppBar>
<Container maxWidth="lg">
{stream && stream.hlsSession.playlistUri && (
<>
<VideoJS
options={{
controls: true,
preload: 'auto',
autoplay: true,
sources: [{
src: `${(context?.apiBaseUrl ?? '') + stream.hlsSession.playlistUri}`,
type: 'application/x-mpegURL',
}],
playbackRates: [
0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5,
],
}}
/>
</>)}
{stream && stream.errorCode === undefined && (
<>
<span>{stream.errorCode}</span>
</>
)}
<Button
variant="contained"
onClick={closeWindow}
>Close</Button>

</Container>
</Dialog>
);
};


export default ChannelComponent;
export default ChannelComponent;
Loading

0 comments on commit fd14727

Please sign in to comment.