@vnejs/plugins.views.video 0.1.9 → 0.1.11

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/events.js CHANGED
@@ -2,6 +2,8 @@ export const SUBSCRIBE_EVENTS = {
2
2
  SET: "vne:video:set",
3
3
  GET: "vne:video:get",
4
4
  LOAD: "vne:video:load",
5
+
6
+ SET_SRC: "vne:video:set_src",
5
7
  SHOW: "vne:video:show",
6
8
  HIDE: "vne:video:hide",
7
9
  UPDATE: "vne:video:update",
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { regPlugin } from "@vnejs/shared";
2
2
 
3
- import * as constants from "./const/const";
4
3
  import { SUBSCRIBE_EVENTS } from "./const/events";
5
4
  import * as params from "./const/params";
6
5
 
6
+ import { VideoController } from "./modules/controller";
7
7
  import { Video } from "./modules/video";
8
8
  import { VideoView } from "./modules/view";
9
9
 
10
- regPlugin("VIDEO", { constants, events: SUBSCRIBE_EVENTS, params }, [Video, VideoView]);
10
+ regPlugin("VIDEO", { events: SUBSCRIBE_EVENTS, params }, [VideoController, Video, VideoView]);
@@ -0,0 +1,26 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ export class VideoController extends ModuleController {
4
+ name = "video.controller";
5
+
6
+ updateEvent = this.EVENTS.VIDEO.UPDATE;
7
+ controls = { [this.CONST.CONTROLS.BUTTONS.ANY]: () => this.emit(this.EVENTS.INTERACT.EMIT) };
8
+ controlsIndex = this.PARAMS.VIDEO.ZINDEX;
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.VIDEO.SHOW, this.onShow);
12
+ this.on(this.EVENTS.VIDEO.HIDE, this.onHide);
13
+ this.on(this.EVENTS.VIDEO.SET_SRC, this.onVideoSetSrc);
14
+
15
+ this.on(this.EVENTS.STATE.CLEAR, this.onHideForce);
16
+ };
17
+
18
+ beforeShow = () => this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
19
+ afterShow = () => this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitHide });
20
+ afterHide = () => this.emit(this.EVENTS.INTERACT.POP, { key: this.name }).then(this.clearSrcAndGoNext);
21
+
22
+ onVideoSetSrc = async ({ src = "" } = {}) => this.updateStateAndViewFast({ src });
23
+
24
+ emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
25
+ clearSrcAndGoNext = () => void Promise.all([this.emit(this.EVENTS.VIDEO.SET_SRC, { src: "" }), this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name })]);
26
+ }
package/modules/video.js CHANGED
@@ -1,47 +1,34 @@
1
- import { ModuleController } from "@vnejs/module.components";
1
+ import { Module } from "@vnejs/module";
2
2
 
3
- export class Video extends ModuleController {
4
- name = "video";
5
-
6
- emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
3
+ import { tokenizeExecLine } from "@vnejs/helpers";
7
4
 
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;
5
+ export class Video extends Module {
6
+ name = "video";
11
7
 
12
8
  subscribe = () => {
13
- this.on(this.EVENTS.VIDEO.SHOW, this.onShow);
14
- this.on(this.EVENTS.VIDEO.HIDE, this.onHide);
9
+ this.on(this.EVENTS.VIDEO.HIDE, this.setDefaultState);
10
+
15
11
  this.on(this.EVENTS.VIDEO.LOAD, this.onVideoLoad);
16
12
  this.on(this.EVENTS.VIDEO.GET, this.onVideoGet);
17
13
  this.on(this.EVENTS.VIDEO.SET, this.onVideoSet);
18
14
 
19
15
  this.on(this.EVENTS.STATE.SET, this.onStateSet);
20
- this.on(this.EVENTS.STATE.CLEAR, this.onHide);
21
16
  };
22
17
 
23
18
  init = () =>
24
19
  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 }),
20
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec }),
21
+ this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.name, handler: this.onLineLoad }),
27
22
  ]);
28
23
 
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.updateStateAndViewFast({ src: "" });
33
- this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
34
- };
35
-
36
- onExecLineHandler = async (line = "") => {
37
- const { name } = line.match(this.CONST.VIDEO.LINE_REG).groups;
24
+ onLineExec = async ({ line = "" } = {}) => {
25
+ const [name = ""] = tokenizeExecLine(line);
38
26
 
39
27
  await this.emit(this.EVENTS.VIDEO.SET, { name });
40
28
  await this.emit(this.EVENTS.VIDEO.SHOW);
41
- await this.emit(this.EVENTS.INTERACT.PUSH, { key: this.name, handler: this.emitHide });
42
29
  };
43
- onPreloadLineHandler = ({ line, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
44
- const { name = "" } = line.match(this.CONST.VIDEO.LINE_REG).groups;
30
+ onLineLoad = ({ line, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
31
+ const [name = ""] = tokenizeExecLine(line);
45
32
 
46
33
  return name && this.emit(this.EVENTS.VIDEO.LOAD, { name, priority });
47
34
  };
@@ -49,14 +36,16 @@ export class Video extends ModuleController {
49
36
  onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority));
50
37
  onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
51
38
  onVideoSet = async ({ name = "" } = {}) => {
39
+ this.updateState({ name });
40
+
52
41
  const video = await this.emitOne(this.EVENTS.VIDEO.GET, { name });
53
42
 
54
43
  if (!video) throw Error("no video");
55
44
 
56
- this.updateState({ src: video.src });
45
+ this.emit(this.EVENTS.VIDEO.SET_SRC, { src: video.src });
57
46
  };
58
47
 
59
- onStateSet = async ({ [this.name]: state } = {}) => this.setState(await this.emitOne(this.EVENTS.VENDORS.CLONE, state));
48
+ onStateSet = async ({ [this.name]: { name = "" } = {} } = {}) => name && this.emit(this.EVENTS.VIDEO.SET, { name });
60
49
 
61
50
  getMediaArgs = (name, priority) => {
62
51
  const [type, quality] = [this.CONST.MEDIA.TYPES.VIDEO, this.shared.settings[this.SETTINGS.LAYER.QUALITY]];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.video",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/const/const.js DELETED
@@ -1 +0,0 @@
1
- export const LINE_REG = /^{(?<name>.*)}( (?<animation>.*) (?<duration>\d+))?$/;