@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.
@@ -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 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 { Module } from "@vnejs/module";
1
+ import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class Video extends Module.Controller {
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.emitInteract };
11
- controlsIndex = 2000;
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 = 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
- };
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 = async () => this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
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.emitNext();
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 = async ({
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
- if (name) await this.emit(this.EVENTS.VIDEO.LOAD, { name, priority, isConstant });
46
+ return name && this.emit(this.EVENTS.VIDEO.LOAD, { name, priority, isConstant });
51
47
  };
52
48
 
53
- onVideoLoad = async ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND, isConstant = false } = {}) =>
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.setState({ ...this.state, src: video.src });
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 { Module } from "@vnejs/module";
1
+ import { ModuleView } from "@vnejs/module.components";
2
2
 
3
3
  import { render } from "../view";
4
4
 
5
- export class VideoView extends Module.View {
5
+ export class VideoView extends ModuleView {
6
6
  name = "video.view";
7
- animationTime = 300;
8
- renderFunc = render;
7
+
8
+ animationTime = this.PARAMS.VIDEO.TRANSITION;
9
9
  updateEvent = this.EVENTS.VIDEO.UPDATE;
10
- updateHandler = this.onUpdateReactComponent;
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.0.2",
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
- class VideoView extends React.Component {
11
- state = { isShow: false, isForce: false, src: "" };
12
- videoRef = React.createRef(null);
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
- componentDidUpdate(props, state) {
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
- if (this.state.isShow !== state.isShow) setTimeout(this.onShowChanged, 300);
18
- }
22
+ useEffect(() => {
23
+ const tm = setTimeout(() => {
24
+ if (isShow) return videoRef.current.play();
19
25
 
20
- onShowChanged = () => {
21
- const video = this.videoRef.current;
26
+ videoRef.current.pause();
27
+ videoRef.current.currentTime = 0;
28
+ }, props.PARAMS.VIDEO.TRANSITION);
22
29
 
23
- if (this.state.isShow) return video.play();
30
+ return () => clearTimeout(tm);
31
+ }, [isShow]);
24
32
 
25
- video.pause();
26
- video.currentTime = 0;
27
- };
33
+ const emitHide = useCallback(() => props.emit(props.EVENTS.VIDEO.HIDE), []);
28
34
 
29
- emitHide = () => this.props.emit(this.props.EVENTS.VIDEO.HIDE);
35
+ const propsScreenCommon = useMemo(() => ({ ...props.PARAMS.VIDEO.VIEW_PROPS.screen, onClick: emitHide }), []);
36
+ const propsScreen = useMemo(() => ({ ...propsScreenCommon, isShow, isForce }), [isShow, isForce]);
30
37
 
31
- render() {
32
- const { isShow, isForce, src } = this.state;
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
- return (
35
- <div className={b({ isShow, isForce })} id="Video" onClick={this.emitHide}>
36
- <video
37
- pip="false"
38
- poster="noposter"
39
- className={b("video")}
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, resolve) => ReactDOM.render(<VideoView {...props} />, root, resolve);
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
+ }