UNPKG

@playkit-js/dynamic-watermark

Version:
24 lines (19 loc) 568 B
export const observeVideoAspectRatio = ( video: HTMLVideoElement, callback: (aspectRatio: number | null) => void, ) => { const getAspectRatio = () => { const aspectRatio = Math.max(0, video.videoWidth / video.videoHeight); return isFinite(aspectRatio) ? aspectRatio : null; }; const handleVideoResize = () => { callback(getAspectRatio()); }; video.addEventListener('resize', handleVideoResize); return { initial: getAspectRatio(), disconnect: () => { video.removeEventListener('resize', handleVideoResize); }, }; };