@vnejs/plugins.views.video 0.1.8

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
+ };
@@ -0,0 +1,6 @@
1
+ export const TRANSITION = 300;
2
+ export const ZINDEX = 2000;
3
+
4
+ export const VIEW_PROPS = {
5
+ screen: { transition: TRANSITION, zIndex: ZINDEX },
6
+ };
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import { regPlugin } from "@vnejs/shared";
2
+
3
+ import * as constants from "./const/const";
4
+ import { SUBSCRIBE_EVENTS } from "./const/events";
5
+ import * as params from "./const/params";
6
+
7
+ import { Video } from "./modules/video";
8
+ import { VideoView } from "./modules/view";
9
+
10
+ regPlugin("VIDEO", { constants, events: SUBSCRIBE_EVENTS, params }, [Video, VideoView]);
@@ -0,0 +1,66 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class Video extends ModuleController {
4
+ name = "video";
5
+
6
+ emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
7
+
8
+ updateEvent = this.EVENTS.VIDEO.UPDATE;
9
+ controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERACT.EMIT) };
10
+ controlsIndex = this.PARAMS.VIDEO.ZINDEX;
11
+
12
+ subscribe = () => {
13
+ this.on(this.EVENTS.VIDEO.SHOW, this.onShow);
14
+ this.on(this.EVENTS.VIDEO.HIDE, this.onHide);
15
+ this.on(this.EVENTS.VIDEO.LOAD, this.onVideoLoad);
16
+ this.on(this.EVENTS.VIDEO.GET, this.onVideoGet);
17
+ this.on(this.EVENTS.VIDEO.SET, this.onVideoSet);
18
+
19
+ this.on(this.EVENTS.STATE.SET, this.onUpdateStateFromGlobalState);
20
+ this.on(this.EVENTS.STATE.CLEAR, this.onHide);
21
+ };
22
+
23
+ init = () =>
24
+ Promise.all([
25
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onExecLineHandler }),
26
+ this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.name, handler: this.onPreloadLineHandler }),
27
+ ]);
28
+
29
+ beforeShow = () => this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
30
+ afterHide = async () => {
31
+ await this.emit(this.EVENTS.INTERACT.POP, { key: this.name });
32
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
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 = ({ line, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
44
+ const { name = "" } = line.match(this.CONST.VIDEO.LINE_REG).groups;
45
+
46
+ return name && this.emit(this.EVENTS.VIDEO.LOAD, { name, priority });
47
+ };
48
+
49
+ onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority));
50
+
51
+ onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
52
+
53
+ onVideoSet = async ({ name = "" } = {}) => {
54
+ const video = await this.emitOne(this.EVENTS.VIDEO.GET, { name });
55
+
56
+ if (!video) throw Error("no video");
57
+
58
+ this.updateState({ src: video.src });
59
+ };
60
+
61
+ getMediaArgs = (name, priority) => {
62
+ const [type, quality] = [this.CONST.MEDIA.TYPES.VIDEO, this.shared.settings[this.SETTINGS.LAYER.QUALITY]];
63
+
64
+ return { mediaType: this.name, type, name, quality, priority };
65
+ };
66
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view";
4
+
5
+ export class VideoView extends ModuleView {
6
+ name = "video.view";
7
+
8
+ animationTime = this.PARAMS.VIDEO.TRANSITION;
9
+ updateEvent = this.EVENTS.VIDEO.UPDATE;
10
+
11
+ renderFunc = render;
12
+ updateHandler = this.onUpdateStoreComponent;
13
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@vnejs/plugins.views.video",
3
+ "version": "0.1.8",
4
+ "main": "index.js",
5
+ "scripts": {
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",
10
+ "publish:major": "npm version major && npm publish --access public",
11
+ "publish:minor": "npm version minor && npm publish --access public",
12
+ "publish:patch": "npm version patch && npm publish --access public"
13
+ },
14
+ "author": "",
15
+ "license": "ISC",
16
+ "description": ""
17
+ }
package/view/index.jsx ADDED
@@ -0,0 +1,49 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+
4
+ import { Screen } from "@vnejs/uis.react";
5
+
6
+ import "./index.styl";
7
+
8
+ const TRANSPARENT_IMAGE = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxIDEiLz4=";
9
+
10
+ const VIDEO_PROPS = { pip: "false", poster: TRANSPARENT_IMAGE, className: "VideoView-video", crossOrigin: "anonymous" };
11
+
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);
19
+
20
+ if (videoRef.current) videoRef.current.volume = props.shared.settings[props.SETTINGS.VOLUME.VALUE] / 100;
21
+
22
+ useEffect(() => {
23
+ const tm = setTimeout(() => {
24
+ if (videoRef.current) videoRef.current.volume = props.shared.settings[props.SETTINGS.VOLUME.VALUE] / 100;
25
+
26
+ if (isShow) return videoRef.current.play();
27
+
28
+ if (videoRef.current) {
29
+ videoRef.current.pause();
30
+ videoRef.current.currentTime = 0;
31
+ }
32
+ }, props.PARAMS.VIDEO.TRANSITION);
33
+
34
+ return () => clearTimeout(tm);
35
+ }, [isShow]);
36
+
37
+ const onClick = useCallback(() => props.emit(props.EVENTS.VIDEO.HIDE), []);
38
+
39
+ const propsScreen = useMemo(() => ({ ...props.PARAMS.VIDEO.VIEW_PROPS.screen, onClick, isShow, isForce }), [isShow, isForce]);
40
+ const propsVideo = useMemo(() => ({ ...VIDEO_PROPS, src, ref: videoRef, onEnded: onClick }), [src]);
41
+
42
+ return (
43
+ <Screen {...propsScreen}>
44
+ <video {...propsVideo} />
45
+ </Screen>
46
+ );
47
+ };
48
+
49
+ export const render = (props, root) => createRoot(root).render(<VideoView {...props} />);
@@ -0,0 +1,10 @@
1
+ .VideoView
2
+ &-video
3
+ width: 100%
4
+ height: 100%
5
+ object-fit: fill
6
+
7
+ &::-webkit-media-controls,
8
+ &::-webkit-media-controls-start-playback-button {
9
+ display: none !important;
10
+ }