Skip to content

Commit 4fffe1b

Browse files
authored
feat: dropdown a ReactPlayer version (#254) (#257)
Release As: 1.25.5
1 parent 3a48238 commit 4fffe1b

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"bem-cn-lite": "^4.0.0",
5151
"github-buttons": "2.23.0",
5252
"lodash": "^4.17.21",
53-
"react-player": "^2.12.0",
53+
"react-player": "^2.9.0",
5454
"react-slick": "^0.28.1",
5555
"react-spring": "^9.3.0",
5656
"react-transition-group": "^4.4.2",

src/components/ReactPlayer/ReactPlayer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {MetrikaContext} from '../../context/metrikaContext';
3030
import {MobileContext} from '../../context/mobileContext';
3131
import {useAnalytics} from '../../hooks';
3232
import {PlayVideo} from '../../icons';
33+
import {checkYoutubeVideos} from './utils';
3334

3435
import './ReactPlayer.scss';
3536

@@ -100,6 +101,8 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
100101
const [paused, setPaused] = useState<boolean>(false);
101102
const [ended, setEnded] = useState<boolean>(false);
102103

104+
const videoSrc = useMemo(() => checkYoutubeVideos(src), [src]);
105+
103106
const eventsArray = useMemo(() => {
104107
if (analyticsEvents) {
105108
return Array.isArray(analyticsEvents) ? analyticsEvents : [analyticsEvents];
@@ -329,7 +332,7 @@ export const ReactPlayerBlock = React.forwardRef<ReactPlayerBlockHandler, ReactP
329332
>
330333
<ReactPlayer
331334
className={b('player')}
332-
url={src}
335+
url={videoSrc}
333336
muted={muted}
334337
controls={controls === MediaVideoControlsType.Default}
335338
height={currentHeight || '100%'}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// the file serves to support live video with [email protected]
2+
const LIVE_YUOTUBE_VIDEO_REGEX =
3+
/(?:youtu\.be\/live\/|youtube(?:-nocookie)?\.com\/(?:live\/))((\w|-){11})/;
4+
const YOUTUBE_VIDEO_TEMPLATE = 'https://www.youtube.com/watch?v=';
5+
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+
}
17+
18+
return videoUrl;
19+
});
20+
}
21+
22+
return src;
23+
};

0 commit comments

Comments
 (0)