Fix VimeoEmbed TypeScript player instance types
This commit is contained in:
@@ -14,14 +14,16 @@ declare global {
|
||||
Player: new (
|
||||
el: HTMLIFrameElement | HTMLElement,
|
||||
opts?: { id?: string | number; url?: string }
|
||||
) => {
|
||||
on: (event: string, cb: (data?: unknown) => void) => void;
|
||||
destroy: () => void;
|
||||
};
|
||||
) => VimeoPlayerInstance;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type VimeoPlayerInstance = {
|
||||
on: (event: string, cb: (data?: unknown) => void) => void;
|
||||
destroy: () => void;
|
||||
};
|
||||
|
||||
let playerSdkPromise: Promise<void> | null = null;
|
||||
|
||||
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`;
|
||||
|
||||
useEffect(() => {
|
||||
let player: { destroy: () => void } | null = null;
|
||||
let player: VimeoPlayerInstance | null = null;
|
||||
let cancelled = false;
|
||||
|
||||
setBlocked(false);
|
||||
@@ -66,7 +68,7 @@ export function VimeoEmbed({ videoId, title, watchUrl, poster }: Props) {
|
||||
.then(() => {
|
||||
if (cancelled || !iframeRef.current || !window.Vimeo?.Player) return;
|
||||
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
|
||||
console.warn("Vimeo player error", data);
|
||||
if (!cancelled) setBlocked(true);
|
||||
|
||||
Reference in New Issue
Block a user