UNPKG

@100mslive/roomkit-react

Version:

![Banner](https://github.com/100mslive/web-sdks/blob/06c65259912db6ccd8617f2ecb6fef51429251ec/prebuilt-banner.png)

76 lines (73 loc) 2 kB
import React, { forwardRef, useEffect, useState } from 'react'; import { Flex } from '../../../Layout'; export const HMSVideo = forwardRef(({ children, isFullScreen, ...props }, videoRef) => { const [width, setWidth] = useState('auto'); useEffect(() => { const updatingVideoWidth = () => { const videoEl = videoRef.current; if (!videoEl) { return; } if (videoEl.videoWidth > videoEl.videoHeight && width !== '100%') { setWidth('100%'); } }; const videoEl = videoRef.current; if (!videoEl) { return; } videoEl.addEventListener('loadedmetadata', updatingVideoWidth); return () => { videoEl.removeEventListener('loadedmetadata', updatingVideoWidth); }; }, [videoRef, width]); return ( <Flex data-testid="hms-video" css={{ size: '100%', position: 'relative', justifyContent: 'center', transition: 'all 0.3s ease-in-out', '@md': { '& video': { height: isFullScreen ? '' : '$60 !important', }, }, '& video::cue': { // default for on-surface-high color: '#EFF0FA', whiteSpace: 'pre-line', fontSize: '$sm', fontStyle: 'normal', fontWeight: '$regular', lineHeight: '$sm', letterSpacing: '0.25px', }, '& video::-webkit-media-text-track-display': { padding: '0 $4', boxShadow: '0px 1px 3px 0px #000000A3', }, '& video::-webkit-media-text-track-container': { fontSize: '$space$10 !important', }, }} direction="column" {...props} > <video style={{ margin: '0 auto', objectFit: 'contain', width: width, height: '100%', maxWidth: '100%', }} ref={videoRef} playsInline disablePictureInPicture /> {children} </Flex> ); });