@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 +2 -0
- package/index.js +2 -2
- package/modules/controller.js +26 -0
- package/modules/video.js +16 -27
- package/package.json +1 -1
- package/const/const.js +0 -1
package/const/events.js
CHANGED
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", {
|
|
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 {
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
name = "video";
|
|
5
|
-
|
|
6
|
-
emitHide = () => this.emit(this.EVENTS.VIDEO.HIDE);
|
|
3
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
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.
|
|
14
|
-
|
|
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.
|
|
26
|
-
this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.name, handler: this.
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
44
|
-
const
|
|
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.
|
|
45
|
+
this.emit(this.EVENTS.VIDEO.SET_SRC, { src: video.src });
|
|
57
46
|
};
|
|
58
47
|
|
|
59
|
-
onStateSet = async ({ [this.name]:
|
|
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
package/const/const.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const LINE_REG = /^{(?<name>.*)}( (?<animation>.*) (?<duration>\d+))?$/;
|