react-hook-videojs 2.0.0 → 2.1.0-beta.2
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/README.md +51 -5
- package/dist/index.d.ts +11 -0
- package/dist/react-hook-videojs.es.js +61 -0
- package/dist/react-hook-videojs.es.js.map +1 -0
- package/dist/react-hook-videojs.umd.js +71 -0
- package/dist/react-hook-videojs.umd.js.map +1 -0
- package/package.json +41 -36
- package/dist/index.css +0 -9
- package/dist/index.js +0 -43
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -40
- package/dist/index.modern.js.map +0 -1
package/README.md
CHANGED
|
@@ -10,15 +10,20 @@ Due to how video.js mutates the DOM, integrating video.js with React can be a bi
|
|
|
10
10
|
|
|
11
11
|
React Hooks helps us package this quite nicely, and all you have to do to use this package is:
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```jsx
|
|
14
14
|
import React from "react";
|
|
15
|
-
import
|
|
15
|
+
import "video.js/dist/video-js.css";
|
|
16
|
+
import { useVideoJS } from "react-hook-videojs";
|
|
16
17
|
|
|
17
18
|
const App = () => {
|
|
18
19
|
const videoUrl = "http://techslides.com/demos/sample-videos/small.mp4";
|
|
19
|
-
const
|
|
20
|
+
const className = "my-class";
|
|
21
|
+
const { Video, player, ready } = useVideoJS(
|
|
22
|
+
{ sources: [{ src: videoUrl }] },
|
|
23
|
+
className // optional
|
|
24
|
+
);
|
|
20
25
|
if (ready) {
|
|
21
|
-
|
|
26
|
+
// Do something with the video.js player object.
|
|
22
27
|
}
|
|
23
28
|
return (
|
|
24
29
|
<div className="App">
|
|
@@ -28,4 +33,45 @@ const App = () => {
|
|
|
28
33
|
};
|
|
29
34
|
```
|
|
30
35
|
|
|
31
|
-
`useVideoJS` takes
|
|
36
|
+
`useVideoJS` takes an options argument, and passes it without modifications to video.js.
|
|
37
|
+
You may also provide an optional second string argument that will be appended as class name on the `video` DOM node.
|
|
38
|
+
|
|
39
|
+
See their [options reference](https://docs.videojs.com/tutorial-options.html) for further information on the options argument.
|
|
40
|
+
|
|
41
|
+
### Using with Tracks or other child components
|
|
42
|
+
|
|
43
|
+
This hook now supports using features such as [tracks](https://docs.videojs.com/tutorial-tracks.html#text-tracks), and other child components of the `<video>` element.
|
|
44
|
+
|
|
45
|
+
Example of using a text track:
|
|
46
|
+
|
|
47
|
+
```jsx
|
|
48
|
+
const App = () => {
|
|
49
|
+
// ...setup code from above
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Video>
|
|
53
|
+
<track
|
|
54
|
+
kind="captions"
|
|
55
|
+
src="//example.com/path/to/captions.vtt"
|
|
56
|
+
srclang="en"
|
|
57
|
+
label="English"
|
|
58
|
+
default
|
|
59
|
+
/>
|
|
60
|
+
</Video>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
_Note: Videojs supports adding `<track>` and `<sources>` elements programmatically_
|
|
66
|
+
|
|
67
|
+
### Support for all `<video>` element attributes
|
|
68
|
+
|
|
69
|
+
This hook supports all attributes for the native `<video>` element directly on the `<Video>` component.
|
|
70
|
+
|
|
71
|
+
```jsx
|
|
72
|
+
const App = () => {
|
|
73
|
+
return <Video muted autopictureinpicture />;
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
_Note: video.js supports many of these (and registration of listeners) through the player options_
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React, { HTMLProps } from "react";
|
|
2
|
+
import videojs, { VideoJsPlayerOptions } from "video.js";
|
|
3
|
+
declare type VideoType = (props: {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
} & Partial<HTMLProps<HTMLVideoElement>>) => JSX.Element;
|
|
6
|
+
export declare const useVideoJS: (videoJsOptions: VideoJsPlayerOptions, classNames?: string) => {
|
|
7
|
+
Video: VideoType;
|
|
8
|
+
ready: boolean;
|
|
9
|
+
player: videojs.Player | null;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
import React, { useRef, useState, useEffect, useCallback } from "react";
|
|
30
|
+
import videojs from "video.js";
|
|
31
|
+
const useVideoJS = (videoJsOptions, classNames = "") => {
|
|
32
|
+
const videoNode = useRef(null);
|
|
33
|
+
const [ready, setReady] = useState(false);
|
|
34
|
+
const changedKey = JSON.stringify(videoJsOptions);
|
|
35
|
+
const player = useRef(null);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (!videoNode.current)
|
|
38
|
+
return;
|
|
39
|
+
player.current = videojs(videoNode.current, videoJsOptions);
|
|
40
|
+
player.current.ready(() => {
|
|
41
|
+
setReady(true);
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = player.current) == null ? void 0 : _a.dispose();
|
|
46
|
+
};
|
|
47
|
+
}, [changedKey]);
|
|
48
|
+
const Video = useCallback((_a) => {
|
|
49
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
50
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
51
|
+
"data-vjs-player": true,
|
|
52
|
+
key: changedKey
|
|
53
|
+
}, /* @__PURE__ */ React.createElement("video", __spreadValues({
|
|
54
|
+
ref: videoNode,
|
|
55
|
+
className: `video-js ${classNames}`
|
|
56
|
+
}, props), children));
|
|
57
|
+
}, [changedKey]);
|
|
58
|
+
return { Video, ready, player: player.current };
|
|
59
|
+
};
|
|
60
|
+
export { useVideoJS };
|
|
61
|
+
//# 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 useEffect,\n useCallback,\n HTMLProps,\n} from \"react\";\nimport videojs, { VideoJsPlayer, VideoJsPlayerOptions } from \"video.js\";\n\ntype VideoType = (\n props: {\n children?: React.ReactNode;\n } & Partial<HTMLProps<HTMLVideoElement>>\n) => JSX.Element;\n\nexport const useVideoJS = (\n videoJsOptions: VideoJsPlayerOptions,\n classNames = \"\"\n): {\n Video: VideoType;\n ready: boolean;\n player: videojs.Player | null;\n} => {\n const videoNode = useRef(null);\n const [ready, setReady] = useState(false);\n const changedKey = JSON.stringify(videoJsOptions);\n const player = useRef<VideoJsPlayer | null>(null);\n useEffect(() => {\n if (!videoNode.current) return;\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<VideoType>(\n ({ children, ...props }) => (\n <div data-vjs-player={true} key={changedKey}>\n <video ref={videoNode} className={`video-js ${classNames}`} {...props}>\n {children}\n </video>\n </div>\n ),\n [changedKey]\n );\n return { Video, ready, player: player.current };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAea,aAAa,CACxB,gBACA,aAAa,OAKV;QACG,YAAY,OAAO,IAAI;QACvB,CAAC,OAAO,YAAY,SAAS,KAAK;QAClC,aAAa,KAAK,UAAU,cAAc;QAC1C,SAAS,OAA6B,IAAI;YACtC,MAAM;QACV,CAAC,UAAU;;WACR,UAAU,QAAQ,UAAU,SAAS,cAAc;WACnD,QAAQ,MAAM,MAAM;eAChB,IAAI;AAAA,KACd;WACM,MAAM;;mBACJ,+BAAS;AAAA;KAEjB,CAAC,UAAU,CAAC;QAET,QAAQ,YACZ,CAAC;AAAA,iBAAE,eAAF,IAAe,kBAAf,IAAe,CAAb;+CACA;MAAI,mBAAiB;AAAA,MAAM,KAAK;AAAA,2CAC9B;MAAM,KAAK;AAAA,MAAW,WAAW,YAAY;AAAA,OAAkB,QAC7D,QACH,CACF;AAAA,KAEF,CAAC,UAAU,CACb;SACO,EAAE,OAAO,OAAO,QAAQ,OAAO;AACxC;;"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __objRest = (source, exclude) => {
|
|
18
|
+
var target = {};
|
|
19
|
+
for (var prop in source)
|
|
20
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
21
|
+
target[prop] = source[prop];
|
|
22
|
+
if (source != null && __getOwnPropSymbols)
|
|
23
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
24
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
(function(global, factory) {
|
|
30
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("video.js")) : typeof define === "function" && define.amd ? define(["exports", "react", "video.js"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["react-hook-videojs"] = {}, global.React, global.videojs));
|
|
31
|
+
})(this, function(exports2, React, videojs) {
|
|
32
|
+
"use strict";
|
|
33
|
+
function _interopDefaultLegacy(e) {
|
|
34
|
+
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
35
|
+
}
|
|
36
|
+
var React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
|
|
37
|
+
var videojs__default = /* @__PURE__ */ _interopDefaultLegacy(videojs);
|
|
38
|
+
const useVideoJS = (videoJsOptions, classNames = "") => {
|
|
39
|
+
const videoNode = React.useRef(null);
|
|
40
|
+
const [ready, setReady] = React.useState(false);
|
|
41
|
+
const changedKey = JSON.stringify(videoJsOptions);
|
|
42
|
+
const player = React.useRef(null);
|
|
43
|
+
React.useEffect(() => {
|
|
44
|
+
if (!videoNode.current)
|
|
45
|
+
return;
|
|
46
|
+
player.current = videojs__default["default"](videoNode.current, videoJsOptions);
|
|
47
|
+
player.current.ready(() => {
|
|
48
|
+
setReady(true);
|
|
49
|
+
});
|
|
50
|
+
return () => {
|
|
51
|
+
var _a;
|
|
52
|
+
(_a = player.current) == null ? void 0 : _a.dispose();
|
|
53
|
+
};
|
|
54
|
+
}, [changedKey]);
|
|
55
|
+
const Video = React.useCallback((_a) => {
|
|
56
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
57
|
+
return /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
58
|
+
"data-vjs-player": true,
|
|
59
|
+
key: changedKey
|
|
60
|
+
}, /* @__PURE__ */ React__default["default"].createElement("video", __spreadValues({
|
|
61
|
+
ref: videoNode,
|
|
62
|
+
className: `video-js ${classNames}`
|
|
63
|
+
}, props), children));
|
|
64
|
+
}, [changedKey]);
|
|
65
|
+
return { Video, ready, player: player.current };
|
|
66
|
+
};
|
|
67
|
+
exports2.useVideoJS = useVideoJS;
|
|
68
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
69
|
+
exports2[Symbol.toStringTag] = "Module";
|
|
70
|
+
});
|
|
71
|
+
//# 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 useEffect,\n useCallback,\n HTMLProps,\n} from \"react\";\nimport videojs, { VideoJsPlayer, VideoJsPlayerOptions } from \"video.js\";\n\ntype VideoType = (\n props: {\n children?: React.ReactNode;\n } & Partial<HTMLProps<HTMLVideoElement>>\n) => JSX.Element;\n\nexport const useVideoJS = (\n videoJsOptions: VideoJsPlayerOptions,\n classNames = \"\"\n): {\n Video: VideoType;\n ready: boolean;\n player: videojs.Player | null;\n} => {\n const videoNode = useRef(null);\n const [ready, setReady] = useState(false);\n const changedKey = JSON.stringify(videoJsOptions);\n const player = useRef<VideoJsPlayer | null>(null);\n useEffect(() => {\n if (!videoNode.current) return;\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<VideoType>(\n ({ children, ...props }) => (\n <div data-vjs-player={true} key={changedKey}>\n <video ref={videoNode} className={`video-js ${classNames}`} {...props}>\n {children}\n </video>\n </div>\n ),\n [changedKey]\n );\n return { Video, ready, player: player.current };\n};\n"],"names":["useRef","useState","videojs","useCallback"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAea,aAAa,CACxB,gBACA,aAAa,OAKV;UACG,YAAYA,aAAO,IAAI;UACvB,CAAC,OAAO,YAAYC,eAAS,KAAK;UAClC,aAAa,KAAK,UAAU,cAAc;UAC1C,SAASD,aAA6B,IAAI;oBACtC,MAAM;UACV,CAAC,UAAU;;aACR,UAAUE,4BAAQ,UAAU,SAAS,cAAc;aACnD,QAAQ,MAAM,MAAM;iBAChB,IAAI;AAAA,OACd;aACM,MAAM;;qBACJ,+BAAS;AAAA;OAEjB,CAAC,UAAU,CAAC;UAET,QAAQC,kBACZ,CAAC;AAAA,mBAAE,eAAF,IAAe,kBAAf,IAAe,CAAb;qEACA;QAAI,mBAAiB;AAAA,QAAM,KAAK;AAAA,iEAC9B;QAAM,KAAK;AAAA,QAAW,WAAW,YAAY;AAAA,SAAkB,QAC7D,QACH,CACF;AAAA,OAEF,CAAC,UAAU,CACb;WACO,EAAE,OAAO,OAAO,QAAQ,OAAO;EACxC;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,53 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hook-videojs",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.2",
|
|
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": ">=12"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"test
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"deploy": "gh-pages -d example/build"
|
|
16
|
+
"clean": "rimraf dist .tmp",
|
|
17
|
+
"build": "vite build && tsc --project tsconfig.types.json",
|
|
18
|
+
"test": "npm run test:lint && npm run test:jest && npm run test:formatting",
|
|
19
|
+
"test:jest": "jest",
|
|
20
|
+
"test:lint": "eslint ./src",
|
|
21
|
+
"test:formatting": "prettier -c .",
|
|
22
|
+
"format": "prettier --write .",
|
|
23
|
+
"prepare": "npm run clean && npm run build",
|
|
24
|
+
"prepublishOnly": "npm run test"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"react": "^16.0.0",
|
|
27
|
+
"react": "^16.8.0, ^17.0.0",
|
|
28
28
|
"video.js": "^7.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"babel
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"eslint-plugin
|
|
39
|
-
"eslint
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"eslint
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"react
|
|
50
|
-
"
|
|
31
|
+
"@babel/core": "^7.14.6",
|
|
32
|
+
"@babel/plugin-transform-typescript": "^7.18.8",
|
|
33
|
+
"@babel/preset-env": "^7.14.7",
|
|
34
|
+
"@babel/preset-react": "^7.14.5",
|
|
35
|
+
"@testing-library/react": "^12.0.0",
|
|
36
|
+
"@types/jest": "^28.1.5",
|
|
37
|
+
"@types/video.js": "^7.3.42",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
|
39
|
+
"@typescript-eslint/parser": "^5.30.6",
|
|
40
|
+
"@vitejs/plugin-react-refresh": "^1.3.6",
|
|
41
|
+
"babel-jest": "^28.1.3",
|
|
42
|
+
"eslint": "^8.0.0",
|
|
43
|
+
"eslint-config-prettier": "^8.3.0",
|
|
44
|
+
"eslint-plugin-jest": "^26.1.1",
|
|
45
|
+
"eslint-plugin-react": "^7.24.0",
|
|
46
|
+
"jest": "^28.1.3",
|
|
47
|
+
"jest-environment-jsdom": "^28.1.3",
|
|
48
|
+
"prettier": "^2.3.2",
|
|
49
|
+
"react": "^17.0.2",
|
|
50
|
+
"react-dom": "^17.0.2",
|
|
51
|
+
"rimraf": "^3.0.2",
|
|
52
|
+
"ts-jest": "^28.0.5",
|
|
53
|
+
"typescript": "^4.7.4",
|
|
54
|
+
"video.js": "^7.13.3",
|
|
55
|
+
"vite": "^2.4.4"
|
|
51
56
|
},
|
|
52
57
|
"files": [
|
|
53
58
|
"dist"
|
package/dist/index.css
DELETED
package/dist/index.js
DELETED
|
@@ -1,43 +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
|
-
var useVideoJS = function useVideoJS(videoJsOptions) {
|
|
9
|
-
var videoNode = React.useRef(null);
|
|
10
|
-
|
|
11
|
-
var _useState = React.useState(false),
|
|
12
|
-
ready = _useState[0],
|
|
13
|
-
setReady = _useState[1];
|
|
14
|
-
|
|
15
|
-
var changedKey = JSON.stringify(videoJsOptions);
|
|
16
|
-
var player = React.useRef(null);
|
|
17
|
-
React.useEffect(function () {
|
|
18
|
-
player.current = videojs(videoNode.current, videoJsOptions);
|
|
19
|
-
player.current.ready(function () {
|
|
20
|
-
setReady(true);
|
|
21
|
-
});
|
|
22
|
-
return function () {
|
|
23
|
-
player.current.dispose();
|
|
24
|
-
};
|
|
25
|
-
}, [changedKey]);
|
|
26
|
-
var Video = React.useCallback(function () {
|
|
27
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
28
|
-
"data-vjs-player": true,
|
|
29
|
-
key: changedKey
|
|
30
|
-
}, /*#__PURE__*/React__default.createElement("video", {
|
|
31
|
-
ref: videoNode,
|
|
32
|
-
className: "video-js"
|
|
33
|
-
}));
|
|
34
|
-
}, [changedKey]);
|
|
35
|
-
return {
|
|
36
|
-
Video: Video,
|
|
37
|
-
ready: ready,
|
|
38
|
-
player: player.current
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
exports.useVideoJS = useVideoJS;
|
|
43
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.js"],"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","useState","ready","setReady","changedKey","JSON","stringify","player","useEffect","current","videojs","dispose","Video","useCallback","React"],"mappings":";;;;;;;IAIaA,UAAU,GAAG,SAAbA,UAAa,CAACC,cAAD,EAAoB;AAC5C,MAAMC,SAAS,GAAGC,YAAM,CAAC,IAAD,CAAxB;;AAD4C,kBAElBC,cAAQ,CAAC,KAAD,CAFU;AAAA,MAErCC,KAFqC;AAAA,MAE9BC,QAF8B;;AAG5C,MAAMC,UAAU,GAAGC,IAAI,CAACC,SAAL,CAAeR,cAAf,CAAnB;AACA,MAAMS,MAAM,GAAGP,YAAM,CAAC,IAAD,CAArB;AACAQ,EAAAA,eAAS,CAAC,YAAM;AACdD,IAAAA,MAAM,CAACE,OAAP,GAAiBC,OAAO,CAACX,SAAS,CAACU,OAAX,EAAoBX,cAApB,CAAxB;AACAS,IAAAA,MAAM,CAACE,OAAP,CAAeP,KAAf,CAAqB,YAAM;AACzBC,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;AAGA,WAAO,YAAM;AACXI,MAAAA,MAAM,CAACE,OAAP,CAAeE,OAAf;AACD,KAFD;AAGD,GARQ,EAQN,CAACP,UAAD,CARM,CAAT;AAUA,MAAMQ,KAAK,GAAGC,iBAAW,CACvB;AAAA,wBACEC;AAAK,6BAAL;AAAqB,MAAA,GAAG,EAAEV;AAA1B,oBACEU;AAAO,MAAA,GAAG,EAAEf,SAAZ;AAAuB,MAAA,SAAS,EAAC;AAAjC,MADF,CADF;AAAA,GADuB,EAMvB,CAACK,UAAD,CANuB,CAAzB;AAQA,SAAO;AAAEQ,IAAAA,KAAK,EAALA,KAAF;AAASV,IAAAA,KAAK,EAALA,KAAT;AAAgBK,IAAAA,MAAM,EAAEA,MAAM,CAACE;AAA/B,GAAP;AACD;;;;"}
|
package/dist/index.modern.js
DELETED
|
@@ -1,40 +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
|
-
var useVideoJS = function useVideoJS(videoJsOptions) {
|
|
6
|
-
var videoNode = useRef(null);
|
|
7
|
-
|
|
8
|
-
var _useState = useState(false),
|
|
9
|
-
ready = _useState[0],
|
|
10
|
-
setReady = _useState[1];
|
|
11
|
-
|
|
12
|
-
var changedKey = JSON.stringify(videoJsOptions);
|
|
13
|
-
var player = useRef(null);
|
|
14
|
-
useEffect(function () {
|
|
15
|
-
player.current = videojs(videoNode.current, videoJsOptions);
|
|
16
|
-
player.current.ready(function () {
|
|
17
|
-
setReady(true);
|
|
18
|
-
});
|
|
19
|
-
return function () {
|
|
20
|
-
player.current.dispose();
|
|
21
|
-
};
|
|
22
|
-
}, [changedKey]);
|
|
23
|
-
var Video = useCallback(function () {
|
|
24
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
25
|
-
"data-vjs-player": true,
|
|
26
|
-
key: changedKey
|
|
27
|
-
}, /*#__PURE__*/React.createElement("video", {
|
|
28
|
-
ref: videoNode,
|
|
29
|
-
className: "video-js"
|
|
30
|
-
}));
|
|
31
|
-
}, [changedKey]);
|
|
32
|
-
return {
|
|
33
|
-
Video: Video,
|
|
34
|
-
ready: ready,
|
|
35
|
-
player: player.current
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { useVideoJS };
|
|
40
|
-
//# 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.js"],"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","useState","ready","setReady","changedKey","JSON","stringify","player","useEffect","current","videojs","dispose","Video","useCallback"],"mappings":";;;;IAIaA,UAAU,GAAG,SAAbA,UAAa,CAACC,cAAD,EAAoB;AAC5C,MAAMC,SAAS,GAAGC,MAAM,CAAC,IAAD,CAAxB;;AAD4C,kBAElBC,QAAQ,CAAC,KAAD,CAFU;AAAA,MAErCC,KAFqC;AAAA,MAE9BC,QAF8B;;AAG5C,MAAMC,UAAU,GAAGC,IAAI,CAACC,SAAL,CAAeR,cAAf,CAAnB;AACA,MAAMS,MAAM,GAAGP,MAAM,CAAC,IAAD,CAArB;AACAQ,EAAAA,SAAS,CAAC,YAAM;AACdD,IAAAA,MAAM,CAACE,OAAP,GAAiBC,OAAO,CAACX,SAAS,CAACU,OAAX,EAAoBX,cAApB,CAAxB;AACAS,IAAAA,MAAM,CAACE,OAAP,CAAeP,KAAf,CAAqB,YAAM;AACzBC,MAAAA,QAAQ,CAAC,IAAD,CAAR;AACD,KAFD;AAGA,WAAO,YAAM;AACXI,MAAAA,MAAM,CAACE,OAAP,CAAeE,OAAf;AACD,KAFD;AAGD,GARQ,EAQN,CAACP,UAAD,CARM,CAAT;AAUA,MAAMQ,KAAK,GAAGC,WAAW,CACvB;AAAA,wBACE;AAAK,6BAAL;AAAqB,MAAA,GAAG,EAAET;AAA1B,oBACE;AAAO,MAAA,GAAG,EAAEL,SAAZ;AAAuB,MAAA,SAAS,EAAC;AAAjC,MADF,CADF;AAAA,GADuB,EAMvB,CAACK,UAAD,CANuB,CAAzB;AAQA,SAAO;AAAEQ,IAAAA,KAAK,EAALA,KAAF;AAASV,IAAAA,KAAK,EAALA,KAAT;AAAgBK,IAAAA,MAAM,EAAEA,MAAM,CAACE;AAA/B,GAAP;AACD;;;;"}
|