@vnejs/plugins.controllers.common.video 0.0.0-stage → 0.2.14

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.
Files changed (42) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +17 -0
  3. package/dist/modules/controller.d.ts +14 -0
  4. package/dist/modules/controller.interact.d.ts +11 -0
  5. package/dist/modules/controller.interact.js +9 -0
  6. package/dist/modules/controller.js +15 -0
  7. package/dist/modules/controller.src.d.ts +8 -0
  8. package/dist/modules/controller.src.js +11 -0
  9. package/dist/modules/hide.state.d.ts +7 -0
  10. package/dist/modules/hide.state.js +6 -0
  11. package/dist/modules/video.d.ts +21 -0
  12. package/dist/modules/video.js +52 -0
  13. package/dist/modules/view.d.ts +9 -0
  14. package/dist/modules/view.js +8 -0
  15. package/dist/types.d.ts +18 -0
  16. package/dist/types.js +1 -0
  17. package/dist/utils/video.d.ts +10 -0
  18. package/dist/utils/video.js +1 -0
  19. package/dist/view/index.d.ts +3 -0
  20. package/dist/view/index.js +16 -0
  21. package/dist/view/index.styles.d.ts +1 -0
  22. package/dist/view/index.styles.js +15 -0
  23. package/package.json +65 -4
  24. package/src/index.ts +21 -0
  25. package/src/modules/controller.interact.ts +22 -0
  26. package/src/modules/controller.src.ts +18 -0
  27. package/src/modules/controller.ts +21 -0
  28. package/src/modules/hide.state.ts +11 -0
  29. package/src/modules/video.ts +82 -0
  30. package/src/modules/view.ts +15 -0
  31. package/src/tests/controller.interact.test.ts +87 -0
  32. package/src/tests/controller.src.test.ts +24 -0
  33. package/src/tests/controller.test.ts +37 -0
  34. package/src/tests/hide.state.test.ts +25 -0
  35. package/src/tests/setup.ts +56 -0
  36. package/src/tests/video.test.ts +54 -0
  37. package/src/types.ts +33 -0
  38. package/src/utils/video.ts +11 -0
  39. package/src/view/index.styles.ts +18 -0
  40. package/src/view/index.tsx +51 -0
  41. package/tsconfig.json +10 -0
  42. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.controllers.common.video";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import "@vnejs/contracts.controllers.common.video";
