File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
src/components/ReactPlayer Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -3,21 +3,23 @@ const LIVE_YUOTUBE_VIDEO_REGEX =
33 / (?: y o u t u \. b e \/ l i v e \/ | y o u t u b e (?: - n o c o o k i e ) ? \. c o m \/ (?: l i v e \/ ) ) ( ( \w | - ) { 11 } ) / ;
44const YOUTUBE_VIDEO_TEMPLATE = 'https://www.youtube.com/watch?v=' ;
55
6- export const checkYoutubeVideos = ( src : string | string [ ] ) => {
7- if ( Array . isArray ( src ) ) {
8- return src . map ( ( videoUrl ) => {
9- if ( LIVE_YUOTUBE_VIDEO_REGEX . test ( videoUrl ) ) {
10- const youtubeLiveId = videoUrl . match ( LIVE_YUOTUBE_VIDEO_REGEX ) ?. [ 1 ] ;
11- if ( ! youtubeLiveId ) {
12- return videoUrl ;
13- }
14-
15- return `${ YOUTUBE_VIDEO_TEMPLATE } ${ youtubeLiveId } ` ;
16- }
6+ const transformYoutubeUrl = ( src : string ) => {
7+ if ( LIVE_YUOTUBE_VIDEO_REGEX . test ( src ) ) {
8+ const youtubeLiveId = src . match ( LIVE_YUOTUBE_VIDEO_REGEX ) ?. [ 1 ] ;
9+ if ( ! youtubeLiveId ) {
10+ return src ;
11+ }
1712
18- return videoUrl ;
19- } ) ;
13+ return `${ YOUTUBE_VIDEO_TEMPLATE } ${ youtubeLiveId } ` ;
2014 }
2115
2216 return src ;
2317} ;
18+
19+ export const checkYoutubeVideos = ( src : string | string [ ] ) => {
20+ if ( Array . isArray ( src ) ) {
21+ return src . map ( ( videoUrl ) => transformYoutubeUrl ( videoUrl ) ) ;
22+ }
23+
24+ return transformYoutubeUrl ( src ) ;
25+ } ;
You can’t perform that action at this time.
0 commit comments