Fix VimeoEmbed TypeScript player instance types
This commit is contained in:
@@ -14,14 +14,16 @@ declare global {
|
|||||||
Player: new (
|
Player: new (
|
||||||
el: HTMLIFrameElement | HTMLElement,
|
el: HTMLIFrameElement | HTMLElement,
|
||||||
opts?: { id?: string | number; url?: string }
|
opts?: { id?: string | number; url?: string }
|
||||||
) => {
|
) => VimeoPlayerInstance;
|
||||||
on: (event: string, cb: (data?: unknown) => void) => void;
|
|
||||||
destroy: () => void;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VimeoPlayerInstance = {
|
||||||
|
on: (event: string, cb: (data?: unknown) => void) => void;
|
||||||
|
destroy: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
let playerSdkPromise: Promise<void> | null = null;
|
let playerSdkPromise: Promise<void> | null = null;
|
||||||
|
|
||||||
function loadVimeoSdk(): Promise<void> {
|
function loadVimeoSdk(): Promise<void> {
|
||||||
@@ -57,7 +59,7 @@ export function VimeoEmbed({ videoId, title, watchUrl, poster }: Props) {
|
|||||||
const embedSrc = `https://player.vimeo.com/video/${videoId}?title=0&byline=0&portrait=0`;
|
const embedSrc = `https://player.vimeo.com/video/${videoId}?title=0&byline=0&portrait=0`;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let player: { destroy: () => void } | null = null;
|
let player: VimeoPlayerInstance | null = null;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
setBlocked(false);
|
setBlocked(false);
|
||||||
@@ -66,7 +68,7 @@ export function VimeoEmbed({ videoId, title, watchUrl, poster }: Props) {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
if (cancelled || !iframeRef.current || !window.Vimeo?.Player) return;
|
if (cancelled || !iframeRef.current || !window.Vimeo?.Player) return;
|
||||||
player = new window.Vimeo.Player(iframeRef.current);
|
player = new window.Vimeo.Player(iframeRef.current);
|
||||||
player.on("error", (data: unknown) => {
|
player.on("error", (data?: unknown) => {
|
||||||
// Privacy / password / unavailable — leave site only as last resort
|
// Privacy / password / unavailable — leave site only as last resort
|
||||||
console.warn("Vimeo player error", data);
|
console.warn("Vimeo player error", data);
|
||||||
if (!cancelled) setBlocked(true);
|
if (!cancelled) setBlocked(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user