@vnejs/plugins.media.video 0.1.0 → 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 +12 -12
- package/modules/view.js +2 -2
- package/package.json +1 -1
- 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
|
@@ -3,12 +3,11 @@ import { ModuleController } from "@vnejs/module.components";
|
|
|
3
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,12 +20,13 @@ export class Video extends ModuleController {
|
|
|
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
32
|
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
@@ -40,13 +40,13 @@ export class Video extends ModuleController {
|
|
|
40
40
|
await this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitHide });
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
onPreloadLineHandler =
|
|
43
|
+
onPreloadLineHandler = ({ line, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) => {
|
|
44
44
|
const { name = "" } = line.match(this.CONST.VIDEO.LINE_REG).groups;
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
return name && this.emit(this.EVENTS.VIDEO.LOAD, { name, priority, isConstant });
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
onVideoLoad =
|
|
49
|
+
onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) =>
|
|
50
50
|
this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority, isConstant));
|
|
51
51
|
|
|
52
52
|
onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
|
|
@@ -56,7 +56,7 @@ export class Video extends ModuleController {
|
|
|
56
56
|
|
|
57
57
|
if (!video) throw Error("no video");
|
|
58
58
|
|
|
59
|
-
this.
|
|
59
|
+
this.updateState({ src: video.src });
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
getMediaArgs = (name, priority, isConstant) => {
|
package/modules/view.js
CHANGED
|
@@ -5,9 +5,9 @@ import { render } from "../view";
|
|
|
5
5
|
export class VideoView extends ModuleView {
|
|
6
6
|
name = "video.view";
|
|
7
7
|
|
|
8
|
-
animationTime =
|
|
8
|
+
animationTime = this.PARAMS.VIDEO.TRANSITION;
|
|
9
9
|
updateEvent = this.EVENTS.VIDEO.UPDATE;
|
|
10
10
|
|
|
11
11
|
renderFunc = render;
|
|
12
|
-
updateHandler = this.
|
|
12
|
+
updateHandler = this.onUpdateStoreComponent;
|
|
13
13
|
}
|
package/package.json
CHANGED
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
|
+
}
|