Skip to content

Commit

Permalink
COLUMBIA: Convert VideoJSViewer to a functional component
Browse files Browse the repository at this point in the history
- correct a propType validation on audio viewer
  • Loading branch information
barmintor committed Feb 12, 2025
1 parent 785b9a3 commit f6209f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/culPlugins/mirador-videojs/components/VideoJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import videojs from 'video.js';
import 'video.js/dist/video-js.css';

/** */
export const VideoJS = ({ options = {}, onReady }) => {
export const VideoJS = ({ options = {}, onReady = null }) => {
const videoRef = React.useRef(null);
const playerRef = React.useRef(null);

Expand Down Expand Up @@ -53,7 +53,7 @@ export const VideoJS = ({ options = {}, onReady }) => {
export default VideoJS;

VideoJS.propTypes = {
onReady: PropTypes.func.isRequired,
onReady: PropTypes.func,
options: PropTypes.shape({
autoplay: PropTypes.bool,
sources: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
Expand Down
50 changes: 25 additions & 25 deletions src/culPlugins/mirador-videojs/components/VideoJSViewer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { connect } from 'react-redux';
import { compose } from 'redux';
import { withTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { VideoViewer } from '../../../components/VideoViewer';
import { getConfig, getVisibleCanvasCaptions, getVisibleCanvasVideoResources } from '../../../state/selectors';

Expand All @@ -22,36 +23,35 @@ const enhance = compose(
);

/** */
class VideoJSViewerBase extends VideoViewer {
/** */
render() {
const {
captions, videoOptions, videoResources,
} = this.props;
function VideoJSViewerBase({ captions, videoOptions, videoResources }) {
const videoJsOptions = {
...videoOptions,
autoplay: false,
controlBar: {
remainingTimeDisplay: false,
},
controls: true,
fill: true,
playbackRates: [0.5, 1, 1.5, 2],
responsive: true,
sources: videoResources.filter(video => video.id && video.getFormat()).map(
video => ({ src: video.id, type: video.getFormat() }),
),
tracks: captions.filter(caption => caption.id).map(caption => ({ kind: (caption.kind || 'captions'), src: caption.id })),
};

const videoJsOptions = {
...videoOptions,
autoplay: false,
controlBar: {
remainingTimeDisplay: false,
},
controls: true,
fill: true,
playbackRates: [0.5, 1, 1.5, 2],
responsive: true,
sources: videoResources.filter(video => video.id && video.getFormat()).map(
video => ({ src: video.id, type: video.getFormat() }),
),
tracks: captions.filter(caption => caption.id).map(caption => ({ kind: (caption.kind || 'captions'), src: caption.id })),
};

if (videoJsOptions.sources.length === 0) return <ForbiddenComponent id="this content" />;
return <VideoJS options={videoJsOptions} />;
}
if (videoJsOptions.sources.length === 0) return <ForbiddenComponent id="this content" />;
return <VideoJS options={videoJsOptions} />;
}

export const VideoJSViewer = enhance(VideoJSViewerBase);
/** */
const VideoJSViewerPlugin = ({ targetProps }) => (<VideoJSViewer {...targetProps} />); // eslint-disable-line react/prop-types
/** */
export default VideoJSViewerPlugin;

VideoJSViewerBase.propTypes = {
captions: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
videoOptions: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
videoResources: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types
};

0 comments on commit f6209f2

Please sign in to comment.