react-hook-videojs 2.0.1 → 3.0.0-rc.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/index.d.ts +12 -0
- package/dist/react-hook-videojs.es.js +70 -0
- package/dist/react-hook-videojs.es.js.map +1 -0
- package/dist/react-hook-videojs.umd.js +74 -0
- package/dist/react-hook-videojs.umd.js.map +1 -0
- package/package.json +37 -33
- package/LICENSE +0 -21
- package/README.md +0 -31
- package/dist/index.js +0 -37
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -34
- package/dist/index.modern.js.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { HTMLProps } from "react";
|
|
2
|
+
import { VideoJsPlayer, VideoJsPlayerOptions } from "video.js";
|
|
3
|
+
declare type VideoProps = {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
} & Partial<HTMLProps<HTMLVideoElement>>;
|
|
6
|
+
declare type VideoType = (props: VideoProps) => JSX.Element;
|
|
7
|
+
export declare const useVideoJS: (videoJsOptions: VideoJsPlayerOptions, classNames?: string) => {
|
|
8
|
+
Video: VideoType;
|
|
9
|
+
ready: boolean;
|
|
10
|
+
player: VideoJsPlayer | null;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useLayoutEffect, useState, useCallback } from "react";
|
|
2
|
+
import videojs from "video.js";
|
|
3
|
+
import cloneDeep from "lodash.clonedeep";
|
|
4
|
+
import { dequal } from "dequal";
|
|
5
|
+
function useDeepCompareMemoize(value) {
|
|
6
|
+
const ref = React.useRef(value);
|
|
7
|
+
const signalRef = React.useRef(0);
|
|
8
|
+
if (!dequal(value, ref.current)) {
|
|
9
|
+
ref.current = value;
|
|
10
|
+
signalRef.current += 1;
|
|
11
|
+
}
|
|
12
|
+
return React.useMemo(() => ref.current, [signalRef.current]);
|
|
13
|
+
}
|
|
14
|
+
const VideoJsWrapper = forwardRef(({ children, videoJsOptions, onReady, onDispose, classNames, ...props }, playerRef) => {
|
|
15
|
+
const player = playerRef;
|
|
16
|
+
const videoJsOptionsCloned = cloneDeep(videoJsOptions);
|
|
17
|
+
const videoNode = useRef(null);
|
|
18
|
+
const containerRef = useRef(null);
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
var _a;
|
|
21
|
+
if (!((_a = videoNode.current) == null ? void 0 : _a.parentNode))
|
|
22
|
+
return;
|
|
23
|
+
const originalVideoNodeParent = videoNode.current.parentNode.cloneNode(true);
|
|
24
|
+
if (!player.current) {
|
|
25
|
+
player.current = videojs(videoNode.current, videoJsOptionsCloned);
|
|
26
|
+
player.current.ready(() => {
|
|
27
|
+
onReady();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
var _a2;
|
|
32
|
+
if (player.current) {
|
|
33
|
+
player.current.dispose();
|
|
34
|
+
if (containerRef.current && ((_a2 = videoNode.current) == null ? void 0 : _a2.parentNode) && !containerRef.current.contains(videoNode.current.parentNode)) {
|
|
35
|
+
containerRef.current.appendChild(originalVideoNodeParent);
|
|
36
|
+
videoNode.current = originalVideoNodeParent.firstChild;
|
|
37
|
+
}
|
|
38
|
+
player.current = null;
|
|
39
|
+
onDispose();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, [useDeepCompareMemoize(videoJsOptions)]);
|
|
43
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
44
|
+
ref: containerRef
|
|
45
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
46
|
+
"data-vjs-player": true
|
|
47
|
+
}, /* @__PURE__ */ React.createElement("video", {
|
|
48
|
+
ref: videoNode,
|
|
49
|
+
className: `video-js ${classNames}`,
|
|
50
|
+
...props
|
|
51
|
+
}, children)));
|
|
52
|
+
});
|
|
53
|
+
VideoJsWrapper.displayName = "VideoJsWrapper";
|
|
54
|
+
const useVideoJS = (videoJsOptions, classNames = "") => {
|
|
55
|
+
const [ready, setReady] = useState(false);
|
|
56
|
+
const player = useRef(null);
|
|
57
|
+
const Video = useCallback(({ children, ...props }) => /* @__PURE__ */ React.createElement(VideoJsWrapper, {
|
|
58
|
+
videoJsOptions,
|
|
59
|
+
classNames,
|
|
60
|
+
onReady: () => setReady(true),
|
|
61
|
+
onDispose: () => setReady(false),
|
|
62
|
+
...props,
|
|
63
|
+
ref: player
|
|
64
|
+
}, children), [useDeepCompareMemoize(videoJsOptions), classNames]);
|
|
65
|
+
return { Video, ready, player: player.current };
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
useVideoJS
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=react-hook-videojs.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-hook-videojs.es.js","sources":["../src/index.tsx"],"sourcesContent":["import React, {\n useRef,\n useState,\n useLayoutEffect,\n useCallback,\n forwardRef,\n HTMLProps,\n MutableRefObject,\n} from \"react\";\nimport videojs, { VideoJsPlayer, VideoJsPlayerOptions } from \"video.js\";\nimport cloneDeep from \"lodash.clonedeep\";\nimport { dequal } from \"dequal\";\n\n// Function copied from\n// https://github.com/kentcdodds/use-deep-compare-effect/blob/main/src/index.ts\nfunction useDeepCompareMemoize<T>(value: T): T {\n const ref = React.useRef<T>(value);\n const signalRef = React.useRef<number>(0);\n\n if (!dequal(value, ref.current)) {\n ref.current = value;\n signalRef.current += 1;\n }\n\n return React.useMemo(() => ref.current, [signalRef.current]);\n}\n\n// Integrating React and video.js is a bit tricky, especially when supporting\n// React 18 strict mode. We'll do our best to explain what happens in inline comments.\n\nconst VideoJsWrapper = forwardRef<\n VideoJsPlayer,\n {\n children: React.ReactNode;\n videoJsOptions: VideoJsPlayerOptions;\n onReady: () => void;\n onDispose: () => void;\n classNames: string;\n }\n>(\n (\n { children, videoJsOptions, onReady, onDispose, classNames, ...props },\n playerRef\n ) => {\n const player = playerRef as MutableRefObject<VideoJsPlayer | null>;\n // video.js sometimes mutates the provided options object.\n // We clone it to avoid mutation issues.\n const videoJsOptionsCloned = cloneDeep(videoJsOptions);\n const videoNode = useRef<HTMLVideoElement | null>(null);\n const containerRef = useRef<HTMLDivElement | null>(null);\n\n useLayoutEffect(() => {\n if (!videoNode.current?.parentNode) return;\n\n // Once we initialize the player, videojs will start mutating the DOM.\n // We need a snapshot of the state just before, so we know what state\n // to reset the DOM to.\n const originalVideoNodeParent =\n videoNode.current.parentNode.cloneNode(true);\n\n if (!player.current) {\n player.current = videojs(videoNode.current, videoJsOptionsCloned);\n player.current.ready(() => {\n onReady();\n });\n }\n\n return (): void => {\n // Whenever something changes in the options object, we\n // want to reinitialize video.js, and destroy the old player by calling `player.current.dispose()`\n\n if (player.current) {\n player.current.dispose();\n\n // Unfortunately, video.js heavily mutates the DOM in a way that React doesn't\n // like, so we need to readd the removed DOM elements directly after dispose.\n // More concretely, the node marked with `data-vjs-player` will be removed from the\n // DOM. We are readding the cloned original video node parent as it was when React first rendered it,\n // so it is once again synchronized with React.\n if (\n containerRef.current &&\n videoNode.current?.parentNode &&\n !containerRef.current.contains(videoNode.current.parentNode)\n ) {\n containerRef.current.appendChild(originalVideoNodeParent);\n videoNode.current =\n originalVideoNodeParent.firstChild as HTMLVideoElement;\n }\n\n player.current = null;\n onDispose();\n }\n };\n\n // We'll use the serialized videoJsOptions object as a dependency object\n }, [useDeepCompareMemoize(videoJsOptions)]);\n\n return (\n // TODO: can we get by withour introducing an extra div?\n <div ref={containerRef}>\n <div data-vjs-player>\n <video\n ref={videoNode}\n className={`video-js ${classNames}`}\n {...props}\n >\n {children}\n </video>\n </div>\n </div>\n );\n }\n);\n\nVideoJsWrapper.displayName = \"VideoJsWrapper\";\n\ntype VideoProps = {\n children?: React.ReactNode;\n} & Partial<HTMLProps<HTMLVideoElement>>;\n\ntype VideoType = (props: VideoProps) => JSX.Element;\n\nexport const useVideoJS = (\n videoJsOptions: VideoJsPlayerOptions,\n classNames = \"\"\n): {\n Video: VideoType;\n ready: boolean;\n player: VideoJsPlayer | null;\n} => {\n const [ready, setReady] = useState(false);\n\n // player will contain the video.js player object, once it is ready.\n const player = useRef<VideoJsPlayer>(null);\n const Video = useCallback(\n ({ children, ...props }: VideoProps) => (\n <VideoJsWrapper\n videoJsOptions={videoJsOptions}\n classNames={classNames}\n onReady={(): void => setReady(true)}\n onDispose={(): void => setReady(false)}\n {...props}\n ref={player}\n >\n {children}\n </VideoJsWrapper>\n ),\n [useDeepCompareMemoize(videoJsOptions), classNames]\n );\n\n return { Video, ready, player: player.current };\n};\n"],"names":[],"mappings":";;;;AAeA,+BAAkC,OAAa;AACvC,QAAA,MAAM,MAAM,OAAU,KAAK;AAC3B,QAAA,YAAY,MAAM,OAAe,CAAC;AAExC,MAAI,CAAC,OAAO,OAAO,IAAI,OAAO,GAAG;AAC/B,QAAI,UAAU;AACd,cAAU,WAAW;AAAA,EACvB;AAEO,SAAA,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,UAAU,OAAO,CAAC;AAC7D;AAKA,MAAM,iBAAiB,WAUrB,CACE,EAAE,UAAU,gBAAgB,SAAS,WAAW,eAAe,SAC/D,cACG;AACH,QAAM,SAAS;AAGT,QAAA,uBAAuB,UAAU,cAAc;AAC/C,QAAA,YAAY,OAAgC,IAAI;AAChD,QAAA,eAAe,OAA8B,IAAI;AAEvD,kBAAgB,MAAM;;AAChB,QAAA,CAAC,iBAAU,YAAV,mBAAmB;AAAY;AAKpC,UAAM,0BACJ,UAAU,QAAQ,WAAW,UAAU,IAAI;AAEzC,QAAA,CAAC,OAAO,SAAS;AACnB,aAAO,UAAU,QAAQ,UAAU,SAAS,oBAAoB;AACzD,aAAA,QAAQ,MAAM,MAAM;AACjB;MAAA,CACT;AAAA,IACH;AAEA,WAAO,MAAY;;AAIjB,UAAI,OAAO,SAAS;AAClB,eAAO,QAAQ;AAOf,YACE,aAAa,WACb,kBAAU,YAAV,oBAAmB,eACnB,CAAC,aAAa,QAAQ,SAAS,UAAU,QAAQ,UAAU,GAC3D;AACa,uBAAA,QAAQ,YAAY,uBAAuB;AACxD,oBAAU,UACR,wBAAwB;AAAA,QAC5B;AAEA,eAAO,UAAU;AACP;MACZ;AAAA,IAAA;AAAA,EAID,GAAA,CAAC,sBAAsB,cAAc,CAAC,CAAC;AAE1C,SAEG,sBAAA,cAAA,OAAA;AAAA,IAAI,KAAK;AAAA,EAAA,GACP,sBAAA,cAAA,OAAA;AAAA,IAAI,mBAAe;AAAA,EAAA,GACjB,sBAAA,cAAA,SAAA;AAAA,IACC,KAAK;AAAA,IACL,WAAW,YAAY;AAAA,IACtB,GAAG;AAAA,EAAA,GAEH,QACH,CACF,CACF;AAEJ,CACF;AAEA,eAAe,cAAc;AAQtB,MAAM,aAAa,CACxB,gBACA,aAAa,OAKV;AACH,QAAM,CAAC,OAAO,YAAY,SAAS,KAAK;AAGlC,QAAA,SAAS,OAAsB,IAAI;AACzC,QAAM,QAAQ,YACZ,CAAC,EAAE,aAAa,YACb,sBAAA,cAAA,gBAAA;AAAA,IACC;AAAA,IACA;AAAA,IACA,SAAS,MAAY,SAAS,IAAI;AAAA,IAClC,WAAW,MAAY,SAAS,KAAK;AAAA,IACpC,GAAG;AAAA,IACJ,KAAK;AAAA,EAAA,GAEJ,QACH,GAEF,CAAC,sBAAsB,cAAc,GAAG,UAAU,CACpD;AAEA,SAAO,EAAE,OAAO,OAAO,QAAQ,OAAO,QAAQ;AAChD;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("video.js"), require("lodash.clonedeep"), require("dequal")) : typeof define === "function" && define.amd ? define(["exports", "react", "video.js", "lodash.clonedeep", "dequal"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["react-hook-videojs"] = {}, global.react, global.video.js, global.lodash.clonedeep, global.dequal));
|
|
3
|
+
})(this, function(exports2, React, videojs, cloneDeep, dequal) {
|
|
4
|
+
"use strict";
|
|
5
|
+
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
6
|
+
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
|
|
7
|
+
const videojs__default = /* @__PURE__ */ _interopDefaultLegacy(videojs);
|
|
8
|
+
const cloneDeep__default = /* @__PURE__ */ _interopDefaultLegacy(cloneDeep);
|
|
9
|
+
function useDeepCompareMemoize(value) {
|
|
10
|
+
const ref = React__default.default.useRef(value);
|
|
11
|
+
const signalRef = React__default.default.useRef(0);
|
|
12
|
+
if (!dequal.dequal(value, ref.current)) {
|
|
13
|
+
ref.current = value;
|
|
14
|
+
signalRef.current += 1;
|
|
15
|
+
}
|
|
16
|
+
return React__default.default.useMemo(() => ref.current, [signalRef.current]);
|
|
17
|
+
}
|
|
18
|
+
const VideoJsWrapper = React.forwardRef(({ children, videoJsOptions, onReady, onDispose, classNames, ...props }, playerRef) => {
|
|
19
|
+
const player = playerRef;
|
|
20
|
+
const videoJsOptionsCloned = cloneDeep__default.default(videoJsOptions);
|
|
21
|
+
const videoNode = React.useRef(null);
|
|
22
|
+
const containerRef = React.useRef(null);
|
|
23
|
+
React.useLayoutEffect(() => {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!((_a = videoNode.current) == null ? void 0 : _a.parentNode))
|
|
26
|
+
return;
|
|
27
|
+
const originalVideoNodeParent = videoNode.current.parentNode.cloneNode(true);
|
|
28
|
+
if (!player.current) {
|
|
29
|
+
player.current = videojs__default.default(videoNode.current, videoJsOptionsCloned);
|
|
30
|
+
player.current.ready(() => {
|
|
31
|
+
onReady();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
var _a2;
|
|
36
|
+
if (player.current) {
|
|
37
|
+
player.current.dispose();
|
|
38
|
+
if (containerRef.current && ((_a2 = videoNode.current) == null ? void 0 : _a2.parentNode) && !containerRef.current.contains(videoNode.current.parentNode)) {
|
|
39
|
+
containerRef.current.appendChild(originalVideoNodeParent);
|
|
40
|
+
videoNode.current = originalVideoNodeParent.firstChild;
|
|
41
|
+
}
|
|
42
|
+
player.current = null;
|
|
43
|
+
onDispose();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}, [useDeepCompareMemoize(videoJsOptions)]);
|
|
47
|
+
return /* @__PURE__ */ React__default.default.createElement("div", {
|
|
48
|
+
ref: containerRef
|
|
49
|
+
}, /* @__PURE__ */ React__default.default.createElement("div", {
|
|
50
|
+
"data-vjs-player": true
|
|
51
|
+
}, /* @__PURE__ */ React__default.default.createElement("video", {
|
|
52
|
+
ref: videoNode,
|
|
53
|
+
className: `video-js ${classNames}`,
|
|
54
|
+
...props
|
|
55
|
+
}, children)));
|
|
56
|
+
});
|
|
57
|
+
VideoJsWrapper.displayName = "VideoJsWrapper";
|
|
58
|
+
const useVideoJS = (videoJsOptions, classNames = "") => {
|
|
59
|
+
const [ready, setReady] = React.useState(false);
|
|
60
|
+
const player = React.useRef(null);
|
|
61
|
+
const Video = React.useCallback(({ children, ...props }) => /* @__PURE__ */ React__default.default.createElement(VideoJsWrapper, {
|
|
62
|
+
videoJsOptions,
|
|
63
|
+
classNames,
|
|
64
|
+
onReady: () => setReady(true),
|
|
65
|
+
onDispose: () => setReady(false),
|
|
66
|
+
...props,
|
|
67
|
+
ref: player
|
|
68
|
+
}, children), [useDeepCompareMemoize(videoJsOptions), classNames]);
|
|
69
|
+
return { Video, ready, player: player.current };
|
|
70
|
+
};
|
|
71
|
+
exports2.useVideoJS = useVideoJS;
|
|
72
|
+
Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=react-hook-videojs.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-hook-videojs.umd.js","sources":["../src/index.tsx"],"sourcesContent":["import React, {\n useRef,\n useState,\n useLayoutEffect,\n useCallback,\n forwardRef,\n HTMLProps,\n MutableRefObject,\n} from \"react\";\nimport videojs, { VideoJsPlayer, VideoJsPlayerOptions } from \"video.js\";\nimport cloneDeep from \"lodash.clonedeep\";\nimport { dequal } from \"dequal\";\n\n// Function copied from\n// https://github.com/kentcdodds/use-deep-compare-effect/blob/main/src/index.ts\nfunction useDeepCompareMemoize<T>(value: T): T {\n const ref = React.useRef<T>(value);\n const signalRef = React.useRef<number>(0);\n\n if (!dequal(value, ref.current)) {\n ref.current = value;\n signalRef.current += 1;\n }\n\n return React.useMemo(() => ref.current, [signalRef.current]);\n}\n\n// Integrating React and video.js is a bit tricky, especially when supporting\n// React 18 strict mode. We'll do our best to explain what happens in inline comments.\n\nconst VideoJsWrapper = forwardRef<\n VideoJsPlayer,\n {\n children: React.ReactNode;\n videoJsOptions: VideoJsPlayerOptions;\n onReady: () => void;\n onDispose: () => void;\n classNames: string;\n }\n>(\n (\n { children, videoJsOptions, onReady, onDispose, classNames, ...props },\n playerRef\n ) => {\n const player = playerRef as MutableRefObject<VideoJsPlayer | null>;\n // video.js sometimes mutates the provided options object.\n // We clone it to avoid mutation issues.\n const videoJsOptionsCloned = cloneDeep(videoJsOptions);\n const videoNode = useRef<HTMLVideoElement | null>(null);\n const containerRef = useRef<HTMLDivElement | null>(null);\n\n useLayoutEffect(() => {\n if (!videoNode.current?.parentNode) return;\n\n // Once we initialize the player, videojs will start mutating the DOM.\n // We need a snapshot of the state just before, so we know what state\n // to reset the DOM to.\n const originalVideoNodeParent =\n videoNode.current.parentNode.cloneNode(true);\n\n if (!player.current) {\n player.current = videojs(videoNode.current, videoJsOptionsCloned);\n player.current.ready(() => {\n onReady();\n });\n }\n\n return (): void => {\n // Whenever something changes in the options object, we\n // want to reinitialize video.js, and destroy the old player by calling `player.current.dispose()`\n\n if (player.current) {\n player.current.dispose();\n\n // Unfortunately, video.js heavily mutates the DOM in a way that React doesn't\n // like, so we need to readd the removed DOM elements directly after dispose.\n // More concretely, the node marked with `data-vjs-player` will be removed from the\n // DOM. We are readding the cloned original video node parent as it was when React first rendered it,\n // so it is once again synchronized with React.\n if (\n containerRef.current &&\n videoNode.current?.parentNode &&\n !containerRef.current.contains(videoNode.current.parentNode)\n ) {\n containerRef.current.appendChild(originalVideoNodeParent);\n videoNode.current =\n originalVideoNodeParent.firstChild as HTMLVideoElement;\n }\n\n player.current = null;\n onDispose();\n }\n };\n\n // We'll use the serialized videoJsOptions object as a dependency object\n }, [useDeepCompareMemoize(videoJsOptions)]);\n\n return (\n // TODO: can we get by withour introducing an extra div?\n <div ref={containerRef}>\n <div data-vjs-player>\n <video\n ref={videoNode}\n className={`video-js ${classNames}`}\n {...props}\n >\n {children}\n </video>\n </div>\n </div>\n );\n }\n);\n\nVideoJsWrapper.displayName = \"VideoJsWrapper\";\n\ntype VideoProps = {\n children?: React.ReactNode;\n} & Partial<HTMLProps<HTMLVideoElement>>;\n\ntype VideoType = (props: VideoProps) => JSX.Element;\n\nexport const useVideoJS = (\n videoJsOptions: VideoJsPlayerOptions,\n classNames = \"\"\n): {\n Video: VideoType;\n ready: boolean;\n player: VideoJsPlayer | null;\n} => {\n const [ready, setReady] = useState(false);\n\n // player will contain the video.js player object, once it is ready.\n const player = useRef<VideoJsPlayer>(null);\n const Video = useCallback(\n ({ children, ...props }: VideoProps) => (\n <VideoJsWrapper\n videoJsOptions={videoJsOptions}\n classNames={classNames}\n onReady={(): void => setReady(true)}\n onDispose={(): void => setReady(false)}\n {...props}\n ref={player}\n >\n {children}\n </VideoJsWrapper>\n ),\n [useDeepCompareMemoize(videoJsOptions), classNames]\n );\n\n return { Video, ready, player: player.current };\n};\n"],"names":["React","dequal","forwardRef","cloneDeep","useRef","useLayoutEffect","videojs","useState","useCallback"],"mappings":";;;;;;;;AAeA,iCAAkC,OAAa;AACvC,UAAA,MAAMA,eAAAA,QAAM,OAAU,KAAK;AAC3B,UAAA,YAAYA,eAAAA,QAAM,OAAe,CAAC;AAExC,QAAI,CAACC,OAAAA,OAAO,OAAO,IAAI,OAAO,GAAG;AAC/B,UAAI,UAAU;AACd,gBAAU,WAAW;AAAA,IACvB;AAEO,WAAAD,eAAA,QAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,UAAU,OAAO,CAAC;AAAA,EAC7D;AAKA,QAAM,iBAAiBE,MAUrB,WAAA,CACE,EAAE,UAAU,gBAAgB,SAAS,WAAW,eAAe,SAC/D,cACG;AACH,UAAM,SAAS;AAGT,UAAA,uBAAuBC,2BAAU,cAAc;AAC/C,UAAA,YAAYC,aAAgC,IAAI;AAChD,UAAA,eAAeA,aAA8B,IAAI;AAEvDC,UAAAA,gBAAgB,MAAM;;AAChB,UAAA,CAAC,iBAAU,YAAV,mBAAmB;AAAY;AAKpC,YAAM,0BACJ,UAAU,QAAQ,WAAW,UAAU,IAAI;AAEzC,UAAA,CAAC,OAAO,SAAS;AACnB,eAAO,UAAUC,iBAAA,QAAQ,UAAU,SAAS,oBAAoB;AACzD,eAAA,QAAQ,MAAM,MAAM;AACjB;QAAA,CACT;AAAA,MACH;AAEA,aAAO,MAAY;;AAIjB,YAAI,OAAO,SAAS;AAClB,iBAAO,QAAQ;AAOf,cACE,aAAa,WACb,kBAAU,YAAV,oBAAmB,eACnB,CAAC,aAAa,QAAQ,SAAS,UAAU,QAAQ,UAAU,GAC3D;AACa,yBAAA,QAAQ,YAAY,uBAAuB;AACxD,sBAAU,UACR,wBAAwB;AAAA,UAC5B;AAEA,iBAAO,UAAU;AACP;QACZ;AAAA,MAAA;AAAA,IAID,GAAA,CAAC,sBAAsB,cAAc,CAAC,CAAC;AAE1C,WAEGN,+BAAA,QAAA,cAAA,OAAA;AAAA,MAAI,KAAK;AAAA,IAAA,GACPA,+BAAA,QAAA,cAAA,OAAA;AAAA,MAAI,mBAAe;AAAA,IAAA,GACjBA,+BAAA,QAAA,cAAA,SAAA;AAAA,MACC,KAAK;AAAA,MACL,WAAW,YAAY;AAAA,MACtB,GAAG;AAAA,IAAA,GAEH,QACH,CACF,CACF;AAAA,EAEJ,CACF;AAEA,iBAAe,cAAc;AAQhB,QAAA,aAAa,CACxB,gBACA,aAAa,OAKV;AACH,UAAM,CAAC,OAAO,YAAYO,MAAA,SAAS,KAAK;AAGlC,UAAA,SAASH,aAAsB,IAAI;AACzC,UAAM,QAAQI,kBACZ,CAAC,EAAE,aAAa,YACbR,+BAAAA,QAAA,cAAA,gBAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,SAAS,MAAY,SAAS,IAAI;AAAA,MAClC,WAAW,MAAY,SAAS,KAAK;AAAA,MACpC,GAAG;AAAA,MACJ,KAAK;AAAA,IAAA,GAEJ,QACH,GAEF,CAAC,sBAAsB,cAAc,GAAG,UAAU,CACpD;AAEA,WAAO,EAAE,OAAO,OAAO,QAAQ,OAAO,QAAQ;AAAA,EAChD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hook-videojs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"description": "A simple react hook to easily integrate video.js with React",
|
|
5
5
|
"author": "jimmycallin",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "jimmycallin/react-hook-videojs",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"main": "dist/react-hook-videojs.umd.js",
|
|
10
|
+
"module": "dist/react-hook-videojs.es.js",
|
|
11
|
+
"source": "src/index.tsx",
|
|
11
12
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
13
|
+
"node": ">=18"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"test": "npm run test:
|
|
18
|
-
"test:
|
|
19
|
-
"
|
|
16
|
+
"clean": "rimraf dist .tmp",
|
|
17
|
+
"build": "vite build && tsc --project tsconfig.types.json",
|
|
18
|
+
"test": "npm run test:vitest",
|
|
19
|
+
"test:vitest": "vitest run",
|
|
20
|
+
"format": "prettier --write .",
|
|
21
|
+
"prepare": "npm run clean && npm run build",
|
|
22
|
+
"prepublishOnly": "npm run test",
|
|
23
|
+
"dev": "vite build --watch"
|
|
20
24
|
},
|
|
21
25
|
"peerDependencies": {
|
|
22
|
-
"react": "
|
|
26
|
+
"react": ">=16.8.0 < 19",
|
|
27
|
+
"react-dom": ">=16.8.0 < 19",
|
|
23
28
|
"video.js": "^7.0.0"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"eslint
|
|
33
|
-
"eslint-
|
|
34
|
-
"eslint-plugin-react": "^7.
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"video.js": "^7.
|
|
31
|
+
"@testing-library/react": "^13.3.0",
|
|
32
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
33
|
+
"@types/video.js": "^7.3.42",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
|
35
|
+
"@typescript-eslint/parser": "^5.30.7",
|
|
36
|
+
"@vitejs/plugin-react-refresh": "^1.3.6",
|
|
37
|
+
"eslint": "^8.20.0",
|
|
38
|
+
"eslint-config-prettier": "^8.5.0",
|
|
39
|
+
"eslint-plugin-react": "^7.30.1",
|
|
40
|
+
"jsdom": "^20.0.0",
|
|
41
|
+
"prettier": "^2.7.1",
|
|
42
|
+
"react": "^18.2.0",
|
|
43
|
+
"react-dom": "^18.2.0",
|
|
44
|
+
"rimraf": "^3.0.2",
|
|
45
|
+
"typescript": "^4.7.4",
|
|
46
|
+
"video.js": "^7.20.1",
|
|
47
|
+
"vite": "^3.0.2",
|
|
48
|
+
"vitest": "^0.18.1"
|
|
42
49
|
},
|
|
43
50
|
"files": [
|
|
44
51
|
"dist"
|
|
45
52
|
],
|
|
46
|
-
"dependencies": {
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
"moduleNameMapper": {
|
|
50
|
-
"\\.(css|less|sass|scss)$": "<rootDir>/__mocks__/styleMock.js"
|
|
51
|
-
}
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"dequal": "^2.0.3",
|
|
55
|
+
"lodash.clonedeep": "^4.5.0"
|
|
52
56
|
}
|
|
53
57
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Jimmy Callin
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# react-hook-videojs
|
|
2
|
-
|
|
3
|
-
> A simple react hook to easily integrate video.js with React
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/react-hook-videojs)
|
|
6
|
-
|
|
7
|
-
# react-hook-videojs
|
|
8
|
-
|
|
9
|
-
Due to how video.js mutates the DOM, integrating video.js with React can be a bit tricky. Especially if you want to support video.js component updates and correctly dispose of any old player.
|
|
10
|
-
|
|
11
|
-
React Hooks helps us package this quite nicely, and all you have to do to use this package is:
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
import React from "react";
|
|
15
|
-
import { useVideoJS } from "react-hook-videojs";
|
|
16
|
-
|
|
17
|
-
const App = () => {
|
|
18
|
-
const videoUrl = "http://techslides.com/demos/sample-videos/small.mp4";
|
|
19
|
-
const { Video, player, ready } = useVideoJS({ sources: [{ src: videoUrl }] });
|
|
20
|
-
if (ready) {
|
|
21
|
-
// Do something with the video.js player object.
|
|
22
|
-
}
|
|
23
|
-
return (
|
|
24
|
-
<div className="App">
|
|
25
|
-
<Video />
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
`useVideoJS` takes a single options argument, and passes it without modifications to video.js. See their [options reference](https://docs.videojs.com/tutorial-options.html) for further information.
|
package/dist/index.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var React__default = _interopDefault(React);
|
|
5
|
-
var videojs = _interopDefault(require('video.js'));
|
|
6
|
-
require('video.js/dist/video-js.css');
|
|
7
|
-
|
|
8
|
-
const useVideoJS = videoJsOptions => {
|
|
9
|
-
const videoNode = React.useRef(null);
|
|
10
|
-
const [ready, setReady] = React.useState(false);
|
|
11
|
-
const changedKey = JSON.stringify(videoJsOptions);
|
|
12
|
-
const player = React.useRef(null);
|
|
13
|
-
React.useEffect(() => {
|
|
14
|
-
player.current = videojs(videoNode.current, videoJsOptions);
|
|
15
|
-
player.current.ready(() => {
|
|
16
|
-
setReady(true);
|
|
17
|
-
});
|
|
18
|
-
return () => {
|
|
19
|
-
player.current.dispose();
|
|
20
|
-
};
|
|
21
|
-
}, [changedKey]);
|
|
22
|
-
const Video = React.useCallback(() => /*#__PURE__*/React__default.createElement("div", {
|
|
23
|
-
"data-vjs-player": true,
|
|
24
|
-
key: changedKey
|
|
25
|
-
}, /*#__PURE__*/React__default.createElement("video", {
|
|
26
|
-
ref: videoNode,
|
|
27
|
-
className: "video-js"
|
|
28
|
-
})), [changedKey]);
|
|
29
|
-
return {
|
|
30
|
-
Video,
|
|
31
|
-
ready,
|
|
32
|
-
player: player.current
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.useVideoJS = useVideoJS;
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.jsx"],"sourcesContent":["import React, { useRef, useState, useEffect, useCallback } from \"react\";\nimport videojs from \"video.js\";\nimport \"video.js/dist/video-js.css\";\n\nexport const useVideoJS = (videoJsOptions) => {\n const videoNode = useRef(null);\n const [ready, setReady] = useState(false);\n const changedKey = JSON.stringify(videoJsOptions);\n const player = useRef(null);\n useEffect(() => {\n player.current = videojs(videoNode.current, videoJsOptions);\n player.current.ready(() => {\n setReady(true);\n });\n return () => {\n player.current.dispose();\n };\n }, [changedKey]);\n\n const Video = useCallback(\n () => (\n <div data-vjs-player key={changedKey}>\n <video ref={videoNode} className=\"video-js\" />\n </div>\n ),\n [changedKey]\n );\n return { Video, ready, player: player.current };\n};\n"],"names":["useVideoJS","videoJsOptions","videoNode","useRef","ready","setReady","useState","changedKey","JSON","stringify","player","useEffect","current","videojs","dispose","Video","useCallback","React"],"mappings":";;;;;;;MAIaA,UAAU,GAAIC,cAAD,IAAoB;AAC5C,QAAMC,SAAS,GAAGC,YAAM,CAAC,IAAD,CAAxB;AACA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBC,cAAQ,CAAC,KAAD,CAAlC;AACA,QAAMC,UAAU,GAAGC,IAAI,CAACC,SAAL,CAAeR,cAAf,CAAnB;AACA,QAAMS,MAAM,GAAGP,YAAM,CAAC,IAAD,CAArB;AACAQ,EAAAA,eAAS,CAAC,MAAM;AACdD,IAAAA,MAAM,CAACE,OAAP,GAAiBC,OAAO,CAACX,SAAS,CAACU,OAAX,EAAoBX,cAApB,CAAxB;AACAS,IAAAA,MAAM,CAACE,OAAP,CAAeR,KAAf,CAAqB,MAAM;AACzBC,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;AAGA,WAAO,MAAM;AACXK,MAAAA,MAAM,CAACE,OAAP,CAAeE,OAAf;AACD,KAFD;AAGD,GARQ,EAQN,CAACP,UAAD,CARM,CAAT;AAUA,QAAMQ,KAAK,GAAGC,iBAAW,CACvB,mBACEC;AAAK,2BAAL;AAAqB,IAAA,GAAG,EAAEV;AAA1B,kBACEU;AAAO,IAAA,GAAG,EAAEf,SAAZ;AAAuB,IAAA,SAAS,EAAC;AAAjC,IADF,CAFqB,EAMvB,CAACK,UAAD,CANuB,CAAzB;AAQA,SAAO;AAAEQ,IAAAA,KAAF;AAASX,IAAAA,KAAT;AAAgBM,IAAAA,MAAM,EAAEA,MAAM,CAACE;AAA/B,GAAP;AACD;;;;"}
|
package/dist/index.modern.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import videojs from 'video.js';
|
|
3
|
-
import 'video.js/dist/video-js.css';
|
|
4
|
-
|
|
5
|
-
const useVideoJS = videoJsOptions => {
|
|
6
|
-
const videoNode = useRef(null);
|
|
7
|
-
const [ready, setReady] = useState(false);
|
|
8
|
-
const changedKey = JSON.stringify(videoJsOptions);
|
|
9
|
-
const player = useRef(null);
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
player.current = videojs(videoNode.current, videoJsOptions);
|
|
12
|
-
player.current.ready(() => {
|
|
13
|
-
setReady(true);
|
|
14
|
-
});
|
|
15
|
-
return () => {
|
|
16
|
-
player.current.dispose();
|
|
17
|
-
};
|
|
18
|
-
}, [changedKey]);
|
|
19
|
-
const Video = useCallback(() => /*#__PURE__*/React.createElement("div", {
|
|
20
|
-
"data-vjs-player": true,
|
|
21
|
-
key: changedKey
|
|
22
|
-
}, /*#__PURE__*/React.createElement("video", {
|
|
23
|
-
ref: videoNode,
|
|
24
|
-
className: "video-js"
|
|
25
|
-
})), [changedKey]);
|
|
26
|
-
return {
|
|
27
|
-
Video,
|
|
28
|
-
ready,
|
|
29
|
-
player: player.current
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { useVideoJS };
|
|
34
|
-
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/index.jsx"],"sourcesContent":["import React, { useRef, useState, useEffect, useCallback } from \"react\";\nimport videojs from \"video.js\";\nimport \"video.js/dist/video-js.css\";\n\nexport const useVideoJS = (videoJsOptions) => {\n const videoNode = useRef(null);\n const [ready, setReady] = useState(false);\n const changedKey = JSON.stringify(videoJsOptions);\n const player = useRef(null);\n useEffect(() => {\n player.current = videojs(videoNode.current, videoJsOptions);\n player.current.ready(() => {\n setReady(true);\n });\n return () => {\n player.current.dispose();\n };\n }, [changedKey]);\n\n const Video = useCallback(\n () => (\n <div data-vjs-player key={changedKey}>\n <video ref={videoNode} className=\"video-js\" />\n </div>\n ),\n [changedKey]\n );\n return { Video, ready, player: player.current };\n};\n"],"names":["useVideoJS","videoJsOptions","videoNode","useRef","ready","setReady","useState","changedKey","JSON","stringify","player","useEffect","current","videojs","dispose","Video","useCallback"],"mappings":";;;;MAIaA,UAAU,GAAIC,cAAD,IAAoB;AAC5C,QAAMC,SAAS,GAAGC,MAAM,CAAC,IAAD,CAAxB;AACA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBC,QAAQ,CAAC,KAAD,CAAlC;AACA,QAAMC,UAAU,GAAGC,IAAI,CAACC,SAAL,CAAeR,cAAf,CAAnB;AACA,QAAMS,MAAM,GAAGP,MAAM,CAAC,IAAD,CAArB;AACAQ,EAAAA,SAAS,CAAC,MAAM;AACdD,IAAAA,MAAM,CAACE,OAAP,GAAiBC,OAAO,CAACX,SAAS,CAACU,OAAX,EAAoBX,cAApB,CAAxB;AACAS,IAAAA,MAAM,CAACE,OAAP,CAAeR,KAAf,CAAqB,MAAM;AACzBC,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;AAGA,WAAO,MAAM;AACXK,MAAAA,MAAM,CAACE,OAAP,CAAeE,OAAf;AACD,KAFD;AAGD,GARQ,EAQN,CAACP,UAAD,CARM,CAAT;AAUA,QAAMQ,KAAK,GAAGC,WAAW,CACvB,mBACE;AAAK,2BAAL;AAAqB,IAAA,GAAG,EAAET;AAA1B,kBACE;AAAO,IAAA,GAAG,EAAEL,SAAZ;AAAuB,IAAA,SAAS,EAAC;AAAjC,IADF,CAFqB,EAMvB,CAACK,UAAD,CANuB,CAAzB;AAQA,SAAO;AAAEQ,IAAAA,KAAF;AAASX,IAAAA,KAAT;AAAgBM,IAAAA,MAAM,EAAEA,MAAM,CAACE;AAA/B,GAAP;AACD;;;;"}
|