@ldelia/react-media 0.5.11 → 0.6.1
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/dist/components/reproduction-widget/ReproductionWidget.d.ts +3 -1
- package/dist/components/reproduction-widget/ReproductionWidget.js +2 -2
- package/dist/components/reproduction-widget/inner-players/YouTubeInnerPlayer.d.ts +2 -1
- package/dist/components/reproduction-widget/inner-players/YouTubeInnerPlayer.js +44 -10
- package/dist/components/reproduction-widget/models/ReproductionBuilder.d.ts +1 -1
- package/dist/stories/reproduction-widget.stories.d.ts +4 -3
- package/dist/stories/reproduction-widget.stories.js +11 -3
- package/dist/stories/timeline.stories.d.ts +7 -7
- package/package.json +15 -15
|
@@ -10,12 +10,14 @@ interface TrainingProps extends BaseProps {
|
|
|
10
10
|
trainingMode: true;
|
|
11
11
|
duration?: never;
|
|
12
12
|
videoId: string;
|
|
13
|
+
onVideoUnavailable: () => void;
|
|
13
14
|
}
|
|
14
15
|
interface NonTrainingProps extends BaseProps {
|
|
15
16
|
trainingMode: false;
|
|
16
17
|
duration: number;
|
|
17
18
|
videoId?: never;
|
|
19
|
+
onVideoUnavailable?: never;
|
|
18
20
|
}
|
|
19
21
|
export type ReproductionWidgetProps = TrainingProps | NonTrainingProps;
|
|
20
|
-
export declare const ReproductionWidget: ({ trainingMode, duration, videoId, withCountingIn, songTempo, onInit, }: ReproductionWidgetProps) => React.JSX.Element;
|
|
22
|
+
export declare const ReproductionWidget: ({ trainingMode, duration, videoId, withCountingIn, songTempo, onInit, onVideoUnavailable, }: ReproductionWidgetProps) => React.JSX.Element;
|
|
21
23
|
export {};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { YouTubeInnerPlayer } from './inner-players/YouTubeInnerPlayer';
|
|
3
3
|
import { PlayAlongInnerPlayer } from './inner-players/PlayAlongInnerPlayer';
|
|
4
4
|
import { Reproduction } from './models/Reproduction';
|
|
5
|
-
export const ReproductionWidget = ({ trainingMode, duration, videoId, withCountingIn = true, songTempo = 0, onInit, }) => {
|
|
5
|
+
export const ReproductionWidget = ({ trainingMode, duration, videoId, withCountingIn = true, songTempo = 0, onInit, onVideoUnavailable, }) => {
|
|
6
6
|
function onPlayAlongInnerPlayerReadyHandler(event) {
|
|
7
7
|
let newReproduction = Reproduction.newBuilder()
|
|
8
8
|
.withTrainingMode(false)
|
|
@@ -22,5 +22,5 @@ export const ReproductionWidget = ({ trainingMode, duration, videoId, withCounti
|
|
|
22
22
|
.createReproduction();
|
|
23
23
|
onInit(newReproduction);
|
|
24
24
|
}
|
|
25
|
-
return (React.createElement(React.Fragment, null, trainingMode ? (React.createElement(YouTubeInnerPlayer, { videoId: videoId, onReady: onYouTubeInnerPlayerReadyHandler })) : (React.createElement(PlayAlongInnerPlayer, { onReady: onPlayAlongInnerPlayerReadyHandler }))));
|
|
25
|
+
return (React.createElement(React.Fragment, null, trainingMode ? (React.createElement(YouTubeInnerPlayer, { videoId: videoId, onReady: onYouTubeInnerPlayerReadyHandler, onVideoUnavailable: onVideoUnavailable })) : (React.createElement(PlayAlongInnerPlayer, { onReady: onPlayAlongInnerPlayerReadyHandler }))));
|
|
26
26
|
};
|
|
@@ -5,6 +5,7 @@ interface Props {
|
|
|
5
5
|
onReady: (event: {
|
|
6
6
|
target: InnerYouTubePlayerInterface;
|
|
7
7
|
}) => void;
|
|
8
|
+
onVideoUnavailable: () => void;
|
|
8
9
|
}
|
|
9
|
-
export declare const YouTubeInnerPlayer: ({ videoId, onReady }: Props) => React.JSX.Element;
|
|
10
|
+
export declare const YouTubeInnerPlayer: ({ videoId, onReady, onVideoUnavailable }: Props) => React.JSX.Element;
|
|
10
11
|
export {};
|
|
@@ -1,13 +1,47 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
2
|
import ReactPlayer from 'react-player/lazy';
|
|
3
|
-
export const YouTubeInnerPlayer = ({ videoId, onReady }) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export const YouTubeInnerPlayer = ({ videoId, onReady, onVideoUnavailable }) => {
|
|
4
|
+
const hasErrorRef = useRef(false);
|
|
5
|
+
const readyTimeoutRef = useRef(null);
|
|
6
|
+
/**
|
|
7
|
+
* When the video is unavailable, the player will throw both, the onError and onReady events.
|
|
8
|
+
* We delay calling onReady to give time for onError to potentially fire.
|
|
9
|
+
*/
|
|
10
|
+
const handleReady = (event) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const internalPlayer = event.getInternalPlayer();
|
|
13
|
+
const iframe = (_a = internalPlayer.getIframe) === null || _a === void 0 ? void 0 : _a.call(internalPlayer);
|
|
14
|
+
if (iframe)
|
|
9
15
|
iframe.tabIndex = -1;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
readyTimeoutRef.current = setTimeout(() => {
|
|
17
|
+
if (!hasErrorRef.current) {
|
|
18
|
+
onReady({ target: internalPlayer });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.warn("YouTubeInnerPlayer onReady suppressed due to error");
|
|
22
|
+
}
|
|
23
|
+
}, 300);
|
|
24
|
+
};
|
|
25
|
+
const handleError = (error, data) => {
|
|
26
|
+
hasErrorRef.current = true;
|
|
27
|
+
if (readyTimeoutRef.current) {
|
|
28
|
+
clearTimeout(readyTimeoutRef.current);
|
|
29
|
+
readyTimeoutRef.current = null;
|
|
30
|
+
}
|
|
31
|
+
if (error === 150) {
|
|
32
|
+
onVideoUnavailable();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.warn('Unhandled YouTube error:', error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// Reset refs when videoId changes
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
hasErrorRef.current = false;
|
|
41
|
+
if (readyTimeoutRef.current) {
|
|
42
|
+
clearTimeout(readyTimeoutRef.current);
|
|
43
|
+
readyTimeoutRef.current = null;
|
|
44
|
+
}
|
|
45
|
+
}, [videoId]);
|
|
46
|
+
return (React.createElement(ReactPlayer, { url: `https://www.youtube.com/watch?v=${videoId}`, onReady: handleReady, onError: handleError }));
|
|
13
47
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReproductionWidgetProps } from '../components/reproduction-widget';
|
|
2
|
-
declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react/dist/types-
|
|
2
|
+
declare const _default: import("@storybook/core/csf").ComponentAnnotations<import("@storybook/react/dist/types-5617c98e").R, import("@storybook/core/csf").Args>;
|
|
3
3
|
export default _default;
|
|
4
|
-
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
5
|
-
export declare const PlayAlong: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
4
|
+
export declare const Default: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, ReproductionWidgetProps>;
|
|
5
|
+
export declare const PlayAlong: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, ReproductionWidgetProps>;
|
|
6
|
+
export declare const InvalidVideo: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, ReproductionWidgetProps>;
|
|
@@ -12,7 +12,7 @@ const Template = (args) => {
|
|
|
12
12
|
const [reproductionTimestamp, setReproductionTimestamp] = useState(0);
|
|
13
13
|
// Handle initialization of reproduction
|
|
14
14
|
const handleInit = useCallback((reproductionInstance) => {
|
|
15
|
-
const refreshEvent = (args) => { setReproductionTimestamp(new Date().getTime());
|
|
15
|
+
const refreshEvent = (args) => { setReproductionTimestamp(new Date().getTime()); };
|
|
16
16
|
setReproduction(reproductionInstance);
|
|
17
17
|
reproductionInstance.on('COUNTING_IN', (args) => { console.log("counting in", args); });
|
|
18
18
|
reproductionInstance.on('PLAYING', refreshEvent);
|
|
@@ -41,8 +41,9 @@ const Template = (args) => {
|
|
|
41
41
|
React.createElement("button", { onClick: handleStop, disabled: !reproduction || reproduction.isStopped() }, "Stop"),
|
|
42
42
|
React.createElement("button", { onClick: handlePause, disabled: !reproduction || !reproduction.isPlaying() }, "Pause"),
|
|
43
43
|
React.createElement("button", { onClick: handleResume, disabled: !reproduction || reproduction.isPlaying() }, "Resume"),
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
reproduction && (React.createElement("div", null,
|
|
45
|
+
"Current time: ", reproduction === null || reproduction === void 0 ? void 0 :
|
|
46
|
+
reproduction.getCurrentTime())))));
|
|
46
47
|
};
|
|
47
48
|
export const Default = Template.bind({});
|
|
48
49
|
Default.args = {
|
|
@@ -56,3 +57,10 @@ PlayAlong.args = {
|
|
|
56
57
|
songTempo: 180,
|
|
57
58
|
duration: 220,
|
|
58
59
|
};
|
|
60
|
+
export const InvalidVideo = Template.bind({});
|
|
61
|
+
InvalidVideo.args = {
|
|
62
|
+
trainingMode: true,
|
|
63
|
+
videoId: 'Y8jDVJrOHvo',
|
|
64
|
+
songTempo: 180,
|
|
65
|
+
onVideoUnavailable: () => console.error('Video unavailable'),
|
|
66
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TimelineProps } from '../components/timeline';
|
|
2
2
|
import './timeline.stories.custom.css';
|
|
3
|
-
declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react/dist/types-
|
|
3
|
+
declare const _default: import("@storybook/core/csf").ComponentAnnotations<import("@storybook/react/dist/types-5617c98e").R, import("@storybook/core/csf").Args>;
|
|
4
4
|
export default _default;
|
|
5
|
-
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
6
|
-
export declare const WithSelectedRange: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
7
|
-
export declare const WithCustomClassName: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
8
|
-
export declare const WithoutTimeBlocks: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
9
|
-
export declare const Minimalist: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
10
|
-
export declare const WithSelectedRangeAndMarkers: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-
|
|
5
|
+
export declare const Default: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
|
6
|
+
export declare const WithSelectedRange: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
|
7
|
+
export declare const WithCustomClassName: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
|
8
|
+
export declare const WithoutTimeBlocks: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
|
9
|
+
export declare const Minimalist: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
|
10
|
+
export declare const WithSelectedRangeAndMarkers: import("@storybook/core/csf").AnnotatedStoryFn<import("@storybook/react/dist/types-5617c98e").R, TimelineProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldelia/react-media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A React components collection for media-related features.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -114,20 +114,20 @@
|
|
|
114
114
|
"@babel/preset-env": "^7.24.8",
|
|
115
115
|
"@babel/preset-react": "^7.24.7",
|
|
116
116
|
"@babel/preset-typescript": "^7.24.7",
|
|
117
|
-
"@chromatic-com/storybook": "^3.2.
|
|
118
|
-
"@storybook/addon-actions": "^8.
|
|
119
|
-
"@storybook/addon-docs": "^8.
|
|
120
|
-
"@storybook/addon-essentials": "^8.
|
|
121
|
-
"@storybook/addon-interactions": "^8.
|
|
117
|
+
"@chromatic-com/storybook": "^3.2.6",
|
|
118
|
+
"@storybook/addon-actions": "^8.6.12",
|
|
119
|
+
"@storybook/addon-docs": "^8.6.12",
|
|
120
|
+
"@storybook/addon-essentials": "^8.6.12",
|
|
121
|
+
"@storybook/addon-interactions": "^8.6.12",
|
|
122
122
|
"@storybook/addon-knobs": "^8.0.1",
|
|
123
|
-
"@storybook/addon-links": "^8.
|
|
124
|
-
"@storybook/addon-onboarding": "^8.
|
|
125
|
-
"@storybook/blocks": "^8.
|
|
126
|
-
"@storybook/node-logger": "^8.
|
|
127
|
-
"@storybook/react": "^8.
|
|
123
|
+
"@storybook/addon-links": "^8.6.12",
|
|
124
|
+
"@storybook/addon-onboarding": "^8.6.12",
|
|
125
|
+
"@storybook/blocks": "^8.6.12",
|
|
126
|
+
"@storybook/node-logger": "^8.6.12",
|
|
127
|
+
"@storybook/react": "^8.6.12",
|
|
128
128
|
"@storybook/react-docgen-typescript-plugin": "^1.0.6--canary.9.0c3f3b7.0",
|
|
129
|
-
"@storybook/react-webpack5": "^8.
|
|
130
|
-
"@storybook/test": "^8.
|
|
129
|
+
"@storybook/react-webpack5": "^8.6.12",
|
|
130
|
+
"@storybook/test": "^8.6.12",
|
|
131
131
|
"@testing-library/jest-dom": "^6.4.6",
|
|
132
132
|
"@testing-library/react": "^16.0.0",
|
|
133
133
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -140,14 +140,14 @@
|
|
|
140
140
|
"babel-loader": "^9.1.3",
|
|
141
141
|
"eslint-config-prettier": "^9.1.0",
|
|
142
142
|
"eslint-plugin-prettier": "^5.1.3",
|
|
143
|
-
"eslint-plugin-storybook": "^0.
|
|
143
|
+
"eslint-plugin-storybook": "^0.12.0",
|
|
144
144
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
145
145
|
"postcss-normalize": "^10.0.1",
|
|
146
146
|
"postcss-preset-env": "^9.5.14",
|
|
147
147
|
"prettier": "^3.3.2",
|
|
148
148
|
"prop-types": "^15.8.1",
|
|
149
149
|
"react-docgen-typescript-plugin": "^1.0.8",
|
|
150
|
-
"storybook": "^8.
|
|
150
|
+
"storybook": "^8.6.12",
|
|
151
151
|
"ts-loader": "^9.5.1",
|
|
152
152
|
"tsconfig-paths-webpack-plugin": "^4.1.0",
|
|
153
153
|
"webpack": "^5.92.0"
|