@cloud-ru/ds-site-media 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/LICENSE +201 -0
- package/README.md +167 -2
- package/dist/cjs/components/SiteImage/SiteImage.d.ts +10 -0
- package/dist/cjs/components/SiteImage/SiteImage.js +8 -0
- package/dist/cjs/components/SiteImage/index.d.ts +1 -0
- package/dist/cjs/components/SiteImage/index.js +17 -0
- package/dist/cjs/components/SiteVideo/SiteVideo.d.ts +15 -0
- package/dist/cjs/components/SiteVideo/SiteVideo.js +16 -0
- package/dist/cjs/components/SiteVideo/VideoContent.d.ts +4 -0
- package/dist/cjs/components/SiteVideo/VideoContent.js +27 -0
- package/dist/cjs/components/SiteVideo/index.d.ts +1 -0
- package/dist/cjs/components/SiteVideo/index.js +17 -0
- package/dist/cjs/components/SiteVideo/styles.module.css +15 -0
- package/dist/cjs/components/index.d.ts +2 -0
- package/dist/cjs/components/index.js +18 -0
- package/dist/cjs/constants.d.ts +31 -0
- package/dist/cjs/constants.js +34 -0
- package/dist/cjs/helperComponents/EmbedPlayer/EmbedPlayer.d.ts +10 -0
- package/dist/cjs/helperComponents/EmbedPlayer/EmbedPlayer.js +108 -0
- package/dist/cjs/helperComponents/EmbedPlayer/index.d.ts +1 -0
- package/dist/cjs/helperComponents/EmbedPlayer/index.js +17 -0
- package/dist/cjs/helperComponents/EmbedPlayer/styles.module.css +15 -0
- package/dist/cjs/helperComponents/NativePlayer/NativePlayer.d.ts +2 -0
- package/dist/cjs/helperComponents/NativePlayer/NativePlayer.js +106 -0
- package/dist/cjs/helperComponents/NativePlayer/hooks.d.ts +13 -0
- package/dist/cjs/helperComponents/NativePlayer/hooks.js +140 -0
- package/dist/cjs/helperComponents/NativePlayer/index.d.ts +1 -0
- package/dist/cjs/helperComponents/NativePlayer/index.js +17 -0
- package/dist/cjs/helperComponents/NativePlayer/styles.module.css +39 -0
- package/dist/cjs/helperComponents/NativePlayer/types.d.ts +6 -0
- package/dist/cjs/helperComponents/NativePlayer/types.js +2 -0
- package/dist/cjs/helperComponents/NativePlayer/utils.d.ts +19 -0
- package/dist/cjs/helperComponents/NativePlayer/utils.js +24 -0
- package/dist/cjs/helperComponents/PlayerError/PlayerError.d.ts +5 -0
- package/dist/cjs/helperComponents/PlayerError/PlayerError.js +15 -0
- package/dist/cjs/helperComponents/PlayerError/index.d.ts +1 -0
- package/dist/cjs/helperComponents/PlayerError/index.js +17 -0
- package/dist/cjs/helperComponents/PlayerError/styles.module.css +32 -0
- package/dist/cjs/helperComponents/SpeedSelect/SpeedSelect.d.ts +7 -0
- package/dist/cjs/helperComponents/SpeedSelect/SpeedSelect.js +30 -0
- package/dist/cjs/helperComponents/SpeedSelect/index.d.ts +1 -0
- package/dist/cjs/helperComponents/SpeedSelect/index.js +17 -0
- package/dist/cjs/helperComponents/SpeedSelect/styles.module.css +7 -0
- package/dist/cjs/helperComponents/Toolbar/PlaybackControls.d.ts +6 -0
- package/dist/cjs/helperComponents/Toolbar/PlaybackControls.js +23 -0
- package/dist/cjs/helperComponents/Toolbar/Timeline.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/Timeline.js +23 -0
- package/dist/cjs/helperComponents/Toolbar/TimelinePreview.d.ts +8 -0
- package/dist/cjs/helperComponents/Toolbar/TimelinePreview.js +21 -0
- package/dist/cjs/helperComponents/Toolbar/Toolbar.d.ts +14 -0
- package/dist/cjs/helperComponents/Toolbar/Toolbar.js +19 -0
- package/dist/cjs/helperComponents/Toolbar/ToolbarButton.d.ts +12 -0
- package/dist/cjs/helperComponents/Toolbar/ToolbarButton.js +14 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/index.js +17 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/useTimeline.d.ts +10 -0
- package/dist/cjs/helperComponents/Toolbar/hooks/useTimeline.js +32 -0
- package/dist/cjs/helperComponents/Toolbar/index.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/index.js +17 -0
- package/dist/cjs/helperComponents/Toolbar/styles.module.css +115 -0
- package/dist/cjs/helperComponents/Toolbar/types.d.ts +5 -0
- package/dist/cjs/helperComponents/Toolbar/types.js +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByKey.d.ts +1 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByKey.js +20 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByPointer.d.ts +5 -0
- package/dist/cjs/helperComponents/Toolbar/utils/getTimeByPointer.js +7 -0
- package/dist/cjs/helperComponents/Toolbar/utils/index.d.ts +6 -0
- package/dist/cjs/helperComponents/Toolbar/utils/index.js +22 -0
- package/dist/cjs/helperComponents/Toolbar/utils/restart.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/restart.js +7 -0
- package/dist/cjs/helperComponents/Toolbar/utils/seek.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/seek.js +6 -0
- package/dist/cjs/helperComponents/Toolbar/utils/setVolume.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/setVolume.js +10 -0
- package/dist/cjs/helperComponents/Toolbar/utils/toggleMute.d.ts +2 -0
- package/dist/cjs/helperComponents/Toolbar/utils/toggleMute.js +9 -0
- package/dist/cjs/helperComponents/VideoPlayButton/VideoPlayButton.d.ts +10 -0
- package/dist/cjs/helperComponents/VideoPlayButton/VideoPlayButton.js +18 -0
- package/dist/cjs/helperComponents/VideoPlayButton/index.d.ts +1 -0
- package/dist/cjs/helperComponents/VideoPlayButton/index.js +17 -0
- package/dist/cjs/helperComponents/VideoPlayButton/styles.module.css +100 -0
- package/dist/cjs/hocs/withPlayerClassName.d.ts +3 -0
- package/dist/cjs/hocs/withPlayerClassName.js +15 -0
- package/dist/cjs/hooks/useFullscreen.d.ts +6 -0
- package/dist/cjs/hooks/useFullscreen.js +32 -0
- package/dist/cjs/hooks/usePlayerState.d.ts +11 -0
- package/dist/cjs/hooks/usePlayerState.js +60 -0
- package/dist/cjs/hooks/useSpriteFrames.d.ts +2 -0
- package/dist/cjs/hooks/useSpriteFrames.js +32 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/locale/index.d.ts +83 -0
- package/dist/cjs/locale/index.js +46 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shared/types.d.ts +8 -0
- package/dist/cjs/shared/types.js +2 -0
- package/dist/cjs/style.css +323 -0
- package/dist/cjs/types.d.ts +15 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/embed.d.ts +8 -0
- package/dist/cjs/utils/embed.js +74 -0
- package/dist/cjs/utils/format.d.ts +2 -0
- package/dist/cjs/utils/format.js +17 -0
- package/dist/cjs/utils/fullscreen.d.ts +5 -0
- package/dist/cjs/utils/fullscreen.js +29 -0
- package/dist/cjs/utils/index.d.ts +6 -0
- package/dist/cjs/utils/index.js +22 -0
- package/dist/cjs/utils/loadSpriteFrames.d.ts +3 -0
- package/dist/cjs/utils/loadSpriteFrames.js +9 -0
- package/dist/cjs/utils/source.d.ts +5 -0
- package/dist/cjs/utils/source.js +19 -0
- package/dist/cjs/utils/sprite.d.ts +3 -0
- package/dist/cjs/utils/sprite.js +41 -0
- package/dist/cjs/utils/url.d.ts +1 -0
- package/dist/cjs/utils/url.js +15 -0
- package/dist/esm/components/SiteImage/SiteImage.d.ts +10 -0
- package/dist/esm/components/SiteImage/SiteImage.js +5 -0
- package/dist/esm/components/SiteImage/index.d.ts +1 -0
- package/dist/esm/components/SiteImage/index.js +1 -0
- package/dist/esm/components/SiteVideo/SiteVideo.d.ts +15 -0
- package/dist/esm/components/SiteVideo/SiteVideo.js +10 -0
- package/dist/esm/components/SiteVideo/VideoContent.d.ts +4 -0
- package/dist/esm/components/SiteVideo/VideoContent.js +21 -0
- package/dist/esm/components/SiteVideo/index.d.ts +1 -0
- package/dist/esm/components/SiteVideo/index.js +1 -0
- package/dist/esm/components/SiteVideo/styles.module.css +15 -0
- package/dist/esm/components/index.d.ts +2 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/constants.d.ts +31 -0
- package/dist/esm/constants.js +31 -0
- package/dist/esm/helperComponents/EmbedPlayer/EmbedPlayer.d.ts +10 -0
- package/dist/esm/helperComponents/EmbedPlayer/EmbedPlayer.js +102 -0
- package/dist/esm/helperComponents/EmbedPlayer/index.d.ts +1 -0
- package/dist/esm/helperComponents/EmbedPlayer/index.js +1 -0
- package/dist/esm/helperComponents/EmbedPlayer/styles.module.css +15 -0
- package/dist/esm/helperComponents/NativePlayer/NativePlayer.d.ts +2 -0
- package/dist/esm/helperComponents/NativePlayer/NativePlayer.js +100 -0
- package/dist/esm/helperComponents/NativePlayer/hooks.d.ts +13 -0
- package/dist/esm/helperComponents/NativePlayer/hooks.js +101 -0
- package/dist/esm/helperComponents/NativePlayer/index.d.ts +1 -0
- package/dist/esm/helperComponents/NativePlayer/index.js +1 -0
- package/dist/esm/helperComponents/NativePlayer/styles.module.css +39 -0
- package/dist/esm/helperComponents/NativePlayer/types.d.ts +6 -0
- package/dist/esm/helperComponents/NativePlayer/types.js +1 -0
- package/dist/esm/helperComponents/NativePlayer/utils.d.ts +19 -0
- package/dist/esm/helperComponents/NativePlayer/utils.js +20 -0
- package/dist/esm/helperComponents/PlayerError/PlayerError.d.ts +5 -0
- package/dist/esm/helperComponents/PlayerError/PlayerError.js +9 -0
- package/dist/esm/helperComponents/PlayerError/index.d.ts +1 -0
- package/dist/esm/helperComponents/PlayerError/index.js +1 -0
- package/dist/esm/helperComponents/PlayerError/styles.module.css +32 -0
- package/dist/esm/helperComponents/SpeedSelect/SpeedSelect.d.ts +7 -0
- package/dist/esm/helperComponents/SpeedSelect/SpeedSelect.js +24 -0
- package/dist/esm/helperComponents/SpeedSelect/index.d.ts +1 -0
- package/dist/esm/helperComponents/SpeedSelect/index.js +1 -0
- package/dist/esm/helperComponents/SpeedSelect/styles.module.css +7 -0
- package/dist/esm/helperComponents/Toolbar/PlaybackControls.d.ts +6 -0
- package/dist/esm/helperComponents/Toolbar/PlaybackControls.js +17 -0
- package/dist/esm/helperComponents/Toolbar/Timeline.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/Timeline.js +17 -0
- package/dist/esm/helperComponents/Toolbar/TimelinePreview.d.ts +8 -0
- package/dist/esm/helperComponents/Toolbar/TimelinePreview.js +15 -0
- package/dist/esm/helperComponents/Toolbar/Toolbar.d.ts +14 -0
- package/dist/esm/helperComponents/Toolbar/Toolbar.js +13 -0
- package/dist/esm/helperComponents/Toolbar/ToolbarButton.d.ts +12 -0
- package/dist/esm/helperComponents/Toolbar/ToolbarButton.js +11 -0
- package/dist/esm/helperComponents/Toolbar/hooks/index.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/hooks/index.js +1 -0
- package/dist/esm/helperComponents/Toolbar/hooks/useTimeline.d.ts +10 -0
- package/dist/esm/helperComponents/Toolbar/hooks/useTimeline.js +29 -0
- package/dist/esm/helperComponents/Toolbar/index.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/index.js +1 -0
- package/dist/esm/helperComponents/Toolbar/styles.module.css +115 -0
- package/dist/esm/helperComponents/Toolbar/types.d.ts +5 -0
- package/dist/esm/helperComponents/Toolbar/types.js +1 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByKey.d.ts +1 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByKey.js +17 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByPointer.d.ts +5 -0
- package/dist/esm/helperComponents/Toolbar/utils/getTimeByPointer.js +4 -0
- package/dist/esm/helperComponents/Toolbar/utils/index.d.ts +6 -0
- package/dist/esm/helperComponents/Toolbar/utils/index.js +6 -0
- package/dist/esm/helperComponents/Toolbar/utils/restart.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/restart.js +4 -0
- package/dist/esm/helperComponents/Toolbar/utils/seek.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/seek.js +3 -0
- package/dist/esm/helperComponents/Toolbar/utils/setVolume.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/setVolume.js +7 -0
- package/dist/esm/helperComponents/Toolbar/utils/toggleMute.d.ts +2 -0
- package/dist/esm/helperComponents/Toolbar/utils/toggleMute.js +6 -0
- package/dist/esm/helperComponents/VideoPlayButton/VideoPlayButton.d.ts +10 -0
- package/dist/esm/helperComponents/VideoPlayButton/VideoPlayButton.js +12 -0
- package/dist/esm/helperComponents/VideoPlayButton/index.d.ts +1 -0
- package/dist/esm/helperComponents/VideoPlayButton/index.js +1 -0
- package/dist/esm/helperComponents/VideoPlayButton/styles.module.css +100 -0
- package/dist/esm/hocs/withPlayerClassName.d.ts +3 -0
- package/dist/esm/hocs/withPlayerClassName.js +9 -0
- package/dist/esm/hooks/useFullscreen.d.ts +6 -0
- package/dist/esm/hooks/useFullscreen.js +29 -0
- package/dist/esm/hooks/usePlayerState.d.ts +11 -0
- package/dist/esm/hooks/usePlayerState.js +57 -0
- package/dist/esm/hooks/useSpriteFrames.d.ts +2 -0
- package/dist/esm/hooks/useSpriteFrames.js +29 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/locale/index.d.ts +83 -0
- package/dist/esm/locale/index.js +43 -0
- package/dist/esm/shared/types.d.ts +8 -0
- package/dist/esm/shared/types.js +1 -0
- package/dist/esm/style.css +323 -0
- package/dist/esm/types.d.ts +15 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/embed.d.ts +8 -0
- package/dist/esm/utils/embed.js +69 -0
- package/dist/esm/utils/format.d.ts +2 -0
- package/dist/esm/utils/format.js +13 -0
- package/dist/esm/utils/fullscreen.d.ts +5 -0
- package/dist/esm/utils/fullscreen.js +26 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/loadSpriteFrames.d.ts +3 -0
- package/dist/esm/utils/loadSpriteFrames.js +6 -0
- package/dist/esm/utils/source.d.ts +5 -0
- package/dist/esm/utils/source.js +14 -0
- package/dist/esm/utils/sprite.d.ts +3 -0
- package/dist/esm/utils/sprite.js +37 -0
- package/dist/esm/utils/url.d.ts +1 -0
- package/dist/esm/utils/url.js +12 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +57 -3
- package/src/components/SiteImage/SiteImage.tsx +16 -0
- package/src/components/SiteImage/index.ts +1 -0
- package/src/components/SiteVideo/SiteVideo.tsx +28 -0
- package/src/components/SiteVideo/VideoContent.tsx +29 -0
- package/src/components/SiteVideo/index.ts +1 -0
- package/src/components/SiteVideo/styles.module.scss +19 -0
- package/src/components/index.ts +2 -0
- package/src/constants.ts +36 -0
- package/src/helperComponents/EmbedPlayer/EmbedPlayer.tsx +179 -0
- package/src/helperComponents/EmbedPlayer/index.ts +1 -0
- package/src/helperComponents/EmbedPlayer/styles.module.scss +18 -0
- package/src/helperComponents/NativePlayer/NativePlayer.tsx +168 -0
- package/src/helperComponents/NativePlayer/hooks.ts +115 -0
- package/src/helperComponents/NativePlayer/index.ts +1 -0
- package/src/helperComponents/NativePlayer/styles.module.scss +41 -0
- package/src/helperComponents/NativePlayer/types.ts +7 -0
- package/src/helperComponents/NativePlayer/utils.ts +29 -0
- package/src/helperComponents/PlayerError/PlayerError.tsx +18 -0
- package/src/helperComponents/PlayerError/index.ts +1 -0
- package/src/helperComponents/PlayerError/styles.module.scss +29 -0
- package/src/helperComponents/SpeedSelect/SpeedSelect.tsx +67 -0
- package/src/helperComponents/SpeedSelect/index.ts +1 -0
- package/src/helperComponents/SpeedSelect/styles.module.scss +9 -0
- package/src/helperComponents/Toolbar/PlaybackControls.tsx +104 -0
- package/src/helperComponents/Toolbar/Timeline.tsx +55 -0
- package/src/helperComponents/Toolbar/TimelinePreview.tsx +33 -0
- package/src/helperComponents/Toolbar/Toolbar.tsx +42 -0
- package/src/helperComponents/Toolbar/ToolbarButton.tsx +46 -0
- package/src/helperComponents/Toolbar/hooks/index.ts +1 -0
- package/src/helperComponents/Toolbar/hooks/useTimeline.ts +43 -0
- package/src/helperComponents/Toolbar/index.ts +1 -0
- package/src/helperComponents/Toolbar/styles.module.scss +138 -0
- package/src/helperComponents/Toolbar/types.ts +1 -0
- package/src/helperComponents/Toolbar/utils/getTimeByKey.ts +18 -0
- package/src/helperComponents/Toolbar/utils/getTimeByPointer.ts +11 -0
- package/src/helperComponents/Toolbar/utils/index.ts +6 -0
- package/src/helperComponents/Toolbar/utils/restart.ts +6 -0
- package/src/helperComponents/Toolbar/utils/seek.ts +5 -0
- package/src/helperComponents/Toolbar/utils/setVolume.ts +10 -0
- package/src/helperComponents/Toolbar/utils/toggleMute.ts +9 -0
- package/src/helperComponents/VideoPlayButton/VideoPlayButton.tsx +39 -0
- package/src/helperComponents/VideoPlayButton/index.ts +1 -0
- package/src/helperComponents/VideoPlayButton/styles.module.scss +112 -0
- package/src/hocs/withPlayerClassName.ts +11 -0
- package/src/hooks/useFullscreen.ts +39 -0
- package/src/hooks/usePlayerState.ts +80 -0
- package/src/hooks/useSpriteFrames.ts +39 -0
- package/src/index.ts +4 -0
- package/src/locale/index.ts +47 -0
- package/src/shared/types.ts +8 -0
- package/src/types.ts +15 -0
- package/src/utils/embed.ts +95 -0
- package/src/utils/format.ts +16 -0
- package/src/utils/fullscreen.ts +34 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/loadSpriteFrames.ts +8 -0
- package/src/utils/source.ts +22 -0
- package/src/utils/sprite.ts +48 -0
- package/src/utils/url.ts +13 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { extractSupportProps } from '@cloud-ru/ds-utils';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { TEST_IDS } from '../../constants.js';
|
|
5
|
+
import styles from './styles.module.css';
|
|
6
|
+
import { VideoContent } from './VideoContent.js';
|
|
7
|
+
/** Воспроизводит MP4 и HLS со своей панелью управления, а YouTube и Rutube — во встроенном плеере провайдера. */
|
|
8
|
+
export function SiteVideo({ video, onPlay, onError, className, ...rest }) {
|
|
9
|
+
return (_jsx("div", { className: cn(styles.videoWrapper, className), "data-test-id": TEST_IDS.root, ...extractSupportProps(rest), children: _jsx(VideoContent, { video: video, onPlay: onPlay, onError: onError }) }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SiteVideoProps } from './SiteVideo.js';
|
|
2
|
+
type VideoContentProps = Pick<SiteVideoProps, 'video' | 'onPlay' | 'onError'>;
|
|
3
|
+
export declare function VideoContent({ video, onPlay, onError }: VideoContentProps): string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | null | undefined;
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isValidElement } from 'react';
|
|
3
|
+
import { EmbedPlayer } from '../../helperComponents/EmbedPlayer/index.js';
|
|
4
|
+
import { NativePlayer } from '../../helperComponents/NativePlayer/index.js';
|
|
5
|
+
import { PlayerError } from '../../helperComponents/PlayerError/index.js';
|
|
6
|
+
import { withPlayerClassName } from '../../hocs/withPlayerClassName.js';
|
|
7
|
+
import { getEmbedSource, isVideoPlayerContent } from '../../utils/index.js';
|
|
8
|
+
import styles from './styles.module.css';
|
|
9
|
+
export function VideoContent({ video, onPlay, onError }) {
|
|
10
|
+
if (isVideoPlayerContent(video)) {
|
|
11
|
+
const embed = getEmbedSource(video.src);
|
|
12
|
+
if (embed) {
|
|
13
|
+
return _jsx(EmbedPlayer, { video: video, source: embed, onFirstPlay: onPlay, onError: onError }, video.src);
|
|
14
|
+
}
|
|
15
|
+
return _jsx(NativePlayer, { video: video, onFirstPlay: onPlay, onError: onError }, video.src);
|
|
16
|
+
}
|
|
17
|
+
if (isValidElement(video)) {
|
|
18
|
+
return withPlayerClassName(video, styles.customPlayer);
|
|
19
|
+
}
|
|
20
|
+
return _jsx(PlayerError, {});
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SiteVideo.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SiteVideo.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.videoWrapper{
|
|
2
|
+
isolation:isolate;
|
|
3
|
+
position:relative;
|
|
4
|
+
overflow:hidden;
|
|
5
|
+
aspect-ratio:16/9;
|
|
6
|
+
width:100%;
|
|
7
|
+
border-radius:var(--sn-density-radius-2xs, var(--sn-platform-comfort-radius-2xs, var(--sn-primitive-dimension-4, 4px)));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.customPlayer{
|
|
11
|
+
display:block;
|
|
12
|
+
width:100%;
|
|
13
|
+
height:100%;
|
|
14
|
+
border:0;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const SPRITE_VTT_NAME = "player_sprite.vtt";
|
|
2
|
+
export declare const PLAYBACK_RATES: number[];
|
|
3
|
+
export declare const SEEK_STEP = 10;
|
|
4
|
+
export declare const TOOLBAR_HIDE_DELAY = 2000;
|
|
5
|
+
export declare const DOUBLE_CLICK_DELAY = 200;
|
|
6
|
+
/** Стабильные идентификаторы секции и элементов плеера. */
|
|
7
|
+
export declare const TEST_IDS: {
|
|
8
|
+
readonly root: "site-video";
|
|
9
|
+
readonly poster: "site-video__poster";
|
|
10
|
+
readonly player: "site-video__player";
|
|
11
|
+
readonly mount: "site-video__mount";
|
|
12
|
+
readonly nativeVideo: "site-video__native-video";
|
|
13
|
+
readonly embed: "site-video__embed";
|
|
14
|
+
readonly playButton: "site-video__play";
|
|
15
|
+
readonly toolbar: "site-video__toolbar";
|
|
16
|
+
readonly timeline: "site-video__timeline";
|
|
17
|
+
readonly play: "site-video__toolbar-play";
|
|
18
|
+
readonly mute: "site-video__mute";
|
|
19
|
+
readonly volume: "site-video__volume";
|
|
20
|
+
readonly rewind: "site-video__rewind";
|
|
21
|
+
readonly forward: "site-video__forward";
|
|
22
|
+
readonly restart: "site-video__restart";
|
|
23
|
+
readonly time: "site-video__time";
|
|
24
|
+
readonly speed: "site-video__speed";
|
|
25
|
+
readonly speedMenu: "site-video__speed-menu";
|
|
26
|
+
readonly speedOption: "site-video__speed-option";
|
|
27
|
+
readonly fullscreen: "site-video__fullscreen";
|
|
28
|
+
readonly error: "site-video__error";
|
|
29
|
+
readonly retry: "site-video__retry";
|
|
30
|
+
readonly preview: "site-video__preview";
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const SPRITE_VTT_NAME = 'player_sprite.vtt';
|
|
2
|
+
export const PLAYBACK_RATES = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
|
3
|
+
export const SEEK_STEP = 10;
|
|
4
|
+
export const TOOLBAR_HIDE_DELAY = 2000;
|
|
5
|
+
export const DOUBLE_CLICK_DELAY = 200;
|
|
6
|
+
/** Стабильные идентификаторы секции и элементов плеера. */
|
|
7
|
+
export const TEST_IDS = {
|
|
8
|
+
root: 'site-video',
|
|
9
|
+
poster: 'site-video__poster',
|
|
10
|
+
player: 'site-video__player',
|
|
11
|
+
mount: 'site-video__mount',
|
|
12
|
+
nativeVideo: 'site-video__native-video',
|
|
13
|
+
embed: 'site-video__embed',
|
|
14
|
+
playButton: 'site-video__play',
|
|
15
|
+
toolbar: 'site-video__toolbar',
|
|
16
|
+
timeline: 'site-video__timeline',
|
|
17
|
+
play: 'site-video__toolbar-play',
|
|
18
|
+
mute: 'site-video__mute',
|
|
19
|
+
volume: 'site-video__volume',
|
|
20
|
+
rewind: 'site-video__rewind',
|
|
21
|
+
forward: 'site-video__forward',
|
|
22
|
+
restart: 'site-video__restart',
|
|
23
|
+
time: 'site-video__time',
|
|
24
|
+
speed: 'site-video__speed',
|
|
25
|
+
speedMenu: 'site-video__speed-menu',
|
|
26
|
+
speedOption: 'site-video__speed-option',
|
|
27
|
+
fullscreen: 'site-video__fullscreen',
|
|
28
|
+
error: 'site-video__error',
|
|
29
|
+
retry: 'site-video__retry',
|
|
30
|
+
preview: 'site-video__preview',
|
|
31
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VideoPlayerProps } from '../../types.js';
|
|
2
|
+
import { EmbedSource } from '../../utils/index.js';
|
|
3
|
+
type EmbedPlayerProps = {
|
|
4
|
+
source: EmbedSource;
|
|
5
|
+
video: VideoPlayerProps;
|
|
6
|
+
onFirstPlay?(): void;
|
|
7
|
+
onError?(): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function EmbedPlayer({ source, video, onFirstPlay, onError }: EmbedPlayerProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { TEST_IDS } from '../../constants.js';
|
|
4
|
+
import { siteMediaLocale } from '../../locale/index.js';
|
|
5
|
+
import { getEmbedPlaying, parseEmbedMessage } from '../../utils/index.js';
|
|
6
|
+
import { PlayerError } from '../PlayerError/index.js';
|
|
7
|
+
import { VideoPlayButton } from '../VideoPlayButton/index.js';
|
|
8
|
+
import styles from './styles.module.css';
|
|
9
|
+
export function EmbedPlayer({ source, video, onFirstPlay, onError }) {
|
|
10
|
+
const { t } = siteMediaLocale.useTranslations();
|
|
11
|
+
const { controls = true, autoPlay = false, poster, muted = false, loop = false } = video;
|
|
12
|
+
const iframeRef = useRef(null);
|
|
13
|
+
const firstPlayRef = useRef(false);
|
|
14
|
+
const callbacksRef = useRef({ onFirstPlay, onError });
|
|
15
|
+
callbacksRef.current = { onFirstPlay, onError };
|
|
16
|
+
const [activated, setActivated] = useState(autoPlay || !controls);
|
|
17
|
+
const [playing, setPlaying] = useState(false);
|
|
18
|
+
const [hovered, setHovered] = useState(false);
|
|
19
|
+
const [failed, setFailed] = useState(false);
|
|
20
|
+
const [attempt, setAttempt] = useState(0);
|
|
21
|
+
const [pageOrigin, setPageOrigin] = useState();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setPageOrigin(window.location.origin);
|
|
24
|
+
}, []);
|
|
25
|
+
const url = new URL(source.src);
|
|
26
|
+
url.searchParams.set('autoplay', activated && (controls || autoPlay) ? '1' : '0');
|
|
27
|
+
url.searchParams.set('controls', controls ? '1' : '0');
|
|
28
|
+
if (muted || autoPlay) {
|
|
29
|
+
url.searchParams.set('mute', '1');
|
|
30
|
+
}
|
|
31
|
+
if (loop) {
|
|
32
|
+
url.searchParams.set('loop', '1');
|
|
33
|
+
if (source.provider === 'youtube') {
|
|
34
|
+
url.searchParams.set('playlist', url.pathname.split('/').pop() ?? '');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (pageOrigin) {
|
|
38
|
+
url.searchParams.set('origin', pageOrigin);
|
|
39
|
+
}
|
|
40
|
+
const origin = url.origin;
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const handleMessage = (event) => {
|
|
43
|
+
if (event.source !== iframeRef.current?.contentWindow || event.origin !== origin) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const message = parseEmbedMessage(event.data);
|
|
47
|
+
if (!message) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (message.event === 'onError' || message.type === 'player:error') {
|
|
51
|
+
setFailed(true);
|
|
52
|
+
callbacksRef.current.onError?.();
|
|
53
|
+
}
|
|
54
|
+
const nextPlaying = getEmbedPlaying(source.provider, message);
|
|
55
|
+
if (nextPlaying !== undefined) {
|
|
56
|
+
setPlaying(nextPlaying);
|
|
57
|
+
if (nextPlaying && !firstPlayRef.current) {
|
|
58
|
+
firstPlayRef.current = true;
|
|
59
|
+
callbacksRef.current.onFirstPlay?.();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
window.addEventListener('message', handleMessage);
|
|
64
|
+
return () => {
|
|
65
|
+
window.removeEventListener('message', handleMessage);
|
|
66
|
+
};
|
|
67
|
+
}, [source.provider, origin]);
|
|
68
|
+
const handleLoad = () => {
|
|
69
|
+
const target = iframeRef.current?.contentWindow;
|
|
70
|
+
if (source.provider === 'youtube') {
|
|
71
|
+
target?.postMessage(JSON.stringify({ event: 'listening' }), origin);
|
|
72
|
+
target?.postMessage(JSON.stringify({ event: 'command', func: 'addEventListener', args: ['onStateChange'] }), origin);
|
|
73
|
+
target?.postMessage(JSON.stringify({ event: 'command', func: 'addEventListener', args: ['onError'] }), origin);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const handleToggle = () => {
|
|
77
|
+
if (!activated) {
|
|
78
|
+
setActivated(true);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const command = source.provider === 'youtube'
|
|
82
|
+
? { event: 'command', func: playing ? 'pauseVideo' : 'playVideo', args: [] }
|
|
83
|
+
: { type: playing ? 'player:pause' : 'player:play', data: {} };
|
|
84
|
+
iframeRef.current?.contentWindow?.postMessage(JSON.stringify(command), origin);
|
|
85
|
+
};
|
|
86
|
+
const handleError = () => {
|
|
87
|
+
setFailed(true);
|
|
88
|
+
callbacksRef.current.onError?.();
|
|
89
|
+
};
|
|
90
|
+
const handleRetry = () => {
|
|
91
|
+
setFailed(false);
|
|
92
|
+
setPlaying(false);
|
|
93
|
+
setAttempt(value => value + 1);
|
|
94
|
+
};
|
|
95
|
+
const handlePointerEnter = () => {
|
|
96
|
+
setHovered(true);
|
|
97
|
+
};
|
|
98
|
+
const handlePointerLeave = () => {
|
|
99
|
+
setHovered(false);
|
|
100
|
+
};
|
|
101
|
+
return (_jsxs("div", { className: styles.root, "data-test-id": TEST_IDS.player, "data-playing": playing, onPointerEnter: handlePointerEnter, onPointerLeave: handlePointerLeave, children: [activated && (_jsx("iframe", { ref: iframeRef, className: styles.iframe, title: t('player'), src: url.href, allow: 'autoplay; encrypted-media; picture-in-picture; fullscreen', allowFullScreen: true, "data-test-id": TEST_IDS.embed, onLoad: handleLoad, onError: handleError }, attempt)), !activated && poster && _jsx("img", { className: styles.poster, src: poster, alt: '', "data-test-id": TEST_IDS.poster }), failed ? (_jsx(PlayerError, { onRetry: handleRetry })) : (controls && (_jsx(VideoPlayButton, { compact: activated, playing: playing, visible: !activated || !playing || hovered, onClick: handleToggle })))] }));
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EmbedPlayer.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EmbedPlayer.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.root{
|
|
2
|
+
position:absolute;
|
|
3
|
+
inset:0;
|
|
4
|
+
background:var(--sn-theme-color-neutral-background, var(--sn-brand-color-neutral-90, var(--sn-brand-palette-gray-90, #f4f4f4)));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.iframe,
|
|
8
|
+
.poster{
|
|
9
|
+
display:block;
|
|
10
|
+
width:100%;
|
|
11
|
+
height:100%;
|
|
12
|
+
border:0;
|
|
13
|
+
-o-object-fit:cover;
|
|
14
|
+
object-fit:cover;
|
|
15
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { DOUBLE_CLICK_DELAY, SEEK_STEP, TEST_IDS, TOOLBAR_HIDE_DELAY } from '../../constants.js';
|
|
4
|
+
import { useFullscreen } from '../../hooks/useFullscreen.js';
|
|
5
|
+
import { useSpriteFrames } from '../../hooks/useSpriteFrames.js';
|
|
6
|
+
import { siteMediaLocale } from '../../locale/index.js';
|
|
7
|
+
import { PlayerError } from '../PlayerError/index.js';
|
|
8
|
+
import { Toolbar } from '../Toolbar/index.js';
|
|
9
|
+
import { VideoPlayButton } from '../VideoPlayButton/index.js';
|
|
10
|
+
import { useVideoPlayer } from './hooks.js';
|
|
11
|
+
import styles from './styles.module.css';
|
|
12
|
+
export function NativePlayer({ video, onFirstPlay, onError }) {
|
|
13
|
+
const { src, poster, controls = true } = video;
|
|
14
|
+
const { t } = siteMediaLocale.useTranslations();
|
|
15
|
+
const rootRef = useRef(null);
|
|
16
|
+
const clickTimeoutRef = useRef();
|
|
17
|
+
const hideTimeoutRef = useRef();
|
|
18
|
+
const pointerTypeRef = useRef('mouse');
|
|
19
|
+
const [isPointerActive, setIsPointerActive] = useState(false);
|
|
20
|
+
const { mountRef, player, state, hasError, hasStarted, togglePlay, retry, handlePlaybackError } = useVideoPlayer({
|
|
21
|
+
video,
|
|
22
|
+
onFirstPlay,
|
|
23
|
+
onError,
|
|
24
|
+
});
|
|
25
|
+
const frames = useSpriteFrames(src, controls);
|
|
26
|
+
const { isFullscreen, toggleFullscreen } = useFullscreen(rootRef, player);
|
|
27
|
+
useEffect(() => () => {
|
|
28
|
+
clearTimeout(clickTimeoutRef.current);
|
|
29
|
+
clearTimeout(hideTimeoutRef.current);
|
|
30
|
+
}, []);
|
|
31
|
+
const showToolbar = () => {
|
|
32
|
+
setIsPointerActive(true);
|
|
33
|
+
clearTimeout(hideTimeoutRef.current);
|
|
34
|
+
hideTimeoutRef.current = setTimeout(() => {
|
|
35
|
+
setIsPointerActive(false);
|
|
36
|
+
}, TOOLBAR_HIDE_DELAY);
|
|
37
|
+
};
|
|
38
|
+
const handleClick = (event) => {
|
|
39
|
+
if (event.detail === 0) {
|
|
40
|
+
togglePlay();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (clickTimeoutRef.current) {
|
|
44
|
+
clearTimeout(clickTimeoutRef.current);
|
|
45
|
+
clickTimeoutRef.current = undefined;
|
|
46
|
+
toggleFullscreen();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const revealOnly = pointerTypeRef.current !== 'mouse' && state.isPlaying && !isPointerActive;
|
|
50
|
+
clickTimeoutRef.current = setTimeout(() => {
|
|
51
|
+
clickTimeoutRef.current = undefined;
|
|
52
|
+
if (revealOnly) {
|
|
53
|
+
showToolbar();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
togglePlay();
|
|
57
|
+
}
|
|
58
|
+
}, DOUBLE_CLICK_DELAY);
|
|
59
|
+
};
|
|
60
|
+
const handlePointerActivity = (event) => {
|
|
61
|
+
pointerTypeRef.current = event.pointerType;
|
|
62
|
+
if (event.pointerType === 'mouse' || isPointerActive) {
|
|
63
|
+
showToolbar();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const handlePointerLeave = (event) => {
|
|
67
|
+
if (event.pointerType === 'mouse') {
|
|
68
|
+
setIsPointerActive(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const handleKeyDown = (event) => {
|
|
72
|
+
if (!player) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
switch (event.key.toLowerCase()) {
|
|
76
|
+
case 'k':
|
|
77
|
+
togglePlay();
|
|
78
|
+
break;
|
|
79
|
+
case 'arrowleft':
|
|
80
|
+
player.currentTime(Math.max(0, state.currentTime - SEEK_STEP));
|
|
81
|
+
break;
|
|
82
|
+
case 'arrowright':
|
|
83
|
+
player.currentTime(state.duration ? Math.min(state.duration, state.currentTime + SEEK_STEP) : state.currentTime);
|
|
84
|
+
break;
|
|
85
|
+
case 'm':
|
|
86
|
+
player.muted(!player.muted());
|
|
87
|
+
break;
|
|
88
|
+
case 'f':
|
|
89
|
+
toggleFullscreen();
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
};
|
|
96
|
+
const visible = !state.isPlaying || isPointerActive;
|
|
97
|
+
return (_jsxs("div", { ref: rootRef, className: styles.root, role: 'region', "aria-label": t('player'), "aria-busy": !player && !hasError, "data-test-id": TEST_IDS.player, "data-playing": state.isPlaying, onPointerDown: handlePointerActivity, onPointerMove: handlePointerActivity, onPointerLeave: handlePointerLeave, onContextMenu: event => {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
}, children: [_jsx("div", { ref: mountRef, className: styles.mount, "data-test-id": TEST_IDS.mount }), !hasStarted && poster && _jsx("img", { className: styles.poster, src: poster, alt: '', "data-test-id": TEST_IDS.poster }), hasError ? (_jsx(PlayerError, { onRetry: retry })) : (controls && (_jsxs(_Fragment, { children: [_jsx(VideoPlayButton, { playing: state.isPlaying, visible: visible, onClick: handleClick, onKeyDown: handleKeyDown }), player && hasStarted && (_jsx(Toolbar, { player: player, state: state, frames: frames, visible: visible, fullscreen: isFullscreen, onTogglePlay: togglePlay, onToggleFullscreen: toggleFullscreen, onPlaybackError: handlePlaybackError }))] })))] }));
|
|
100
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Player from 'video.js/dist/types/player';
|
|
2
|
+
import { NativePlayerProps } from './types.js';
|
|
3
|
+
/** Жизненный цикл video.js: создание, готовность, события, повторная попытка и освобождение ресурсов. */
|
|
4
|
+
export declare function useVideoPlayer({ video, onFirstPlay, onError }: NativePlayerProps): {
|
|
5
|
+
mountRef: import("react").RefObject<HTMLDivElement>;
|
|
6
|
+
player: Player | null;
|
|
7
|
+
state: import("../../hooks/usePlayerState").PlayerState;
|
|
8
|
+
hasError: boolean;
|
|
9
|
+
hasStarted: boolean;
|
|
10
|
+
togglePlay: () => void;
|
|
11
|
+
retry: () => void;
|
|
12
|
+
handlePlaybackError: (error: unknown) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { TEST_IDS } from '../../constants.js';
|
|
3
|
+
import { usePlayerState } from '../../hooks/usePlayerState.js';
|
|
4
|
+
import styles from './styles.module.css';
|
|
5
|
+
import { getVideoPlayerOptions, isPlaybackInterrupted } from './utils.js';
|
|
6
|
+
/** Жизненный цикл video.js: создание, готовность, события, повторная попытка и освобождение ресурсов. */
|
|
7
|
+
export function useVideoPlayer({ video, onFirstPlay, onError }) {
|
|
8
|
+
const { src, poster, autoPlay = false, muted = false, loop = false } = video;
|
|
9
|
+
const mountRef = useRef(null);
|
|
10
|
+
const pendingPlayRef = useRef(false);
|
|
11
|
+
const firstPlayRef = useRef(false);
|
|
12
|
+
const errorReportedRef = useRef(false);
|
|
13
|
+
const callbacksRef = useRef({ onFirstPlay, onError });
|
|
14
|
+
callbacksRef.current = { onFirstPlay, onError };
|
|
15
|
+
const [player, setPlayer] = useState(null);
|
|
16
|
+
const [hasError, setHasError] = useState(false);
|
|
17
|
+
const [hasStarted, setHasStarted] = useState(false);
|
|
18
|
+
const [attempt, setAttempt] = useState(0);
|
|
19
|
+
const state = usePlayerState(player);
|
|
20
|
+
const options = useMemo(() => getVideoPlayerOptions({ src, poster, autoPlay, muted, loop }), [src, poster, autoPlay, muted, loop]);
|
|
21
|
+
const handlePlaybackError = useCallback((error) => {
|
|
22
|
+
if (isPlaybackInterrupted(error) || errorReportedRef.current)
|
|
23
|
+
return;
|
|
24
|
+
errorReportedRef.current = true;
|
|
25
|
+
setHasError(true);
|
|
26
|
+
callbacksRef.current.onError?.();
|
|
27
|
+
}, []);
|
|
28
|
+
const handlePlay = useCallback(() => {
|
|
29
|
+
setHasStarted(true);
|
|
30
|
+
if (firstPlayRef.current)
|
|
31
|
+
return;
|
|
32
|
+
firstPlayRef.current = true;
|
|
33
|
+
callbacksRef.current.onFirstPlay?.();
|
|
34
|
+
}, []);
|
|
35
|
+
const handleReady = useCallback((instance) => {
|
|
36
|
+
setPlayer(instance);
|
|
37
|
+
if (!pendingPlayRef.current)
|
|
38
|
+
return;
|
|
39
|
+
pendingPlayRef.current = false;
|
|
40
|
+
instance.play()?.catch(handlePlaybackError);
|
|
41
|
+
}, [handlePlaybackError]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const mount = mountRef.current;
|
|
44
|
+
if (!mount)
|
|
45
|
+
return;
|
|
46
|
+
let disposed = false;
|
|
47
|
+
let instance;
|
|
48
|
+
let element;
|
|
49
|
+
errorReportedRef.current = false;
|
|
50
|
+
setHasError(false);
|
|
51
|
+
setHasStarted(false);
|
|
52
|
+
setPlayer(null);
|
|
53
|
+
const initializePlayer = async () => {
|
|
54
|
+
const { default: videojs } = await import('video.js');
|
|
55
|
+
if (disposed)
|
|
56
|
+
return;
|
|
57
|
+
element = mount.ownerDocument.createElement('video-js');
|
|
58
|
+
element.className = styles.player;
|
|
59
|
+
mount.appendChild(element);
|
|
60
|
+
const createdPlayer = videojs(element, options);
|
|
61
|
+
instance = createdPlayer;
|
|
62
|
+
createdPlayer.on('play', handlePlay);
|
|
63
|
+
createdPlayer.on('error', () => {
|
|
64
|
+
handlePlaybackError(new Error('Media source error'));
|
|
65
|
+
});
|
|
66
|
+
createdPlayer.ready(() => {
|
|
67
|
+
if (disposed)
|
|
68
|
+
return;
|
|
69
|
+
const media = mount.querySelector('video');
|
|
70
|
+
media?.classList.add(styles.media);
|
|
71
|
+
media?.setAttribute('data-test-id', TEST_IDS.nativeVideo);
|
|
72
|
+
handleReady(createdPlayer);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
initializePlayer().catch(error => {
|
|
76
|
+
if (!disposed)
|
|
77
|
+
handlePlaybackError(error);
|
|
78
|
+
});
|
|
79
|
+
return () => {
|
|
80
|
+
disposed = true;
|
|
81
|
+
instance?.dispose();
|
|
82
|
+
element?.remove();
|
|
83
|
+
};
|
|
84
|
+
}, [options, attempt, handlePlay, handleReady, handlePlaybackError]);
|
|
85
|
+
const togglePlay = useCallback(() => {
|
|
86
|
+
if (!player) {
|
|
87
|
+
pendingPlayRef.current = true;
|
|
88
|
+
}
|
|
89
|
+
else if (player.paused()) {
|
|
90
|
+
player.play()?.catch(handlePlaybackError);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
player.pause();
|
|
94
|
+
}
|
|
95
|
+
}, [player, handlePlaybackError]);
|
|
96
|
+
const retry = useCallback(() => {
|
|
97
|
+
pendingPlayRef.current = true;
|
|
98
|
+
setAttempt(value => value + 1);
|
|
99
|
+
}, []);
|
|
100
|
+
return { mountRef, player, state, hasError, hasStarted, togglePlay, retry, handlePlaybackError };
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NativePlayer.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NativePlayer.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
.root{
|
|
2
|
+
position:absolute;
|
|
3
|
+
inset:0;
|
|
4
|
+
overflow:hidden;
|
|
5
|
+
border-radius:inherit;
|
|
6
|
+
}
|
|
7
|
+
.root:fullscreen{
|
|
8
|
+
border-radius:0;
|
|
9
|
+
background:var(--sn-theme-color-neutral-background, var(--sn-brand-color-neutral-90, var(--sn-brand-palette-gray-90, #f4f4f4)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.mount{
|
|
13
|
+
position:absolute;
|
|
14
|
+
inset:0;
|
|
15
|
+
}
|
|
16
|
+
.mount > .player{
|
|
17
|
+
display:block;
|
|
18
|
+
width:100%;
|
|
19
|
+
height:100%;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.media,
|
|
23
|
+
.poster{
|
|
24
|
+
display:block;
|
|
25
|
+
width:100%;
|
|
26
|
+
height:100%;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.media{
|
|
30
|
+
-o-object-fit:contain;
|
|
31
|
+
object-fit:contain;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.poster{
|
|
35
|
+
position:absolute;
|
|
36
|
+
inset:0;
|
|
37
|
+
-o-object-fit:cover;
|
|
38
|
+
object-fit:cover;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VideoPlayerProps } from '../../types.js';
|
|
2
|
+
/** Управление рисует DS; video.js отвечает за загрузку и воспроизведение медиа. */
|
|
3
|
+
export declare function getVideoPlayerOptions({ src, poster, autoPlay, muted, loop, }: VideoPlayerProps): {
|
|
4
|
+
sources: {
|
|
5
|
+
src: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}[];
|
|
8
|
+
poster: string | undefined;
|
|
9
|
+
autoplay: boolean;
|
|
10
|
+
muted: boolean;
|
|
11
|
+
loop: boolean;
|
|
12
|
+
preload: string;
|
|
13
|
+
playsinline: boolean;
|
|
14
|
+
fill: boolean;
|
|
15
|
+
controls: boolean;
|
|
16
|
+
children: string[];
|
|
17
|
+
};
|
|
18
|
+
/** Запрет autoplay и отмена запроса не делают источник недоступным. */
|
|
19
|
+
export declare function isPlaybackInterrupted(error: unknown): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getSourceType } from '../../utils/index.js';
|
|
2
|
+
/** Управление рисует DS; video.js отвечает за загрузку и воспроизведение медиа. */
|
|
3
|
+
export function getVideoPlayerOptions({ src, poster, autoPlay = false, muted = false, loop = false, }) {
|
|
4
|
+
return {
|
|
5
|
+
sources: [{ src, type: getSourceType(src) }],
|
|
6
|
+
poster,
|
|
7
|
+
autoplay: autoPlay,
|
|
8
|
+
muted: muted || autoPlay,
|
|
9
|
+
loop,
|
|
10
|
+
preload: autoPlay ? 'auto' : 'metadata',
|
|
11
|
+
playsinline: true,
|
|
12
|
+
fill: true,
|
|
13
|
+
controls: false,
|
|
14
|
+
children: ['mediaLoader', 'liveTracker'],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Запрет autoplay и отмена запроса не делают источник недоступным. */
|
|
18
|
+
export function isPlaybackInterrupted(error) {
|
|
19
|
+
return error instanceof Error && (error.name === 'NotAllowedError' || error.name === 'AbortError');
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from '@cloud-ru/ds-button';
|
|
3
|
+
import { TEST_IDS } from '../../constants.js';
|
|
4
|
+
import { siteMediaLocale } from '../../locale/index.js';
|
|
5
|
+
import styles from './styles.module.css';
|
|
6
|
+
export function PlayerError({ onRetry }) {
|
|
7
|
+
const { t } = siteMediaLocale.useTranslations();
|
|
8
|
+
return (_jsxs("div", { className: styles.root, role: 'status', "data-test-id": TEST_IDS.error, children: [_jsx("div", { className: styles.title, children: t('errorTitle') }), _jsx("div", { className: styles.description, children: t('errorDescription') }), onRetry && _jsx(Button, { label: t('retry'), onClick: onRetry, "data-test-id": TEST_IDS.retry })] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PlayerError.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PlayerError.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.root{
|
|
2
|
+
position:absolute;
|
|
3
|
+
inset:0;
|
|
4
|
+
display:flex;
|
|
5
|
+
flex-direction:column;
|
|
6
|
+
gap:var(--sn-primitive-dimension-12, 12px);
|
|
7
|
+
align-items:center;
|
|
8
|
+
justify-content:center;
|
|
9
|
+
padding:var(--sn-primitive-dimension-16, 16px);
|
|
10
|
+
color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #000000));
|
|
11
|
+
text-align:center;
|
|
12
|
+
background:var(--sn-theme-color-neutral-background, var(--sn-brand-color-neutral-90, var(--sn-brand-palette-gray-90, #f4f4f4)));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.title{
|
|
16
|
+
font-family:var(--sn-regular-title-m-fontFamily, var(--sn-brand-font-fontFamily-regular-title, SB Sans Text));
|
|
17
|
+
font-weight:var(--sn-regular-title-m-fontWeight, var(--sn-theme-typography-fontWeight-regular-title-m, var(--sn-brand-font-fontWeight-light-regular-title-m, var(--sn-primitive-font-fontWeightValue-500, 500))));
|
|
18
|
+
line-height:var(--sn-regular-title-m-lineHeight, var(--sn-density-typography-roleTitle-lineHeightM, var(--sn-platform-comfort-typography-roleTitle-lineHeightM, var(--sn-primitive-font-lineHeight-24, 24px))));
|
|
19
|
+
font-size:var(--sn-regular-title-m-fontSize, var(--sn-density-typography-roleTitle-fontSizeM, var(--sn-platform-comfort-typography-roleTitle-fontSizeM, var(--sn-primitive-font-fontSize-16, 16px))));
|
|
20
|
+
letter-spacing:var(--sn-regular-title-m-letterSpacing, var(--sn-primitive-font-letterSpacing-l, 0.15px));
|
|
21
|
+
paragraph-spacing:var(--sn-regular-title-m-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize16, 8px));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.description{
|
|
25
|
+
color:var(--sn-theme-color-available-version-textSecondary, var(--sn-brand-color-text-version-secondary, rgba(0, 0, 0, 0.7803921569)));
|
|
26
|
+
font-family:var(--sn-regular-body-s-fontFamily, var(--sn-brand-font-fontFamily-regular-body, SB Sans Text));
|
|
27
|
+
font-weight:var(--sn-regular-body-s-fontWeight, var(--sn-theme-typography-fontWeight-regular-body-s, var(--sn-brand-font-fontWeight-light-regular-body-s, var(--sn-primitive-font-fontWeightValue-400, 400))));
|
|
28
|
+
line-height:var(--sn-regular-body-s-lineHeight, var(--sn-density-typography-roleBody-lineHeightS, var(--sn-platform-comfort-typography-roleBody-lineHeightS, var(--sn-primitive-font-lineHeight-20, 20px))));
|
|
29
|
+
font-size:var(--sn-regular-body-s-fontSize, var(--sn-density-typography-roleBody-fontSizeS, var(--sn-platform-comfort-typography-roleBody-fontSizeS, var(--sn-primitive-font-fontSize-14, 14px))));
|
|
30
|
+
letter-spacing:var(--sn-regular-body-s-letterSpacing, var(--sn-primitive-font-letterSpacing-m, 0.1px));
|
|
31
|
+
paragraph-spacing:var(--sn-regular-body-s-paragraphSpacing, var(--sn-primitive-font-paragraphSpacing-byFontSize12, 6px));
|
|
32
|
+
}
|