@vnejs/plugins.media.video 0.0.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/const.js ADDED
@@ -0,0 +1 @@
1
+ export const LINE_REG = /^{(?<name>.*)}( (?<animation>.*) (?<duration>\d+))?$/;
@@ -0,0 +1,8 @@
1
+ export const SUBSCRIBE_EVENTS = {
2
+ SET: "vne:video:set",
3
+ GET: "vne:video:get",
4
+ LOAD: "vne:video:load",
5
+ SHOW: "vne:video:show",
6
+ HIDE: "vne:video:hide",
7
+ UPDATE: "vne:video:update",
8
+ };
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import * as constants from "./const/const";
4
+ import { SUBSCRIBE_EVENTS } from "./const/events";
5
+
6
+ import { Video } from "./modules/video";
7
+ import { VideoView } from "./modules/view";
8
+
9
+ regPlugin("VIDEO", { constants, events: SUBSCRIBE_EVENTS }, [Video, VideoView]);
@@ -0,0 +1,71 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class Video extends Module.Controller {
4
+ name = "video";
5
+
6
+ emitInteract = () => this.emit(this.EVENTS.INTERACT.EMIT);
7
+ emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
8
+
9
+ updateEvent = this.EVENTS.VIDEO.UPDATE;
10
+ controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: this.emitInteract };
11
+ controlsIndex = 2000;
12
+
13
+ subscribe = () => {
14
+ this.on(this.EVENTS.VIDEO.SHOW, this.onShow);
15
+ this.on(this.EVENTS.VIDEO.HIDE, this.onHide);
16
+ this.on(this.EVENTS.VIDEO.LOAD, this.onVideoLoad);
17
+ this.on(this.EVENTS.VIDEO.GET, this.onVideoGet);
18
+ this.on(this.EVENTS.VIDEO.SET, this.onVideoSet);
19
+
20
+ this.on(this.EVENTS.STATE.SET, this.onUpdateStateFromGlobalState);
21
+ this.on(this.EVENTS.STATE.CLEAR, this.onHide);
22
+ };
23
+
24
+ init = async () => {
25
+ await this.emit(this.EVENTS.SCENARIO.EXEC_REG, { module: this.name, handler: this.onExecLineHandler });
26
+ await this.emit(this.EVENTS.SCENARIO.LINE_REG, { module: this.name, handler: this.onPreloadLineHandler });
27
+ };
28
+
29
+ beforeShow = async () => this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
30
+ afterHide = async () => {
31
+ await this.emit(this.EVENTS.INTERACT.POP, { key: this.name });
32
+ this.emitNext();
33
+ };
34
+
35
+ onExecLineHandler = async (line = "") => {
36
+ const { name } = line.match(this.CONST.VIDEO.LINE_REG).groups;
37
+
38
+ await this.emit(this.EVENTS.VIDEO.SET, { name });
39
+ await this.emit(this.EVENTS.VIDEO.SHOW);
40
+ await this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitHide });
41
+ };
42
+
43
+ onPreloadLineHandler = async ({
44
+ line,
45
+ priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND,
46
+ isConstant = false,
47
+ } = {}) => {
48
+ const { name = "" } = line.match(this.CONST.VIDEO.LINE_REG).groups;
49
+
50
+ if (name) await this.emit(this.EVENTS.VIDEO.LOAD, { name, priority, isConstant });
51
+ };
52
+
53
+ onVideoLoad = async ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) =>
54
+ this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority, isConstant));
55
+
56
+ onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
57
+
58
+ onVideoSet = async ({ name = "" } = {}) => {
59
+ const video = await this.emitOne(this.EVENTS.VIDEO.GET, { name });
60
+
61
+ if (!video) throw Error("no video");
62
+
63
+ this.setState({ ...this.state, src: video.src });
64
+ };
65
+
66
+ getMediaArgs = (name, priority, isConstant) => {
67
+ const [type, quality] = [this.CONST.MEDIA.TYPES.VIDEO, this.shared.settings[this.SETTINGS.CANVAS.QUALITY]];
68
+
69
+ return { mediaType: this.name, type, name, quality, priority, isConstant };
70
+ };
71
+ }
@@ -0,0 +1,11 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class VideoView extends Module.View {
6
+ name = "video.view";
7
+ animationTime = 300;
8
+ renderFunc = render;
9
+ updateEvent = this.EVENTS.VIDEO.UPDATE;
10
+ updateHandler = this.onUpdateReactComponent;
11
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@vnejs/plugins.media.video",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major": "npm version major && npm publish --access public",
8
+ "publish:minor": "npm version minor && npm publish --access public",
9
+ "publish:patch": "npm version patch && npm publish --access public"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "description": "",
14
+ "peerDependencies": {
15
+ "@vnejs/shared": "*",
16
+ "@vnejs/module": "*"
17
+ }
18
+ }
package/view/index.jsx ADDED
@@ -0,0 +1,48 @@
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+
4
+ import { cn } from "@bem-react/classname";
5
+
6
+ import "./index.styl";
7
+
8
+ const b = cn("VideoView");
9
+
10
+ class VideoView extends React.Component {
11
+ state = { isShow: false, isForce: false, src: "" };
12
+ videoRef = React.createRef(null);
13
+
14
+ componentDidUpdate(props, state) {
15
+ const {
16
+ videoRef: { current: video } = {},
17
+ state: { isShow = false } = {},
18
+ props: { shared = {}, SETTINGS = {} } = {},
19
+ } = this;
20
+
21
+ video.volume = shared.settings[SETTINGS.AUDIO.VOLUME];
22
+
23
+ if (isShow !== state.isShow) {
24
+ setTimeout(() => (isShow ? video.play() : video.pause()), 300);
25
+ }
26
+ }
27
+
28
+ emitHide = () => this.props.emit(this.props.EVENTS.VIDEO.HIDE);
29
+
30
+ render() {
31
+ const { isShow, isForce, src } = this.state;
32
+
33
+ return (
34
+ <div className={b({ isShow, isForce })} id="Video" onClick={this.emitHide}>
35
+ <video
36
+ pip="false"
37
+ poster="noposter"
38
+ className={b("video")}
39
+ src={src}
40
+ onEnded={this.emitHide}
41
+ ref={this.videoRef}
42
+ />
43
+ </div>
44
+ );
45
+ }
46
+ }
47
+
48
+ export const render = (props, root, resolve) => ReactDOM.render(<VideoView {...props} />, root, resolve);
@@ -0,0 +1,27 @@
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
+
12
+ &-video
13
+ width: 100%
14
+ height: 100%
15
+ object-fit: fill
16
+
17
+ &::-webkit-media-controls,
18
+ &::-webkit-media-controls-start-playback-button {
19
+ display: none !important;
20
+ }
21
+
22
+ &_isShow
23
+ pointer-events: all
24
+ opacity: 1
25
+
26
+ &:not(&_isForce)
27
+ transition: opacity 300ms