mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00

* Change copyright year from 2020 to 2021 Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de> * Change copyright year in jetbrains copyright template Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
/*
|
|
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import React, { useCallback } from 'react'
|
|
import { OneClickEmbedding } from '../one-click-frame/one-click-embedding'
|
|
|
|
interface VimeoApiResponse {
|
|
// Vimeo uses strange names for their fields. ESLint doesn't like that.
|
|
// eslint-disable-next-line camelcase
|
|
thumbnail_large?: string
|
|
}
|
|
|
|
export interface VimeoFrameProps {
|
|
id: string
|
|
}
|
|
|
|
export const VimeoFrame: React.FC<VimeoFrameProps> = ({ id }) => {
|
|
const getPreviewImageLink = useCallback(async () => {
|
|
const response = await fetch(`https://vimeo.com/api/v2/video/${id}.json`, {
|
|
credentials: 'omit',
|
|
referrerPolicy: 'no-referrer'
|
|
})
|
|
if (response.status !== 200) {
|
|
throw new Error('Error while loading data from vimeo api')
|
|
}
|
|
const vimeoResponse: VimeoApiResponse[] = await response.json() as VimeoApiResponse[]
|
|
|
|
if (vimeoResponse[0] && vimeoResponse[0].thumbnail_large) {
|
|
return vimeoResponse[0].thumbnail_large
|
|
} else {
|
|
throw new Error('Invalid vimeo response')
|
|
}
|
|
}, [id])
|
|
|
|
return (
|
|
<OneClickEmbedding containerClassName={'embed-responsive embed-responsive-16by9'} previewContainerClassName={'embed-responsive-item'} loadingImageUrl={'https://i.vimeocdn.com/video/'} hoverIcon={'vimeo-square'}
|
|
onImageFetch={getPreviewImageLink}>
|
|
<iframe className='embed-responsive-item' title={`vimeo video of ${id}`}
|
|
src={`https://player.vimeo.com/video/${id}?autoplay=1`}
|
|
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"/>
|
|
</OneClickEmbedding>
|
|
)
|
|
}
|