All files / atom/videoPlayer/src/hooks useVideoPlayer.js

90% Statements 18/20
75% Branches 3/4
100% Functions 5/5
87.5% Lines 14/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42            1x 1x 1x 1x     1x             1x 63x 63x 63x   63x 5x       58x   58x           58x        
import {lazy} from 'react'
 
import {UNKNOWN} from '../settings/index.js'
import useDetectVideoType from './useDetectVideoType.js'
 
// Static imports for Vite compatibility (instead of dynamic template strings)
const HLSPlayer = lazy(() => import('../components/HLSPlayer.js'))
const NativePlayer = lazy(() => import('../components/NativePlayer.js'))
const VimeoPlayer = lazy(() => import('../components/VimeoPlayer.js'))
const YouTubePlayer = lazy(() => import('../components/YouTubePlayer.js'))
 
// Map player component names to actual components
const PLAYER_COMPONENTS = {
  HLSPlayer,
  NativePlayer,
  VimeoPlayer,
  YouTubePlayer
}
 
const useVideoPlayer = props => {
  const {src} = props
  const {detectVideoType} = useDetectVideoType()
  const videoType = detectVideoType(src)
 
  if (videoType === UNKNOWN) {
    return ['p', {...props, children: 'Not supported media type'}]
  }
 
  // Get the component from the map instead of using dynamic import
  const Component = PLAYER_COMPONENTS[videoType.PLAYER_COMPONENT]
 
  Iif (!Component) {
    console.error(`[useVideoPlayer] Unknown player component: ${videoType.PLAYER_COMPONENT}`)
 
    return ['p', {...props, children: 'Not supported media type'}]
  }
 
  return [Component, props]
}
 
export default useVideoPlayer