2
+ import { regPlugin } from "@vnejs/registry";
3
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.video";
4
+ import { VideoControllerInteract } from "./modules/controller.interact.js";
5
+ import { VideoController } from "./modules/controller.js";
6
+ import { VideoControllerSrc } from "./modules/controller.src.js";
7
+ import { VideoHideState } from "./modules/hide.state.js";
8
+ import { Video } from "./modules/video.js";
9
+ import { VideoView } from "./modules/view.js";
10
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
11
+ VideoController,
12
+ VideoControllerInteract,
13
+ VideoControllerSrc,
14
+ VideoHideState,
15
+ Video,
16
+ VideoView,
17
+ ]);
@@ -0,0 +1,14 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
3
+ import type { VideoPluginState } from "../types.js";
4
+ export declare class VideoController extends ModuleController<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:video:update";
7
+ EVENT_UPDATE_STATE: "vne:video:update_state";
8
+ EVENT_UPDATE_FAST: "vne:video:update_fast";
9
+ EVENT_UPDATE_FORCE: "vne:video:update_force";
10
+ EVENT_SHOW: "vne:video:show";
11
+ EVENT_HIDE: "vne:video:hide";
12
+ onShowBefore: () => undefined;
13
+ onHideAfter: () => void;
14
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerInteract } from "@vnejs/module.controller.interact";
2
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
3
+ import type { VideoPluginState } from "../types.js";
4
+ export declare class VideoControllerInteract extends ModuleControllerInteract<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState> {
5
+ name: string;
6
+ EVENT_SHOW: "vne:video:show";
7
+ EVENT_HIDE: "vne:video:hide";
8
+ CONTROLS_ZINDEX: number;
9
+ CONTROLS_CHECK_NEXT: boolean;
10
+ onInteract: () => Promise<import("@vnejs/registry").EmitResults<"vne:video:hide">> | undefined;
11
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleControllerInteract } from "@vnejs/module.controller.interact";
2
+ export class VideoControllerInteract extends ModuleControllerInteract {
3
+ name = "video.controller.interact";
4
+ EVENT_SHOW = this.EVENTS.VIDEO.SHOW;
5
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
6
+ CONTROLS_ZINDEX = this.PARAMS.VIDEO.ZINDEX;
7
+ CONTROLS_CHECK_NEXT = false;
8
+ onInteract = () => this.emit(this.EVENTS.VIDEO.HIDE);
9
+ }
@@ -0,0 +1,15 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class VideoController extends ModuleController {
3
+ name = "video.controller";
4
+ EVENT_UPDATE_VIEW = this.EVENTS.VIDEO.UPDATE;
5
+ EVENT_UPDATE_STATE = this.EVENTS.VIDEO.UPDATE_STATE;
6
+ EVENT_UPDATE_FAST = this.EVENTS.VIDEO.UPDATE_FAST;
7
+ EVENT_UPDATE_FORCE = this.EVENTS.VIDEO.UPDATE_FORCE;
8
+ EVENT_SHOW = this.EVENTS.VIDEO.SHOW;
9
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
10
+ onShowBefore = () => void this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
11
+ onHideAfter = () => {
12
+ this.emit(this.EVENTS.VIDEO.SET_SRC, { src: "" });
13
+ this.emit(this.EVENTS.SCENARIO.NEXT);
14
+ };
15
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { VideoSetSrcPayload } from "@vnejs/contracts.controllers.common.video";
3
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
4
+ export declare class VideoControllerSrc extends ModuleCore<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onSetSrc: ({ src }?: VideoSetSrcPayload) => Promise<void>;
8
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class VideoControllerSrc extends ModuleCore {
3
+ name = "video.controller.src";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.VIDEO.SET_SRC, this.onSetSrc);
6
+ };
7
+ onSetSrc = async ({ src = "" } = {}) => {
8
+ await this.emit(this.EVENTS.VIDEO.UPDATE_STATE, { src });
9
+ await this.emit(this.EVENTS.VIDEO.UPDATE_FAST);
10
+ };
11
+ }
@@ -0,0 +1,7 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
3
+ export declare class VideoHideState extends ModuleControllerHideOnState<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams> {
4
+ name: string;
5
+ EVENT_HIDE: "vne:video:hide";
6
+ IS_STATE_SET_ENABLED: boolean;
7
+ }
@@ -0,0 +1,6 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ export class VideoHideState extends ModuleControllerHideOnState {
3
+ name = "video.hide.state";
4
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
5
+ IS_STATE_SET_ENABLED = false;
6
+ }
@@ -0,0 +1,21 @@
1
+ import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
+ import type { LineExecHandlerArg, LineLoadHandlerArg } from "@vnejs/module.core";
3
+ import type { VideoGetPayload, VideoLoadPayload, VideoPlayPayload, VideoSetPayload } from "@vnejs/contracts.controllers.common.video";
4
+ import type { VideoMediaArgs, VideoPluginModelState } from "../utils/video.js";
5
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
6
+ export declare class Video extends ModuleCore<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginModelState> {
7
+ name: string;
8
+ subscribe: () => void;
9
+ init: () => Promise<[import("@vnejs/registry").EmitResults<"vne:scenario:line_exec_reg"> | undefined, import("@vnejs/registry").EmitResults<"vne:scenario:line_load_reg"> | undefined]>;
10
+ onLineExec: ({ line, args }?: LineExecHandlerArg) => Promise<import("@vnejs/registry").EmitResults<"vne:video:play"> | undefined> | undefined;
11
+ onLineLoad: ({ line, args, priority }?: LineLoadHandlerArg) => Promise<"" | import("@vnejs/registry").EmitResults<"vne:video:load"> | undefined> | undefined;
12
+ onVideoPlay: ({ name }?: VideoPlayPayload) => Promise<void>;
13
+ onVideoLoad: ({ name, priority }?: VideoLoadPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:media:load">> | undefined;
14
+ onVideoGet: ({ name }?: VideoGetPayload) => Promise<import("@vnejs/contracts.core.media").MediaElement | null | undefined> | undefined;
15
+ onVideoSet: ({ name }?: VideoSetPayload) => Promise<void>;
16
+ onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<void>;
17
+ getDefaultState: () => VideoPluginModelState;
18
+ emitPlay: (name?: string, args?: Record<string, unknown>) => Promise<import("@vnejs/registry").EmitResults<"vne:video:play"> | undefined>;
19
+ getMediaArgs: (name: string, priority?: number) => VideoMediaArgs;
20
+ emitLoad: (name?: string, args?: Record<string, unknown>, priority?: number) => Promise<"" | import("@vnejs/registry").EmitResults<"vne:video:load"> | undefined>;
21
+ }
@@ -0,0 +1,52 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { tokenizeExecLine } from "@vnejs/helpers";
3
+ export class Video extends ModuleCore {
4
+ name = "video";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.VIDEO.HIDE, this.setDefaultState);
7
+ this.on(this.EVENTS.VIDEO.PLAY, this.onVideoPlay);
8
+ this.on(this.EVENTS.VIDEO.LOAD, this.onVideoLoad);
9
+ this.on(this.EVENTS.VIDEO.GET, this.onVideoGet);
10
+ this.on(this.EVENTS.VIDEO.SET, this.onVideoSet);
11
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
12
+ };
13
+ init = () => Promise.all([
14
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec }),
15
+ this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.name, handler: this.onLineLoad }),
16
+ ]);
17
+ onLineExec = ({ line = "", args = {} } = {}) => {
18
+ const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
19
+ if (action === this.CONST.VIDEO.EXEC_ACTIONS.PLAY)
20
+ return this.emitPlay(tokens[0], args);
21
+ };
22
+ onLineLoad = ({ line = "", args = {}, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
23
+ const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
24
+ if (action === this.CONST.VIDEO.EXEC_ACTIONS.PLAY)
25
+ return this.emitLoad(tokens[0], args, priority);
26
+ };
27
+ onVideoPlay = async ({ name = "" } = {}) => {
28
+ await this.emit(this.EVENTS.VIDEO.SET, { name });
29
+ await this.emit(this.EVENTS.VIDEO.SHOW);
30
+ };
31
+ onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority));
32
+ onVideoGet = ({ name = "" } = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
33
+ onVideoSet = async ({ name = "" } = {}) => {
34
+ this.updateState({ name });
35
+ const video = (await this.emitOne(this.EVENTS.VIDEO.GET, { name }));
36
+ if (!video?.src)
37
+ throw Error("no video");
38
+ this.emit(this.EVENTS.VIDEO.SET_SRC, { src: video.src });
39
+ };
40
+ onStateSet = async (payload) => {
41
+ const { name = "" } = this.getStateSlice(payload);
42
+ name && this.emit(this.EVENTS.VIDEO.SET, { name });
43
+ };
44
+ getDefaultState = () => ({ name: "" });
45
+ emitPlay = async (name = "", args) => this.emit(this.EVENTS.VIDEO.PLAY, { name, args });
46
+ getMediaArgs = (name, priority) => {
47
+ const type = this.CONST.MEDIA.TYPES.VIDEO;
48
+ const quality = this.shared.settings[this.SETTINGS.LAYER.QUALITY];
49
+ return { mediaType: this.name, type, name, quality, priority };
50
+ };
51
+ emitLoad = async (name = "", args, priority) => name && this.emit(this.EVENTS.VIDEO.LOAD, { name, args, priority });
52
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
3
+ import type { VideoPluginState } from "../types.js";
4
+ export declare class VideoView extends ModuleView<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:video:update";
7
+ TRANSITION: number;
8
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<VideoPluginState>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class VideoView extends ModuleView {
4
+ name = "video.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.VIDEO.UPDATE;
6
+ TRANSITION = this.PARAMS.VIDEO.TRANSITION;
7
+ renderFunc = render;
8
+ }
@@ -0,0 +1,18 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.common.video";
3
+ import type { PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/contracts.controllers.scenario.interface";
4
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
5
+ import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/contracts.core.interact";
6
+ import type { Constants as MediaConstants, PluginName as MediaPluginName, SubscribeEvents as MediaSubscribeEvents } from "@vnejs/contracts.core.media";
7
+ import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
8
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
9
+ import type { SettingsKeys as VolumeSettingsKeys, PluginName as VolumePluginName } from "@vnejs/contracts.settings.volume";
10
+ export type VideoPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<MediaPluginName, MediaSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<InteractPluginName, InteractSubscribeEvents> & Record<InterfacePluginName, InterfaceSubscribeEvents>;
11
+ export type VideoPluginConstants = ModuleComponentsConstants & Record<PluginName, Constants> & Record<MediaPluginName, MediaConstants> & Record<ControlsPluginName, ControlsConstants>;
12
+ export type VideoPluginSettings = ModuleComponentsSettings & Record<VolumePluginName, VolumeSettingsKeys>;
13
+ export type VideoPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
14
+ export type VideoPluginState = {
15
+ isShow: boolean;
16
+ isForce: boolean;
17
+ src?: string;
18
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export type VideoPluginModelState = {
2
+ name: string;
3
+ };
4
+ export type VideoMediaArgs = {
5
+ mediaType?: string;
6
+ type?: string;
7
+ name?: string;
8
+ quality?: string | number;
9
+ priority?: number;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { VideoPluginState } from "../types.js";
3
+ export declare const render: ViewRenderFunc<VideoPluginState>;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Screen, Video, createRenderFunc, useEffect, useState, useStoreState } from "@vnejs/uis.react";
3
+ import { getVideoVolume } from "@vnejs/contracts.settings.volume";
4
+ import { b } from "./index.styles.js";
5
+ const VideoViewComponent = ({ store, onMount, emit, shared, PARAMS, SETTINGS, EVENTS }) => {
6
+ const { isShow = false, isForce = false, src } = useStoreState(store, onMount);
7
+ const [isPlaying, setIsPlaying] = useState(false);
8
+ useEffect(() => {
9
+ const tm = setTimeout(() => setIsPlaying(isShow), PARAMS.VIDEO.TRANSITION);
10
+ return () => clearTimeout(tm);
11
+ }, [PARAMS.VIDEO.TRANSITION, isShow]);
12
+ const volume = getVideoVolume(shared.settings, SETTINGS.VOLUME?.COMMON, SETTINGS.VOLUME?.VIDEO);
13
+ const onHide = () => void emit(EVENTS.VIDEO.HIDE);
14
+ return (_jsx(Screen, { ...PARAMS.VIDEO.VIEW_PROPS.screen, onClick: onHide, isShow: isShow, isForce: isForce, children: src && (_jsx(Video, { className: b("video"), src: src, volume: volume, isPlaying: isPlaying, transition: isForce ? 0 : PARAMS.VIDEO.TRANSITION, onEnded: onHide })) }));
15
+ };
16
+ export const render = createRenderFunc(VideoViewComponent);
@@ -0,0 +1 @@
1
+ export declare const b: import("@bem-react/classname").ClassNameFormatter;
@@ -0,0 +1,15 @@
1
+ import { cn, injectStyles, sel } from "@vnejs/uis.utils";
2
+ export const b = cn("VideoView");
3
+ const CSS = `
4
+ ${sel(b("video"))} {
5
+ width: 100%;
6
+ height: 100%;
7
+ object-fit: fill;
8
+ }
9
+
10
+ ${sel(b("video"))}::-webkit-media-controls,
11
+ ${sel(b("video"))}::-webkit-media-controls-start-playback-button {
12
+ display: none !important;
13
+ }
14
+ `;
15
+ injectStyles(CSS);
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.common.video",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.14",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
20
+ "scripts": {
21
+ "test": "npx @vnejs/monorepo test",
22
+ "build": "npx @vnejs/monorepo package",
23
+ "publish:major:plugin": "npm run publish:major",
24
+ "publish:minor:plugin": "npm run publish:minor",
25
+ "publish:patch:plugin": "npm run publish:patch",
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
29
+ },
30
+ "author": "",
31
+ "license": "ISC",
32
+ "dependencies": {
33
+ "@vnejs/contracts.controllers.common.video": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.2.0",
37
+ "@vnejs/module.core": "~0.2.0",
38
+ "@vnejs/module.components": "~0.2.0",
39
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
40
+ "@vnejs/module.controller.interact": "~0.2.0",
41
+ "@vnejs/contracts.controls": "~0.2.0",
42
+ "@vnejs/contracts.settings.volume": "~0.2.0",
43
+ "@vnejs/contracts.controllers.scenario.interface": "~0.2.0",
44
+ "@vnejs/registry": "~0.2.0",
45
+ "@vnejs/uis.react": "~0.2.0",
46
+ "@vnejs/uis.utils": "~0.2.0"
47
+ },
48
+ "devDependencies": {
49
+ "@vnejs/configs.ts-common": "~0.2.0",
50
+ "@vnejs/configs.vitest": "~0.2.0",
51
+ "@vnejs/test-utils": "~0.2.0",
52
+ "@vnejs/contracts.canvas.layer": "~0.2.0",
53
+ "@vnejs/contracts.controls": "~0.2.0",
54
+ "@vnejs/contracts.settings.volume": "~0.2.0",
55
+ "@vnejs/contracts.controllers.scenario.interface": "~0.2.0",
56
+ "@vnejs/contracts.controllers.common.video": "~0.2.0",
57
+ "@vnejs/helpers": "~0.2.0",
58
+ "@vnejs/module.core": "~0.2.0",
59
+ "@vnejs/module.components": "~0.2.0",
60
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
61
+ "@vnejs/module.controller.interact": "~0.2.0",
62
+ "@vnejs/registry": "~0.2.0",
63
+ "@vnejs/sources-set": "~0.2.0",
64
+ "@vnejs/uis.react": "~0.2.0",
65
+ "@vnejs/uis.utils": "~0.2.0"
66
+ }
67
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import "@vnejs/contracts.controllers.common.video";
2
+
3
+ import { regPlugin } from "@vnejs/registry";
4
+
5
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.video";
6
+
7
+ import { VideoControllerInteract } from "./modules/controller.interact.js";
8
+ import { VideoController } from "./modules/controller.js";
9
+ import { VideoControllerSrc } from "./modules/controller.src.js";
10
+ import { VideoHideState } from "./modules/hide.state.js";
11
+ import { Video } from "./modules/video.js";
12
+ import { VideoView } from "./modules/view.js";
13
+
14
+ regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
15
+ VideoController,
16
+ VideoControllerInteract,
17
+ VideoControllerSrc,
18
+ VideoHideState,
19
+ Video,
20
+ VideoView,
21
+ ]);
@@ -0,0 +1,22 @@
1
+ import { ModuleControllerInteract } from "@vnejs/module.controller.interact";
2
+
3
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
4
+ import type { VideoPluginState } from "../types.js";
5
+
6
+ export class VideoControllerInteract extends ModuleControllerInteract<
7
+ VideoPluginEvents,
8
+ VideoPluginConstants,
9
+ VideoPluginSettings,
10
+ VideoPluginParams,
11
+ VideoPluginState
12
+ > {
13
+ name = "video.controller.interact";
14
+
15
+ EVENT_SHOW = this.EVENTS.VIDEO.SHOW;
16
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
17
+
18
+ CONTROLS_ZINDEX = this.PARAMS.VIDEO.ZINDEX;
19
+ CONTROLS_CHECK_NEXT = false;
20
+
21
+ onInteract = () => this.emit(this.EVENTS.VIDEO.HIDE);
22
+ }
@@ -0,0 +1,18 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { VideoSetSrcPayload } from "@vnejs/contracts.controllers.common.video";
4
+
5
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
6
+
7
+ export class VideoControllerSrc extends ModuleCore<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams> {
8
+ name = "video.controller.src";
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.VIDEO.SET_SRC, this.onSetSrc);
12
+ };
13
+
14
+ onSetSrc = async ({ src = "" }: VideoSetSrcPayload = {}) => {
15
+ await this.emit(this.EVENTS.VIDEO.UPDATE_STATE, { src });
16
+ await this.emit(this.EVENTS.VIDEO.UPDATE_FAST);
17
+ };
18
+ }
@@ -0,0 +1,21 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
4
+ import type { VideoPluginState } from "../types.js";
5
+
6
+ export class VideoController extends ModuleController<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState> {
7
+ name = "video.controller";
8
+
9
+ EVENT_UPDATE_VIEW = this.EVENTS.VIDEO.UPDATE;
10
+ EVENT_UPDATE_STATE = this.EVENTS.VIDEO.UPDATE_STATE;
11
+ EVENT_UPDATE_FAST = this.EVENTS.VIDEO.UPDATE_FAST;
12
+ EVENT_UPDATE_FORCE = this.EVENTS.VIDEO.UPDATE_FORCE;
13
+ EVENT_SHOW = this.EVENTS.VIDEO.SHOW;
14
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
15
+
16
+ onShowBefore = () => void this.emit(this.EVENTS.INTERFACE.TEXT_HIDE);
17
+ onHideAfter = () => {
18
+ this.emit(this.EVENTS.VIDEO.SET_SRC, { src: "" });
19
+ this.emit(this.EVENTS.SCENARIO.NEXT);
20
+ };
21
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+
3
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
4
+
5
+ export class VideoHideState extends ModuleControllerHideOnState<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams> {
6
+ name = "video.hide.state";
7
+
8
+ EVENT_HIDE = this.EVENTS.VIDEO.HIDE;
9
+
10
+ IS_STATE_SET_ENABLED = false;
11
+ }
@@ -0,0 +1,82 @@
1
+ import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
+
3
+ import type { LineExecHandlerArg, LineLoadHandlerArg } from "@vnejs/module.core";
4
+
5
+ import { tokenizeExecLine } from "@vnejs/helpers";
6
+
7
+ import type { VideoGetPayload, VideoLoadPayload, VideoPlayPayload, VideoSetPayload } from "@vnejs/contracts.controllers.common.video";
8
+
9
+ import type { VideoMediaArgs, VideoPluginModelState } from "../utils/video.js";
10
+
11
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
12
+
13
+ export class Video extends ModuleCore<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginModelState> {
14
+ name = "video";
15
+
16
+ subscribe = () => {
17
+ this.on(this.EVENTS.VIDEO.HIDE, this.setDefaultState);
18
+
19
+ this.on(this.EVENTS.VIDEO.PLAY, this.onVideoPlay);
20
+ this.on(this.EVENTS.VIDEO.LOAD, this.onVideoLoad);
21
+ this.on(this.EVENTS.VIDEO.GET, this.onVideoGet);
22
+ this.on(this.EVENTS.VIDEO.SET, this.onVideoSet);
23
+
24
+ this.on(this.EVENTS.STATE.SET, this.onStateSet);
25
+ };
26
+
27
+ init = () =>
28
+ Promise.all([
29
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec }),
30
+ this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.name, handler: this.onLineLoad }),
31
+ ]);
32
+
33
+ onLineExec = ({ line = "", args = {} }: LineExecHandlerArg = {}) => {
34
+ const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
35
+
36
+ if (action === this.CONST.VIDEO.EXEC_ACTIONS.PLAY) return this.emitPlay(tokens[0], args);
37
+ };
38
+
39
+ onLineLoad = ({ line = "", args = {}, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND }: LineLoadHandlerArg = {}) => {
40
+ const [action = "", ...tokens] = tokenizeExecLine(line).map(String);
41
+
42
+ if (action === this.CONST.VIDEO.EXEC_ACTIONS.PLAY) return this.emitLoad(tokens[0], args, priority);
43
+ };
44
+
45
+ onVideoPlay = async ({ name = "" }: VideoPlayPayload = {}) => {
46
+ await this.emit(this.EVENTS.VIDEO.SET, { name });
47
+ await this.emit(this.EVENTS.VIDEO.SHOW);
48
+ };
49
+
50
+ onVideoLoad = ({ name = "", priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND }: VideoLoadPayload = {}) =>
51
+ this.emit(this.EVENTS.MEDIA.LOAD, this.getMediaArgs(name, priority));
52
+
53
+ onVideoGet = ({ name = "" }: VideoGetPayload = {}) => this.emitOne(this.EVENTS.MEDIA.GET, this.getMediaArgs(name));
54
+
55
+ onVideoSet = async ({ name = "" }: VideoSetPayload = {}) => {
56
+ this.updateState({ name });
57
+
58
+ const video = (await this.emitOne(this.EVENTS.VIDEO.GET, { name })) as { src?: string } | null | undefined;
59
+
60
+ if (!video?.src) throw Error("no video");
61
+
62
+ this.emit(this.EVENTS.VIDEO.SET_SRC, { src: video.src });
63
+ };
64
+
65
+ onStateSet = async (payload: ModuleGlobalStateRegistry) => {
66
+ const { name = "" } = this.getStateSlice(payload);
67
+
68
+ name && this.emit(this.EVENTS.VIDEO.SET, { name });
69
+ };
70
+
71
+ getDefaultState = (): VideoPluginModelState => ({ name: "" });
72
+
73
+ emitPlay = async (name = "", args?: Record<string, unknown>) => this.emit(this.EVENTS.VIDEO.PLAY, { name, args });
74
+
75
+ getMediaArgs = (name: string, priority?: number): VideoMediaArgs => {
76
+ const type = this.CONST.MEDIA.TYPES.VIDEO;
77
+ const quality = this.shared.settings[this.SETTINGS.LAYER.QUALITY];
78
+
79
+ return { mediaType: this.name, type, name, quality, priority };
80
+ };
81
+ emitLoad = async (name = "", args?: Record<string, unknown>, priority?: number) => name && this.emit(this.EVENTS.VIDEO.LOAD, { name, args, priority });
82
+ }
@@ -0,0 +1,15 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
4
+ import type { VideoPluginState } from "../types.js";
5
+
6
+ import { render } from "../view/index.js";
7
+ export class VideoView extends ModuleView<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState> {
8
+ name = "video.view";
9
+
10
+ EVENT_UPDATE_VIEW = this.EVENTS.VIDEO.UPDATE;
11
+
12
+ TRANSITION = this.PARAMS.VIDEO.TRANSITION;
13
+
14
+ renderFunc = render;
15
+ }
@@ -0,0 +1,87 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
6
+ import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
7
+
8
+ import { VideoControllerInteract } from "../modules/controller.interact.js";
9
+
10
+ import { createVideoTestModule, registerVideoPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
11
+
12
+ describe("VideoControllerInteract", () => {
13
+ beforeEach(() => {
14
+ registerVideoPluginVne();
15
+ });
16
+
17
+ it("SHOW pushes ANY and interact handler", async () => {
18
+ const { module, observer } = createVideoTestModule(VideoControllerInteract);
19
+ const interact = module as VideoControllerInteract;
20
+ const controlsPush = spyEvent(observer, CONTROLS_EVENTS.PUSH);
21
+ const interactPush = spyEvent(observer, INTERACT_EVENTS.PUSH);
22
+
23
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
24
+
25
+ expect(controlsPush).toHaveBeenCalledExactlyOnceWith(
26
+ expect.objectContaining({
27
+ key: "video.controller.interact",
28
+ checkNext: false,
29
+ index: interact.PARAMS.VIDEO.ZINDEX + 1,
30
+ }),
31
+ );
32
+ expect(controlsPush.mock.calls[0][0].controls).toHaveProperty(interact.CONST.CONTROLS.BUTTONS.ANY);
33
+ expect(interactPush).toHaveBeenCalledExactlyOnceWith(
34
+ expect.objectContaining({
35
+ key: "video.controller.interact",
36
+ }),
37
+ );
38
+ });
39
+
40
+ it("ANY emits INTERACT.EMIT", async () => {
41
+ const { module, observer } = createVideoTestModule(VideoControllerInteract);
42
+ const interact = module as VideoControllerInteract;
43
+ const emit = spyEvent(observer, INTERACT_EVENTS.EMIT);
44
+
45
+ interact.CONTROLS[interact.CONST.CONTROLS.BUTTONS.ANY]();
46
+ await Promise.resolve();
47
+
48
+ expect(emit).toHaveBeenCalledOnce();
49
+ });
50
+
51
+ it("interact handler emits VIDEO.HIDE", async () => {
52
+ const { observer } = createVideoTestModule(VideoControllerInteract);
53
+ const interactPush = spyEvent(observer, INTERACT_EVENTS.PUSH);
54
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
55
+
56
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
57
+
58
+ const { handler } = interactPush.mock.calls[0][0] as { handler: () => void | Promise<unknown> };
59
+
60
+ await handler();
61
+
62
+ expect(hide).toHaveBeenCalledOnce();
63
+ });
64
+
65
+ it("HIDE pops interact and controls", async () => {
66
+ const { observer } = createVideoTestModule(VideoControllerInteract);
67
+ const interactPop = spyEvent(observer, INTERACT_EVENTS.POP);
68
+ const controlsPop = spyEvent(observer, CONTROLS_EVENTS.POP);
69
+
70
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
71
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
72
+
73
+ expect(interactPop).toHaveBeenCalledExactlyOnceWith({ key: "video.controller.interact" });
74
+ expect(controlsPop).toHaveBeenCalledExactlyOnceWith({ key: "video.controller.interact" });
75
+ });
76
+
77
+ it("HIDE without SHOW pops interact and controls", async () => {
78
+ const { observer } = createVideoTestModule(VideoControllerInteract);
79
+ const interactPop = spyEvent(observer, INTERACT_EVENTS.POP);
80
+ const controlsPop = spyEvent(observer, CONTROLS_EVENTS.POP);
81
+
82
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
83
+
84
+ expect(interactPop).toHaveBeenCalledExactlyOnceWith({ key: "video.controller.interact" });
85
+ expect(controlsPop).toHaveBeenCalledExactlyOnceWith({ key: "video.controller.interact" });
86
+ });
87
+ });
@@ -0,0 +1,24 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { VideoControllerSrc } from "../modules/controller.src.js";
6
+
7
+ import { createVideoTestModule, registerVideoPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("VideoControllerSrc", () => {
10
+ beforeEach(() => {
11
+ registerVideoPluginVne();
12
+ });
13
+
14
+ it("SET_SRC emits UPDATE_STATE and UPDATE_FAST", async () => {
15
+ const { observer } = createVideoTestModule(VideoControllerSrc);
16
+ const updateState = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
17
+ const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
18
+
19
+ await observer.emit(SUBSCRIBE_EVENTS.SET_SRC, { src: "video.mp4" });
20
+
21
+ expect(updateState).toHaveBeenCalledWith({ src: "video.mp4" });
22
+ expect(updateFast).toHaveBeenCalledOnce();
23
+ });
24
+ });
@@ -0,0 +1,37 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { VideoController } from "../modules/controller.js";
6
+
7
+ import { createVideoTestModule, INTERFACE_EVENTS, registerVideoPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("VideoController", () => {
10
+ beforeEach(() => {
11
+ registerVideoPluginVne();
12
+ });
13
+
14
+ it("SHOW hides interface text before display", async () => {
15
+ const { observer } = createVideoTestModule(VideoController);
16
+ const textHide = spyEvent(observer, INTERFACE_EVENTS.TEXT_HIDE);
17
+
18
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
19
+
20
+ expect(textHide).toHaveBeenCalledOnce();
21
+ });
22
+
23
+ it("HIDE clears src and emits next", async () => {
24
+ const { module, observer } = createVideoTestModule(VideoController);
25
+
26
+ (module as VideoController).state = { src: "video.mp4", isShow: true, isForce: false };
27
+
28
+ const setSrc = spyEvent(observer, SUBSCRIBE_EVENTS.SET_SRC);
29
+ const next = spyEvent(observer, "vne:scenario:next");
30
+
31
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
32
+
33
+ expect(setSrc).toHaveBeenCalledWith({ src: "" });
34
+ expect(next).toHaveBeenCalledOnce();
35
+ expect((module as VideoController).state.isShow).toBe(false);
36
+ });
37
+ });
@@ -0,0 +1,25 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
6
+
7
+ import { VideoHideState } from "../modules/hide.state.js";
8
+
9
+ import { createVideoTestModule, registerVideoPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("VideoHideState", () => {
12
+ beforeEach(() => {
13
+ registerVideoPluginVne();
14
+ });
15
+
16
+ it("STATE.CLEAR emits HIDE with isForce and STATE.SET does not", async () => {
17
+ const { observer } = createVideoTestModule(VideoHideState);
18
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
19
+
20
+ await observer.emit(STATE_EVENTS.SET);
21
+ await observer.emit(STATE_EVENTS.CLEAR);
22
+
23
+ expect(hide).toHaveBeenCalledExactlyOnceWith({ isForce: true });
24
+ });
25
+ });
@@ -0,0 +1,56 @@
1
+ import { SourcesSet } from "@vnejs/sources-set";
2
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
3
+
4
+ import { CONSTANTS as LAYER_CONST, PLUGIN_NAME as LAYER, SETTINGS_KEYS as LAYER_SETTINGS } from "@vnejs/contracts.canvas.layer";
5
+ import { CONSTANTS, PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.video";
6
+ import { PARAMS as INTERFACE_PARAMS, PLUGIN_NAME as INTERFACE, SUBSCRIBE_EVENTS as INTERFACE_EVENTS } from "@vnejs/contracts.controllers.scenario.interface";
7
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
8
+ import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
9
+
10
+ export const registerVideoPluginVne = () => {
11
+ registerCoreVne();
12
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
13
+ registerVnePlugin(LAYER, { constants: LAYER_CONST, settings: LAYER_SETTINGS });
14
+ registerVnePlugin(INTERFACE, { events: INTERFACE_EVENTS, params: INTERFACE_PARAMS });
15
+ registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS });
16
+ };
17
+
18
+ export const createVideoTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
19
+ ModuleClass: T,
20
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
21
+ ) => {
22
+ let mediaSrc = "video.mp4";
23
+
24
+ const result = baseCreateTestModule(ModuleClass, {
25
+ state: {
26
+ "video": { name: "" },
27
+ "video.controller": { src: "", isShow: false },
28
+ ...(options.state ?? {}),
29
+ },
30
+ shared: {
31
+ settings: { [LAYER_SETTINGS.QUALITY]: LAYER_CONST.QUALITIES.FHD },
32
+ viewForceAnimationSources: new SourcesSet(),
33
+ ...(options.shared ?? {}),
34
+ },
35
+ ...options,
36
+ });
37
+
38
+ stubEvent(result.observer, MEDIA_EVENTS.GET, () => (mediaSrc ? { src: mediaSrc } : {}));
39
+ stubSilentEvent(result.observer, MEDIA_EVENTS.LOAD);
40
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
41
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
42
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
43
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SET_SRC);
44
+ stubSilentEvent(result.observer, INTERFACE_EVENTS.TEXT_HIDE);
45
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
46
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
47
+
48
+ return {
49
+ ...result,
50
+ setMediaSrc: (src: string) => {
51
+ mediaSrc = src;
52
+ },
53
+ };
54
+ };
55
+
56
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, INTERFACE_EVENTS };
@@ -0,0 +1,54 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
6
+
7
+ import { Video } from "../modules/video.js";
8
+
9
+ import { createVideoTestModule, registerVideoPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("Video", () => {
12
+ beforeEach(() => {
13
+ registerVideoPluginVne();
14
+ });
15
+
16
+ it("PLAY sets video and shows", async () => {
17
+ const { module, observer } = createVideoTestModule(Video);
18
+ const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
19
+ const setSrc = spyEvent(observer, SUBSCRIBE_EVENTS.SET_SRC);
20
+
21
+ await observer.emit(SUBSCRIBE_EVENTS.PLAY, { name: "intro" });
22
+
23
+ expect((module as Video).state.name).toBe("intro");
24
+ expect(setSrc).toHaveBeenCalledExactlyOnceWith({ src: "video.mp4" });
25
+ expect(show).toHaveBeenCalledOnce();
26
+ });
27
+
28
+ it("LOAD emits MEDIA.LOAD", async () => {
29
+ const { observer } = createVideoTestModule(Video);
30
+ const load = spyEvent(observer, MEDIA_EVENTS.LOAD);
31
+
32
+ await observer.emit(SUBSCRIBE_EVENTS.LOAD, { name: "intro" });
33
+
34
+ expect(load).toHaveBeenCalledOnce();
35
+ });
36
+
37
+ it("SET throws when video has no src", async () => {
38
+ const { observer, setMediaSrc } = createVideoTestModule(Video);
39
+
40
+ setMediaSrc("");
41
+
42
+ await expect(observer.emit(SUBSCRIBE_EVENTS.SET, { name: "missing" })).rejects.toThrow("no video");
43
+ });
44
+
45
+ it("line exec play emits PLAY", async () => {
46
+ const { module, observer } = createVideoTestModule(Video, { subscribe: false });
47
+ const play = spyEvent(observer, SUBSCRIBE_EVENTS.PLAY);
48
+
49
+ await (module as Video).init();
50
+ await (module as Video).onLineExec({ line: "play intro" });
51
+
52
+ expect(play).toHaveBeenCalledExactlyOnceWith({ name: "intro", args: {} });
53
+ });
54
+ });
package/src/types.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+
3
+ import type { Constants, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.common.video";
4
+ import type { PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/contracts.controllers.scenario.interface";
5
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
6
+ import type { PluginName as InteractPluginName, SubscribeEvents as InteractSubscribeEvents } from "@vnejs/contracts.core.interact";
7
+ import type { Constants as MediaConstants, PluginName as MediaPluginName, SubscribeEvents as MediaSubscribeEvents } from "@vnejs/contracts.core.media";
8
+ import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
9
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
10
+ import type { SettingsKeys as VolumeSettingsKeys, PluginName as VolumePluginName } from "@vnejs/contracts.settings.volume";
11
+
12
+ export type VideoPluginEvents = ModuleComponentsEvents &
13
+ Record<PluginName, SubscribeEvents> &
14
+ Record<ScenarioPluginName, ScenarioSubscribeEvents> &
15
+ Record<MediaPluginName, MediaSubscribeEvents> &
16
+ Record<StatePluginName, StateSubscribeEvents> &
17
+ Record<InteractPluginName, InteractSubscribeEvents> &
18
+ Record<InterfacePluginName, InterfaceSubscribeEvents>;
19
+
20
+ export type VideoPluginConstants = ModuleComponentsConstants &
21
+ Record<PluginName, Constants> &
22
+ Record<MediaPluginName, MediaConstants> &
23
+ Record<ControlsPluginName, ControlsConstants>;
24
+
25
+ export type VideoPluginSettings = ModuleComponentsSettings & Record<VolumePluginName, VolumeSettingsKeys>;
26
+
27
+ export type VideoPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
28
+
29
+ export type VideoPluginState = {
30
+ isShow: boolean;
31
+ isForce: boolean;
32
+ src?: string;
33
+ };
@@ -0,0 +1,11 @@
1
+ export type VideoPluginModelState = {
2
+ name: string;
3
+ };
4
+
5
+ export type VideoMediaArgs = {
6
+ mediaType?: string;
7
+ type?: string;
8
+ name?: string;
9
+ quality?: string | number;
10
+ priority?: number;
11
+ };
@@ -0,0 +1,18 @@
1
+ import { cn, injectStyles, sel } from "@vnejs/uis.utils";
2
+
3
+ export const b = cn("VideoView");
4
+
5
+ const CSS = `
6
+ ${sel(b("video"))} {
7
+ width: 100%;
8
+ height: 100%;
9
+ object-fit: fill;
10
+ }
11
+
12
+ ${sel(b("video"))}::-webkit-media-controls,
13
+ ${sel(b("video"))}::-webkit-media-controls-start-playback-button {
14
+ display: none !important;
15
+ }
16
+ `;
17
+
18
+ injectStyles(CSS);
@@ -0,0 +1,51 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+
3
+ import { Screen, Video, createRenderFunc, useEffect, useState, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { ReactComponentProps } from "@vnejs/uis.react";
6
+
7
+ import { getVideoVolume } from "@vnejs/contracts.settings.volume";
8
+
9
+ import type { VideoPluginConstants, VideoPluginEvents, VideoPluginParams, VideoPluginSettings } from "../types.js";
10
+ import type { VideoPluginState } from "../types.js";
11
+
12
+ import { b } from "./index.styles.js";
13
+
14
+ type VideoComponentProps = ReactComponentProps<VideoPluginEvents, VideoPluginConstants, VideoPluginSettings, VideoPluginParams, VideoPluginState>;
15
+
16
+ const VideoViewComponent = ({ store, onMount, emit, shared, PARAMS, SETTINGS, EVENTS }: VideoComponentProps) => {
17
+ const { isShow = false, isForce = false, src } = useStoreState<VideoPluginState>(store, onMount);
18
+ const [isPlaying, setIsPlaying] = useState(false);
19
+
20
+ useEffect(() => {
21
+ const tm = setTimeout(() => setIsPlaying(isShow), PARAMS.VIDEO.TRANSITION);
22
+
23
+ return () => clearTimeout(tm);
24
+ }, [PARAMS.VIDEO.TRANSITION, isShow]);
25
+
26
+ const volume = getVideoVolume(shared.settings, SETTINGS.VOLUME?.COMMON, SETTINGS.VOLUME?.VIDEO);
27
+
28
+ const onHide = () => void emit(EVENTS.VIDEO.HIDE);
29
+
30
+ return (
31
+ <Screen
32
+ {...PARAMS.VIDEO.VIEW_PROPS.screen}
33
+ onClick={onHide}
34
+ isShow={isShow}
35
+ isForce={isForce}
36
+ >
37
+ {src && (
38
+ <Video
39
+ className={b("video")}
40
+ src={src}
41
+ volume={volume}
42
+ isPlaying={isPlaying}
43
+ transition={isForce ? 0 : PARAMS.VIDEO.TRANSITION}
44
+ onEnded={onHide}
45
+ />
46
+ )}
47
+ </Screen>
48
+ );
49
+ };
50
+
51
+ export const render: ViewRenderFunc<VideoPluginState> = createRenderFunc(VideoViewComponent);
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "jsx": "react-jsx"
7
+ },
8
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
9
+ "exclude": ["dist", "node_modules", "src/tests"]
10
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.