@@ -6,6 +6,7 @@ import "video.js/dist/video-js.css";
66
77interface PlayerProps {
88 videoSrc : string ;
9+ mimeType ?: string ;
910}
1011
1112const videoJSoptions : {
@@ -32,28 +33,10 @@ export const VideoRenderer = (props: PlayerProps) => {
3233 const playerRef = React . useRef < any > ( null ) ;
3334
3435 const [ videoSrc , setVideoSrc ] = React . useState < string | undefined > ( ) ;
35- const [ overrideMimeType , setOverrideMimeType ] = React . useState <
36- string | undefined
37- > ( undefined ) ;
3836
3937 const [ hasStartedPlaying , setHasStartedPlaying ] =
4038 React . useState < boolean > ( false ) ;
4139
42- const pollUrl = useCallback (
43- async ( url : string ) => {
44- const res = await fetch ( url , { method : "HEAD" } ) ;
45- if ( hasStartedPlaying ) return ;
46- if ( res . ok ) {
47- setVideoSrc ( url ) ;
48- } else {
49- setTimeout ( ( ) => {
50- pollUrl ( url ) ;
51- } , 1000 ) ;
52- }
53- } ,
54- [ setVideoSrc , hasStartedPlaying ]
55- ) ;
56-
5740 const options = useMemo (
5841 ( ) => ( {
5942 ...videoJSoptions ,
@@ -62,7 +45,7 @@ export const VideoRenderer = (props: PlayerProps) => {
6245 {
6346 src : videoSrc ?? "" ,
6447 type :
65- overrideMimeType ||
48+ props . mimeType ||
6649 ( videoSrc ?. endsWith ( ".m3u8" )
6750 ? "application/x-mpegURL"
6851 : videoSrc ?. endsWith ( ".mp4" )
@@ -71,26 +54,12 @@ export const VideoRenderer = (props: PlayerProps) => {
7154 } ,
7255 ] ,
7356 } ) ,
74- [ videoSrc , overrideMimeType ]
57+ [ videoSrc , props . mimeType ]
7558 ) ;
7659
7760 useEffect ( ( ) => {
78- if ( props . videoSrc . startsWith ( "ipfs://" ) ) {
79- // Exchange ipfs:// for .m3u8 url via /livepeer-video?url=ipfs://...
80- const baseUrl = `${
81- process . env . NEXT_PUBLIC_API_URL || "https://api.modprotocol.org"
82- } /livepeer-video`;
83- const endpointUrl = `${ baseUrl } ?url=${ props . videoSrc } ` ;
84- fetch ( endpointUrl ) . then ( async ( res ) => {
85- const { url, fallbackUrl, mimeType } = await res . json ( ) ;
86- setOverrideMimeType ( mimeType ) ;
87- setVideoSrc ( `${ fallbackUrl } ` ) ;
88- pollUrl ( url ) ;
89- } ) ;
90- } else {
91- setVideoSrc ( props . videoSrc ) ;
92- }
93- } , [ props . videoSrc , pollUrl ] ) ;
61+ setVideoSrc ( props . videoSrc ) ;
62+ } , [ props . videoSrc ] ) ;
9463
9564 useEffect ( ( ) => {
9665 // Make sure Video.js player is only initialized once
0 commit comments