Skip to content

Commit

Permalink
Update page.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailkakar authored Aug 9, 2023
1 parent dd29018 commit 1073a9f
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions examples/next-13/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { studioProvider } from 'livepeer/providers/studio';
import { cache } from 'react';

import PlayerPage from './PlayerPage';
import CountdownPage from './CountdownPage';

type SearchParams = { [key: string]: string | string[] | undefined };

Expand Down Expand Up @@ -68,23 +69,48 @@ export default async function Page({

const { loop, lowLatency, objectFit = 'contain' } = query;

const { date, time, poster } = query; // countdown

// fetch the playback info from livepeer
const playbackInfo =
!url && searchParams?.v
? await fetchPlaybackInfo(String(searchParams.v))
: null;

function parseDateTime() {
const [day, month, year] = date.split('/').map(Number);
const [hours, minutes] = time.split(':').map(Number);
return new Date(year, month - 1, day, hours, minutes);
}

function isExpired() {
const targetDateTime = parseDateTime();
const currentDateTime = new Date();

if (targetDateTime < currentDateTime) {
return true; // The target date and time have passed
} else {
return false; // The target date and time are still in the future
}
}

return (
<PlayerPage
src={!playbackInfo ? url : null}
playbackInfo={playbackInfo ? playbackInfo : null}
muted={isTrue(muted)}
autoPlay={isTrue(autoplay)}
loop={isTrue(loop)}
objectFit={objectFit === 'contain' ? 'contain' : 'cover'}
lowLatency={
isFalse(lowLatency) ? false : isForce(lowLatency) ? 'force' : true
}
/>
<>
{date && time && !isExpired() ? (
<CountdownPage poster={poster} countdown={parseDateTime()} />
) : (
<PlayerPage
src={!playbackInfo ? url : null}
playbackInfo={playbackInfo ? playbackInfo : null}
muted={isTrue(muted)}
autoPlay={isTrue(autoplay)}
loop={isTrue(loop)}
objectFit={objectFit === 'contain' ? 'contain' : 'cover'}
lowLatency={
isFalse(lowLatency) ? false : isForce(lowLatency) ? 'force' : true
}
/>
)}
</>
);
}

0 comments on commit 1073a9f

Please sign in to comment.