Unverified Commit 12408a3f authored by Yohann MARTZOLFF's avatar Yohann MARTZOLFF Committed by GitHub

chore(examples): update with-apivideo (#39727)

Co-authored-by: 's avatarThibault Beyou <37510686+ThibaultBee@users.noreply.github.com>
parent 2cafe367
import Image from 'next/image'
import React from 'react'
import styled, { keyframes } from 'styled-components'
interface ILoaderProps {
done: boolean
}
const spin = keyframes`
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
`
const Spinner = styled.div`
border: 3px solid #f3f3f3;
border-top: 3px solid rgb(235, 137, 82);
border-radius: 50%;
width: 25px;
height: 25px;
animation: ${spin} 1s linear infinite;
`
const Loader: React.FC<ILoaderProps> = ({ done }): JSX.Element =>
done ? <Image src="/check.png" width={30} height={30} /> : <Spinner />
export default Loader
import styled from 'styled-components'
export const GlobalContainer = styled.div`
box-sizing: border-box;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
gap: 20px;
main {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
`
export const Header = styled.header`
font-size: 2.5rem;
margin-top: 2rem;
span {
font-weight: 700;
background: -webkit-linear-gradient(
45deg,
rgb(250, 91, 48) 0%,
rgb(128, 54, 255) 26.88%,
rgb(213, 63, 255) 50.44%,
rgb(235, 137, 82) 73.83%,
rgb(247, 181, 0) 100%
);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
`
export const TextsContainer = styled.div`
display: flex;
flex-direction: column;
gap: 20px;
padding: 3rem 5rem;
box-shadow: rgb(0 0 0 / 10%) 0px 2px 4px;
border-radius: 5px;
`
export const Text = styled.p`
text-align: center;
font-size: 1.1rem;
letter-spacing: 0.03rem;
a {
font-weight: 700;
}
`
export const Button = styled.button<{ $upload?: boolean }>`
background: ${(p) =>
p.$upload
? '-webkit-linear-gradient(45deg, rgb(250, 91, 48) 0%, rgb(235, 137, 82) 50%, rgb(247, 181, 0) 100%)'
: '-webkit-linear-gradient(45deg, rgb(247, 181, 0) 0%, rgb(235, 137, 82) 50%, rgb(250, 91, 48) 100%)'};
border: none;
padding: 0.8rem 1.2rem;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
font-size: 1.2rem;
font-weight: 500;
`
export const StatusContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
gap: 2rem;
span {
width: 35px;
height: 5px;
border-radius: 5px;
background-color: rgb(235, 137, 82);
margin-top: 20px;
}
`
export const Footer = styled.footer`
margin-top: auto;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 5px;
a:nth-of-type(2) {
font-weight: 600;
font-size: 1.1rem;
}
`
export const PlayerSdkContainer = styled.div<{
$width: number
$height: number
}>`
width: ${(p) => (p.$width && p.$width <= 800 ? p.$width : '800')}px;
height: ${(p) => (p.$height && p.$height <= 250 ? p.$height : '250')}px;
iframe {
height: ${(p) => (p.$height <= 250 ? p.$height : '250')}px !important;
}
`
export const InputsContainer = styled.div`
display: flex;
gap: 20px;
> div {
display: flex;
flex-direction: column;
gap: 5px;
label {
font-size: 0.6rem;
}
}
> div:last-child {
flex-direction: row;
align-items: center;
align-self: flex-end;
}
`
* {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
vertical-align: baseline;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
text-decoration: none;
color: unset;
}
......@@ -4,28 +4,28 @@ This video uploader and playback app is built with Next.js and api.video, the vi
## Demo
[https://apivideo-uploader.vercel.app/](https://apivideo-uploader.vercel.app/)
[https://with-apivideo.vercel.app/videos](https://with-apivideo.vercel.app/videos)
## Deploy your own
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-apivideo-upload&project-name=with-apivideo-upload&repository-name=with-apivideo-upload)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/with-apivideo&project-name=with-apivideo&repository-name=with-apivideo)
## How to use
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:
```bash
npx create-next-app --example with-apivideo-upload with-apivideo-upload-app
npx create-next-app --example with-apivideo-app
```
```bash
yarn create next-app --example with-apivideo-upload with-apivideo-upload-app
yarn create next-app --example with-apivideo-app
```
```bash
pnpm create next-app --example with-apivideo-upload with-apivideo-upload-app
pnpm create next-app --example with-apivideo-app
```
Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
......@@ -34,19 +34,20 @@ Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&ut
### 1. Create an api.video free account
Go to [dashboard.api.video](https://dashboard.api.video/), log in or create a free account.
You can choose to stay in sandbox and have watermark over your videos, or enter in [production mode](https://api.video/pricing) and take advantage of all the features without limitations.
1. Go to [dashboard.api.video](https://dashboard.api.video/), log in or create a free account.
2. You can choose to stay in sandbox and have watermark over your videos, or enter in [production mode](https://api.video/pricing) and take advantage of all the features without limitations.
### 2. Get you API key
Once in the dashboard, find your API keys directly in the `/overview` or navigate to `/apikeys` with the "API Keys" button in the side navigation.
Copy your API key, and paste it in `.env.local.example` as value for `API_KEY`.
Rename `.env.local.example` to `.env.local`.
You can now try the application locally by running `npm run dev`, `yarn dev` or `pnpm dev` from the root directory.
1. Once in the dashboard, find your API keys directly in the `/overview` or navigate to `/apikeys` with the "API Keys" button in the side navigation.
2. Copy your API key, and paste it in `.env.local.example` as value for `API_KEY`.
3. Rename `.env.local.example` to `.env.local`.
4. Install the packages by running `npm install`, `yarn install` or `pnpm install`.
5. You can now try the application locally by running `npm run dev`, `yarn dev` or `pnpm dev` from the root directory.
### 3. Deployment
First, push your app to GitHub/GitLab or Bitbucket
The, go to [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) and import your new repository.
Add an environment variable with name `API_KEY` and your API key for value.
Click on deploy 🎉
1. First, push your app to GitHub/GitLab or Bitbucket
2. Then, go to [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) and import your new repository.
3. Add an environment variable with name `API_KEY` and your API key for value.
4. Click on deploy 🎉
import React from 'react'
import styled from 'styled-components'
import Image from 'next/image'
interface ICardProps {
content: string
url: string
method: 'get' | 'post'
}
const Container = styled.a`
.container {
border: 1px solid rgb(215, 219, 236);
border-radius: 0.25rem;
background-color: #ffffff;
......@@ -20,42 +10,39 @@ const Container = styled.a`
font-size: 0.5rem;
position: relative;
box-shadow: rgb(0 0 0 / 5%) 0px 2px 4px;
`
}
.container > p {
letter-spacing: 0.05rem;
}
const Method = styled.div<{ $method: 'get' | 'post' }>`
.method {
color: #ffffff;
background-color: ${(p) => (p.$method === 'get' ? 'green' : 'blue')};
padding: 0.3rem;
border-radius: 2px;
font-weight: 500;
`
const Content = styled.p`
letter-spacing: 0.05rem;
`
}
.get {
composes: method;
background-color: green;
}
.post {
composes: method;
background-color: blue;
}
const ImageContainer = styled.div`
.image_container {
position: absolute;
bottom: -25px;
right: -105px;
display: flex;
gap: 5px;
align-items: flex-end;
p {
margin-bottom: -3px;
font-size: 0.5rem;
}
`
const Card: React.FC<ICardProps> = ({ content, url, method }): JSX.Element => (
<Container target="_blank" href={url}>
<Method $method={method}>{method.toUpperCase()}</Method>
<Content>{content}</Content>
<ImageContainer>
<Image src="/arrow.png" alt="Sketch arrow" width={20} height={20} />
<p>Try it out with our API!</p>
</ImageContainer>
</Container>
)
}
.image_container > p {
margin-bottom: -3px;
font-size: 0.5rem;
}
export default Card
#foo {
font-size: large;
}
import React from 'react'
import Image from 'next/image'
import styles from './Card.module.css'
interface ICardProps {
content: string
url: string
method: 'get' | 'post'
}
const Card: React.FC<ICardProps> = ({ content, url, method }): JSX.Element => (
<a className={styles.container} target="_blank" href={url} rel="noreferrer">
<div className={`${method === 'get' ? styles.get : styles.post}`}>
{method.toUpperCase()}
</div>
<p>{content}</p>
<div className={styles.image_container}>
<Image src="/arrow.png" alt="Sketch arrow" width={20} height={20} />
<p>Try it out with our API!</p>
</div>
</a>
)
export default Card
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid rgb(235, 137, 82);
border-radius: 50%;
width: 25px;
height: 25px;
animation: spin 1s linear infinite;
}
import Image from 'next/image'
import React from 'react'
import styles from './Loader.module.css'
interface ILoaderProps {
done: boolean
}
const Loader: React.FC<ILoaderProps> = ({ done }): JSX.Element =>
done ? (
<Image src="/check.png" width={30} height={30} />
) : (
<div className={styles.spinner} />
)
export default Loader
.container {
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
}
import React from 'react'
import styled from 'styled-components'
import Loader from '../Loader'
import styles from './Status.module.css'
interface IStatusProps {
done: boolean
title: string
}
const Container = styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
`
const Status: React.FC<IStatusProps> = ({ done, title }): JSX.Element => (
<Container>
<div className={styles.container}>
<p>{title}</p>
<Loader done={done} />
</Container>
</div>
)
export default Status
......@@ -4,6 +4,9 @@ const nextConfig = {
compiler: {
styledComponents: true,
},
images: {
domains: ['cdn.api.video'],
},
}
module.exports = nextConfig
......@@ -7,19 +7,17 @@
},
"dependencies": {
"@api.video/nodejs-client": "2.2.5",
"@api.video/player-sdk": "1.2.13",
"@api.video/react-player": "^1.0.1",
"@api.video/video-uploader": "1.0.4",
"@types/styled-components": "5.1.24",
"next": "latest",
"react": "18.1.0",
"react-dom": "18.1.0",
"styled-components": "5.3.5",
"swr": "1.2.2"
"react-dom": "18.1.0"
},
"devDependencies": {
"@types/node": "17.0.23",
"@types/react": "17.0.43",
"@types/react-dom": "17.0.14",
"eslint-config-next": "latest",
"typescript": "4.6.3"
}
}
import '../style/index.css'
import '../style/common.css'
function MyApp({ Component, pageProps }: any) {
return <Component {...pageProps} />
......
import type { NextApiRequest, NextApiResponse } from 'next'
import ApiVideoClient from '@api.video/nodejs-client'
const getVideoStatus = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const client = new ApiVideoClient({ apiKey: process.env.API_KEY })
const videos = await client.videos.list()
res.status(200).json({ videos })
} catch (error) {
res.status(400).end()
}
}
export default getVideoStatus
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import React from 'react'
const Home: NextPage = () => (
<div className="global-container">
<Head>
<title>api.video sample app</title>
<meta
name="description"
content="Generated by create next app & created by api.video"
/>
<link rel="icon" href="/favicon.ico" />
</Head>
<header>
<span>api.video sample app</span>
</header>
<main>
<div className="texts-container">
<p>
Hey fellow dev! 👋 <br />
In this basic sample app, you will find{' '}
<a href="https://api.video" target="_blank" rel="noopener noreferrer">
api.video
</a>{' '}
features examples such as <a href="/uploader">video uploader</a>,{' '}
<a href="/videos">videos list</a> and player components.
</p>
<p>
api.video provides APIs and clients to handle all your video needs.
<br />
This app is built with the api.video{' '}
<a
href="https://github.com/apivideo/api.video-nodejs-client"
target="_blank"
rel="noopener noreferrer"
>
Node.js client
</a>
,{' '}
<a
href="https://github.com/apivideo/api.video-typescript-uploader"
target="_blank"
rel="noopener noreferrer"
>
Typescript uploader
</a>{' '}
and{' '}
<a
target="_blank"
rel="noopener noreferrer"
href="https://github.com/apivideo/api.video-react-player"
>
React player component
</a>
.
</p>
<p>
You can{' '}
<a
href="https://github.com/vercel/next.js/tree/canary/examples/with-apivideo"
target="_blank"
rel="noopener noreferrer"
>
check the source code on GitHub
</a>
.
</p>
<p>Please, choose a feature to explore.</p>
</div>
<div className="status-container">
<a className="button" href="/uploader">
Upload a video
</a>
<a className="button" href="/videos">
See my videos
</a>
</div>
</main>
<footer>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
<span>and</span>
<a href="https://api.video" target="_blank" rel="noopener noreferrer">
api.video
</a>
</footer>
</div>
)
export default Home
......@@ -2,26 +2,15 @@ import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import React, { ChangeEvent, useEffect, useRef, useState } from 'react'
import Card from '../components/Card'
import Card from '../../components/Card'
import { VideoUploader, VideoUploadResponse } from '@api.video/video-uploader'
import Status from '../components/Status'
import Status from '../../components/Status'
import { useRouter } from 'next/router'
import {
Button,
Footer,
GlobalContainer,
Header,
StatusContainer,
Text,
TextsContainer,
} from '../style/common'
import useSWR from 'swr'
const fetcher = async (url: string): Promise<any> => {
return fetch(url).then((res) => res.json())
}
const Home: NextPage = () => {
const Uploader: NextPage = () => {
const [uploadToken, setUploadToken] = useState<{ token: string } | undefined>(
undefined
)
const [uploadProgress, setUploadProgress] = useState<number | undefined>(
undefined
)
......@@ -31,47 +20,33 @@ const Home: NextPage = () => {
{ ingested: false, encoded: false }
)
const [interId, setInterId] = useState<number | undefined>(undefined)
const [size, setSize] = useState<
{ width: number; height: number } | undefined
>(undefined)
const inputRef = useRef<HTMLInputElement>(null)
const router = useRouter()
const { data: uploadToken } = useSWR<{ token: string }>(
'/api/uploadToken',
fetcher
)
const fetchVideoStatus = async (videoId: string): Promise<void> => {
const { status } = await fetcher(`/api/${videoId}`)
const { encoding, ingest } = status
setStatus({
ingested: ingest.status === 'uploaded',
encoded: encoding.playable,
})
if (ingest.status === 'uploaded' && encoding.playable) {
setSize({
width: encoding.metadata.width,
height: encoding.metadata.height,
})
setReady(true)
}
}
const clearState = (): void => {
setReady(false)
setStatus({ ingested: false, encoded: false })
setVideo(undefined)
setUploadProgress(undefined)
setSize(undefined)
}
useEffect(() => {
fetch('/api/uploadToken')
.then((res) => res.json())
.then((res) => setUploadToken(res))
}, [])
useEffect(() => {
if (video) {
const fetchVideoStatus = async (videoId: string): Promise<void> => {
const { status } = await fetch(`/api/${videoId}`).then((res) =>
res.json()
)
const { encoding, ingest } = status
setStatus({
ingested: ingest.status === 'uploaded',
encoded: encoding.playable,
})
if (ingest.status === 'uploaded' && encoding.playable) setReady(true)
}
const intervalId = window.setInterval(() => {
fetchVideoStatus(video.videoId)
}, 1000)
setInterId(intervalId)
return () => window.clearInterval(intervalId)
}
}, [video, ready])
useEffect(() => {
......@@ -82,6 +57,13 @@ const Home: NextPage = () => {
e: ChangeEvent<HTMLInputElement>
): Promise<void> => {
e.preventDefault()
if (!uploadToken || !uploadToken.token) return
const clearState = (): void => {
setReady(false)
setStatus({ ingested: false, encoded: false })
setVideo(undefined)
setUploadProgress(undefined)
}
clearState()
if (!e.target.files || !uploadToken) return
const file = e.target.files[0]
......@@ -98,11 +80,11 @@ const Home: NextPage = () => {
const handleNavigate = (): void => {
if (!video) return
router.push(`/${video.videoId}?w=${size?.width}&h=${size?.height}`)
router.push(`/videos/${video.videoId}?uploaded=1`)
}
return (
<GlobalContainer>
<div className="global-container">
<Head>
<title>Video Uploader</title>
<meta
......@@ -112,13 +94,13 @@ const Home: NextPage = () => {
<link rel="icon" href="/favicon.ico" />
</Head>
<Header>
<header>
<span>api.video uploader</span> 🚀
</Header>
</header>
<main>
<TextsContainer>
<Text>
<div className="texts-container">
<p>
Hey fellow dev! 👋 <br />
Welcome to this basic example of video uploader provided by{' '}
<a
......@@ -137,8 +119,8 @@ const Home: NextPage = () => {
Vercel & Next.js
</a>
.
</Text>
<Text>
</p>
<p>
api.video provides APIs and clients to handle all your video needs.
<br />
This app is built with the{' '}
......@@ -158,8 +140,8 @@ const Home: NextPage = () => {
Typescript uploader
</a>
.
</Text>
<Text>
</p>
<p>
You can{' '}
<a
href="https://github.com/vercel/next.js/tree/canary/examples/with-apivideo-upload"
......@@ -169,18 +151,21 @@ const Home: NextPage = () => {
check the source code on GitHub
</a>
.
</Text>
<Text>
</p>
<p>
Please add a video to upload and let the power of the API do the
rest 🎩
</Text>
</TextsContainer>
</p>
</div>
{!uploadProgress ? (
<>
<Button $upload onClick={() => inputRef.current?.click()}>
<button
className="upload"
onClick={() => inputRef.current?.click()}
>
Select a file
</Button>
</button>
<input
ref={inputRef}
hidden
......@@ -191,13 +176,13 @@ const Home: NextPage = () => {
</>
) : (
<>
<StatusContainer>
<div className="status-container">
<Status title="Uploaded" done={uploadProgress >= 100} />
<span />
<Status title="Ingested" done={status.ingested} />
<span />
<Status title="Playable" done={status.encoded} />
</StatusContainer>
</div>
<Card
content="https://ws.api.video/videos/{videoId}/source"
url="https://docs.api.video/reference/post_videos-videoid-source"
......@@ -207,11 +192,13 @@ const Home: NextPage = () => {
)}
{ready && video && (
<Button onClick={handleNavigate}>Watch it 🍿</Button>
<button className="upload" onClick={handleNavigate}>
Watch it 🍿
</button>
)}
</main>
<Footer>
<footer>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
......@@ -226,9 +213,9 @@ const Home: NextPage = () => {
<a href="https://api.video" target="_blank" rel="noopener noreferrer">
api.video
</a>
</Footer>
</GlobalContainer>
</footer>
</div>
)
}
export default Home
export default Uploader
import { PlayerSdk, PlayerTheme } from '@api.video/player-sdk'
import { GetServerSideProps, NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import { useRouter } from 'next/router'
import React, { ChangeEvent, useEffect, useState } from 'react'
import {
Button,
Footer,
GlobalContainer,
Header,
InputsContainer,
PlayerSdkContainer,
Text,
TextsContainer,
} from '../style/common'
import React, { ChangeEvent, useState } from 'react'
import ApiVideoPlayer, { PlayerTheme } from '@api.video/react-player'
interface IVideoViewProps {
children: React.ReactNode
videoId: string
width: string
height: string
uploaded: string
}
const VideoView: NextPage<IVideoViewProps> = ({
videoId,
width,
height,
uploaded,
}): JSX.Element => {
const [player, setPlayer] = useState<PlayerSdk | undefined>(undefined)
const [playerSettings, setPlayerSettings] = useState<PlayerTheme>({
const [playerTheme, setPlayerTheme] = useState<PlayerTheme>({
link: 'rgb(235, 137, 82)',
linkHover: 'rgb(240, 95, 12)',
})
const [hideControls, setHideControls] = useState<boolean>(false)
const router = useRouter()
useEffect(() => {
const player = new PlayerSdk('#player', {
id: videoId,
const handleChangeSetting = (e: ChangeEvent<HTMLInputElement>) =>
setPlayerTheme({
...playerTheme,
[e.currentTarget.id]: e.currentTarget.value,
})
player.setTheme({
link: 'rgb(235, 137, 82)',
linkHover: 'rgb(240, 95, 12)',
})
setPlayer(player)
}, [videoId])
useEffect(() => {
player && player?.loadConfig({ id: videoId, hideControls: hideControls })
}, [hideControls, player, videoId])
const handleChangeSetting = (
e: ChangeEvent<HTMLInputElement>,
prop: string
) => {
const newSettings = { ...playerSettings, [prop]: e.currentTarget.value }
setPlayerSettings(newSettings)
player?.setTheme(newSettings)
}
return (
<GlobalContainer>
<div className="global-container">
<Head>
<title>Video view</title>
<meta
......@@ -67,44 +37,54 @@ const VideoView: NextPage<IVideoViewProps> = ({
/>
<link rel="icon" href="/favicon.ico" />
</Head>
<Header>
<span>Already there</span> 🎉
</Header>
<header>
{uploaded ? (
<>
<span>Already there</span> 🎉
</>
) : (
<>
<span>Here's your player</span> 👀
</>
)}
</header>
<main>
<TextsContainer>
<Text>
<div className="texts-container">
<p>
This player is generated by the{' '}
<a
target="_blank"
rel="noopener noreferrer"
href="https://github.com/apivideo/api.video-player-sdk"
href="https://github.com/apivideo/api.video-react-player"
>
api.video's Player SDK
api.video's React player component
</a>
.<br />
It provides multiple properties to customize your video player.
</Text>
<Text>Try 3 of them just bellow 👇</Text>
</TextsContainer>
</p>
<p>Try 3 of them just bellow 👇</p>
</div>
<InputsContainer>
<div className="inputs-container">
<div>
<label>Play button color</label>
<input
id="link"
type="text"
placeholder="Play button color"
value={playerSettings.link}
onChange={(e) => handleChangeSetting(e, 'link')}
value={playerTheme.link}
onChange={handleChangeSetting}
/>
</div>
<div>
<label>Buttons hover color</label>
<input
id="linkHover"
type="text"
placeholder="Buttons hover color"
value={playerSettings.linkHover}
onChange={(e) => handleChangeSetting(e, 'linkHover')}
value={playerTheme.linkHover}
onChange={handleChangeSetting}
/>
</div>
<div>
......@@ -117,17 +97,23 @@ const VideoView: NextPage<IVideoViewProps> = ({
/>
<label>Hide controls</label>
</div>
</InputsContainer>
<PlayerSdkContainer
id="player"
$width={parseInt(width)}
$height={parseInt(height)}
</div>
<ApiVideoPlayer
video={{ id: videoId }}
style={{ width: '75%', height: 300 }}
theme={playerTheme}
chromeless={hideControls}
/>
<Button onClick={() => router.push('/')}>Another video?</Button>
<button
className="upload"
onClick={() => router.push(uploaded ? '/uploader' : '/videos')}
>
{uploaded ? 'Another video?' : 'Videos list'}
</button>
</main>
<Footer>
<footer>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
......@@ -142,14 +128,14 @@ const VideoView: NextPage<IVideoViewProps> = ({
<a href="https://api.video" target="_blank" rel="noopener noreferrer">
api.video
</a>
</Footer>
</GlobalContainer>
</footer>
</div>
)
}
export default VideoView
export const getServerSideProps: GetServerSideProps = async (context) => {
const { videoId, w, h } = context.query
return { props: { videoId, width: w ?? null, height: h ?? null } }
const { videoId, uploaded } = context.query
return { props: { videoId, uploaded: uploaded ?? null } }
}
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import React, { useEffect, useState } from 'react'
import VideosListResponse from '@api.video/nodejs-client/lib/model/VideosListResponse'
const Videos: NextPage = () => {
const [videosResponse, setVideosResponse] = useState<
VideosListResponse | undefined
>(undefined)
const [error, setError] = useState<boolean>(false)
useEffect(() => {
fetch('/api/videos')
.then((res) => res.json())
.then((res: { videos: VideosListResponse }) =>
setVideosResponse(res.videos)
)
.catch((_) => setError(true))
}, [])
return (
<div className="global-container">
<Head>
<title>Videos List</title>
<meta
name="description"
content="Generated by create next app & created by api.video"
/>
<link rel="icon" href="/favicon.ico" />
</Head>
<header>
<span>api.video videos list</span> 📚
</header>
<main>
<div className="texts-container">
<p>
Welcome to this basic example of videos list provided by{' '}
<a
href="https://api.video"
target="_blank"
rel="noopener noreferrer"
>
api.video
</a>
.
</p>
<p>
Please, add your api.video API key in your <i>.env</i> file and let
the power of the API do the rest 🎩
</p>
</div>
{!videosResponse && !error && <div>Loading...</div>}
{error && (
<div className="error">
An error occured trying to fetch your videos. Be sure to have you
API key set in your .env file this way: <i>API_KEY=YOUR_API_KEY</i>
</div>
)}
{videosResponse && videosResponse.data?.length > 0 && (
<div className="videos-list">
{videosResponse.data.map((video) => (
<a
className="video-card"
href={`/videos/${video.videoId}`}
key={video.videoId}
>
<h3>{video.title}</h3>
<Image
src={video.assets?.thumbnail ?? '/vercel.svg'}
alt="Video thumbmail"
width={150}
height={80}
/>
</a>
))}
</div>
)}
{videosResponse && videosResponse.data?.length === 0 && (
<>
<p>You don't have any video yet 🧐</p>
<a className="button" href="/uploader">
Upload my first video
</a>
</>
)}
</main>
<footer>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
<span>and</span>
<a href="https://api.video" target="_blank" rel="noopener noreferrer">
api.video
</a>
</footer>
</div>
)
}
export default Videos
header {
font-size: 2.5rem;
margin-top: 2rem;
}
header > span {
font-weight: 700;
background: -webkit-linear-gradient(
45deg,
rgb(250, 91, 48) 0%,
rgb(128, 54, 255) 26.88%,
rgb(213, 63, 255) 50.44%,
rgb(235, 137, 82) 73.83%,
rgb(247, 181, 0) 100%
);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
footer {
margin-top: auto;
margin-bottom: 1rem;
display: flex;
align-items: center;
gap: 5px;
}
footer > a:nth-child(3) {
font-weight: 600;
font-size: 1.1rem;
}
p {
text-align: center;
font-size: 1.1rem;
letter-spacing: 0.03rem;
}
p > a {
font-weight: 700;
text-decoration: underline;
}
p > a:hover {
color: rgb(2, 2, 102);
}
.global-container {
box-sizing: border-box;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
gap: 20px;
}
.global-container main {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
}
.texts-container {
display: flex;
flex-direction: column;
gap: 20px;
padding: 3rem 5rem;
box-shadow: rgb(0 0 0 / 10%) 0px 2px 4px;
border-radius: 5px;
}
.texts-container > p {
text-align: center;
font-size: 1.1rem;
letter-spacing: 0.03rem;
}
.texts-container > p a {
font-weight: 700;
}
.videos-list {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: stretch;
gap: 1rem;
}
.videos-list .video-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 1rem 2rem;
box-shadow: rgb(0 0 0 / 10%) 0px 2px 4px;
border-radius: 5px;
max-width: 250px;
text-align: center;
transition: transform 200ms ease-in-out;
}
.videos-list .video-card:hover {
transform: scale(1.05);
}
button.upload,
a.button {
background: -webkit-linear-gradient(
45deg,
rgb(250, 91, 48) 0%,
rgb(235, 137, 82) 50%,
rgb(247, 181, 0) 100%
);
border: none;
padding: 0.8rem 1.2rem;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
font-size: 1.2rem;
font-weight: 500;
}
.status-container {
display: flex;
justify-content: center;
align-items: center;
gap: 2rem;
}
.status-container > span {
width: 35px;
height: 5px;
border-radius: 5px;
background-color: rgb(235, 137, 82);
margin-top: 20px;
}
.inputs-container {
display: flex;
gap: 20px;
}
.inputs-container > div {
display: flex;
flex-direction: column;
gap: 5px;
}
.inputs-container > div label {
font-size: 0.6rem;
}
.inputs-container > div:last-child {
flex-direction: row;
align-items: center;
align-self: flex-end;
}
.error {
color: rgb(250, 91, 48);
}
.error i {
font-weight: 600;
}
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
p {
margin: 0 !important;
}
* {
box-sizing: border-box;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment