@vnejs/plugins.media.video 0.0.2 → 0.1.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/const/params.js +6 -0
- package/index.js +2 -1
- package/modules/video.js +15 -19
- package/modules/view.js +7 -5
- package/package.json +5 -6
- package/view/index.jsx +31 -32
- package/view/index.styl +2 -19
package/const/params.js
ADDED
package/index.js
CHANGED
|
@@ -2,8 +2,9 @@ import { regPlugin } from "@vnejs/shared";
|
|
|
2
2
|
|
|
3
3
|
import * as constants from "./const/const";
|
|
4
4
|
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
5
|
+
import * as params from "./const/params";
|
|
5
6
|
|
|
6
7
|
import { Video } from "./modules/video";
|
|
7
8
|
import { VideoView } from "./modules/view";
|
|
8
9
|
|
|
9
|
-
regPlugin("VIDEO", { constants, events: SUBSCRIBE_EVENTS }, [Video, VideoView]);
|
|
10
|
+
regPlugin("VIDEO", { constants, events: SUBSCRIBE_EVENTS, params }, [Video, VideoView]);
|
package/modules/video.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
|
-
export class Video extends
|
|
3
|
+
export class Video extends ModuleController {
|
|
4
4
|
name = "video";
|
|
5
5
|
|
|
6
|
-
emitInteract = () => this.emit(this.EVENTS.INTERACT.EMIT);
|
|
7
6
|
emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
|
|
8
7
|
|
|
9
8
|
updateEvent = this.EVENTS.VIDEO.UPDATE;
|
|
10
|
-
controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: this.
|
|
11
|
-
controlsIndex =
|
|
9
|
+
controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERACT.EMIT) };
|
|
10
|
+
controlsIndex = this.PARAMS.VIDEO.ZINDEX;
|
|
12
11
|
|
|
13
12
|
subscribe = () => {
|
|
14
13
|
this.on(this.EVENTS.VIDEO.SHOW, this.onShow);
|
|
@@ -21,15 +20,16 @@ export class Video extends Module.Controller {
|
|
|
21
20
|
this.on(this.EVENTS.STATE.CLEAR, this.onHide);
|
|
22
21
|
};
|
|
23
22
|
|
|
24
|
-
init =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
init = () =>
|
|
24
|
+
Promise.all([
|
|
25
|
+
this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.onExecLineHandler }),
|
|
26
|
+
this.emit(this.EVENTS.SCENARIO.LINE_REG, { module: this.name, handler: this.onPreloadLineHandler }),
|
|
27
|
+
]);
|
|
28
28
|
|
|
29
|
-
beforeShow =
|
|
29
|
+
beforeShow = () => this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
|
|
30
30
|
afterHide = async () => {
|
|
31
31
|
await this.emit(this.EVENTS.INTERACT.POP, { key: this.name });
|
|
32
|
-
this.
|
|
32
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
onExecLineHandler = async (line = "") => {
|
|
@@ -40,17 +40,13 @@ export class Video extends Module.Controller {
|
|
|
40
40
|
await this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitHide });
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
onPreloadLineHandler =
|
|
44
|
-
line,
|
|
45
|
-
priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND,
|
|
46
|
-
isConstant = false,
|
|
47
|
-
} = {}) => {
|
|
43
|
+
onPreloadLineHandler = ({ line, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) => {
|
|
48
44
|
const { name = "" } = line.match(this.CONST.VIDEO.LINE_REG).groups;
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
return name && this.emit(this.EVENTS.VIDEO.LOAD, { name, priority, isConstant });
|
|
51
47
|
};
|
|
52
48
|
|
|
53
|
-
onVideoLoad =
|
|
49
|
+
onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) =>
|
|
54
50
|
this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority, isConstant));
|
|
55
51
|
|
|
56
52
|
onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
|
|
@@ -60,7 +56,7 @@ export class Video extends Module.Controller {
|
|
|
60
56
|
|
|
61
57
|
if (!video) throw Error("no video");
|
|
62
58
|
|
|
63
|
-
this.
|
|
59
|
+
this.updateState({ src: video.src });
|
|
64
60
|
};
|
|
65
61
|
|
|
66
62
|
getMediaArgs = (name, priority, isConstant) => {
|
package/modules/view.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
2
|
|
|
3
3
|
import { render } from "../view";
|
|
4
4
|
|
|
5
|
-
export class VideoView extends
|
|
5
|
+
export class VideoView extends ModuleView {
|
|
6
6
|
name = "video.view";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
animationTime = this.PARAMS.VIDEO.TRANSITION;
|
|
9
9
|
updateEvent = this.EVENTS.VIDEO.UPDATE;
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
renderFunc = render;
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
11
13
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.media.video",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
7
10
|
"publish:major": "npm version major && npm publish --access public",
|
|
8
11
|
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
12
|
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
13
|
},
|
|
11
14
|
"author": "",
|
|
12
15
|
"license": "ISC",
|
|
13
|
-
"description": ""
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@vnejs/shared": "*",
|
|
16
|
-
"@vnejs/module": "*"
|
|
17
|
-
}
|
|
16
|
+
"description": ""
|
|
18
17
|
}
|
package/view/index.jsx
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
|
|
4
4
|
import { cn } from "@bem-react/classname";
|
|
5
5
|
|
|
6
|
+
import { Screen } from "@vnejs/uis.base";
|
|
7
|
+
|
|
6
8
|
import "./index.styl";
|
|
7
9
|
|
|
8
10
|
const b = cn("VideoView");
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const VideoView = ({ store, onMount, ...props } = {}) => {
|
|
13
|
+
const [{ isShow = false, isForce = false, src = "" }, setState] = useState({});
|
|
14
|
+
|
|
15
|
+
useEffect(() => store.subscribe(setState), []);
|
|
16
|
+
useEffect(() => void onMount(), []);
|
|
17
|
+
|
|
18
|
+
const videoRef = useRef(null);
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
this.videoRef.current.volume = this.props.shared.settings[this.props.SETTINGS.AUDIO.VOLUME];
|
|
20
|
+
if (videoRef.current) videoRef.current.volume = props.shared.settings[props.SETTINGS.AUDIO.VOLUME];
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const tm = setTimeout(() => {
|
|
24
|
+
if (isShow) return videoRef.current.play();
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
videoRef.current.pause();
|
|
27
|
+
videoRef.current.currentTime = 0;
|
|
28
|
+
}, props.PARAMS.VIDEO.TRANSITION);
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
return () => clearTimeout(tm);
|
|
31
|
+
}, [isShow]);
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
video.currentTime = 0;
|
|
27
|
-
};
|
|
33
|
+
const emitHide = useCallback(() => props.emit(props.EVENTS.VIDEO.HIDE), []);
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
const propsScreenCommon = useMemo(() => ({ ...props.PARAMS.VIDEO.VIEW_PROPS.screen, onClick: emitHide }), []);
|
|
36
|
+
const propsScreen = useMemo(() => ({ ...propsScreenCommon, isShow, isForce }), [isShow, isForce]);
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
const propsVideoCommon = useMemo(() => ({ pip: "false", poster: "noposter", className: b("video") }), []);
|
|
39
|
+
const propsVideo = useMemo(() => ({ ...propsVideoCommon, src, ref: videoRef, onEnded: emitHide }), [src]);
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
src={src}
|
|
41
|
-
onEnded={this.emitHide}
|
|
42
|
-
ref={this.videoRef}
|
|
43
|
-
/>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
41
|
+
return (
|
|
42
|
+
<Screen {...propsScreen}>
|
|
43
|
+
<video {...propsVideo} />
|
|
44
|
+
</Screen>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
48
47
|
|
|
49
|
-
export const render = (props, root
|
|
48
|
+
export const render = (props, root) => ReactDOM.render(<VideoView {...props} />, root);
|
package/view/index.styl
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
.VideoView
|
|
2
|
-
position: absolute
|
|
3
|
-
top: 0
|
|
4
|
-
right: 0
|
|
5
|
-
bottom: 0
|
|
6
|
-
left: 0
|
|
7
|
-
z-index: 5000
|
|
8
|
-
display: flex
|
|
9
|
-
opacity: 0
|
|
10
|
-
pointer-events: none
|
|
11
|
-
|
|
1
|
+
.VideoView
|
|
12
2
|
&-video
|
|
13
3
|
width: 100%
|
|
14
4
|
height: 100%
|
|
@@ -17,11 +7,4 @@
|
|
|
17
7
|
&::-webkit-media-controls,
|
|
18
8
|
&::-webkit-media-controls-start-playback-button {
|
|
19
9
|
display: none !important;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
&_isShow
|
|
23
|
-
pointer-events: all
|
|
24
|
-
opacity: 1
|
|
25
|
-
|
|
26
|
-
&:not(&_isForce)
|
|
27
|
-
transition: opacity 300ms
|
|
10
|
+
}
|