@vnejs/plugins.core.media 0.0.1 → 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.
- package/const/const.js +1 -5
- package/index.d.ts +18 -0
- package/modules/load.js +5 -9
- package/modules/media.js +4 -5
- package/package.json +4 -6
package/const/const.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
export const TYPES = { IMAGE: "image", AUDIO: "audio", VIDEO: "video" };
|
|
2
2
|
|
|
3
|
-
export const CONSTRUCTORS = {
|
|
4
|
-
[TYPES.IMAGE]: Image,
|
|
5
|
-
[TYPES.AUDIO]: Audio,
|
|
6
|
-
[TYPES.VIDEO]: HTMLVideoElement,
|
|
7
|
-
};
|
|
3
|
+
export const CONSTRUCTORS = { [TYPES.IMAGE]: Image, [TYPES.AUDIO]: Audio, [TYPES.VIDEO]: HTMLVideoElement };
|
|
8
4
|
|
|
9
5
|
export const PRIORITIES = { HIGH: 0, MEDIUM: 1, LOW: 2, BACKGROUND: 3 };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as constants from "./const/const";
|
|
2
|
+
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
3
|
+
import { SETTINGS_KEYS } from "./const/settings";
|
|
4
|
+
|
|
5
|
+
type SubscribeEventsType = typeof SUBSCRIBE_EVENTS;
|
|
6
|
+
type SettingsKeysType = typeof SETTINGS_KEYS;
|
|
7
|
+
type ConstantsType = typeof constants;
|
|
8
|
+
|
|
9
|
+
const PLUGIN_NAME = "MEDIA";
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
interface CONST {
|
|
13
|
+
[PLUGIN_NAME]: ConstantsType;
|
|
14
|
+
}
|
|
15
|
+
interface EVENTS {
|
|
16
|
+
[PLUGIN_NAME]: SubscribeEventsType;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/modules/load.js
CHANGED
|
@@ -40,7 +40,7 @@ export class MediaLoad extends Module {
|
|
|
40
40
|
return this.emitOne(this.EVENTS.MEDIA.MEMORY_GET, { mediaId });
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
onMediaLoadCheck = async (mediaId) => {
|
|
43
|
+
onMediaLoadCheck = async ({ mediaId } = {}) => {
|
|
44
44
|
if (this.inProcess[mediaId]) return this.inProcess[mediaId];
|
|
45
45
|
|
|
46
46
|
const oldMedia = await this.emitOne(this.EVENTS.MEDIA.MEMORY_GET, { mediaId });
|
|
@@ -63,17 +63,14 @@ export class MediaLoad extends Module {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
loadMedia = async (mediaId, type, src, priority, isConstant = false, isTmp = false) => {
|
|
66
|
-
this.
|
|
66
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "load start", mediaId, type, priority, isConstant, isTmp } });
|
|
67
67
|
|
|
68
68
|
const ts = Math.round(new Date().getTime() / 1000 / 60 / 60);
|
|
69
69
|
const mediaSrc = `${src}?ts=${ts}&version=${this.options?.global?.version || 0}`;
|
|
70
70
|
const splitSrc = src.split(".");
|
|
71
71
|
const ext = splitSrc[splitSrc.length - 1];
|
|
72
72
|
const mediaRequest = await fetch(mediaSrc);
|
|
73
|
-
const media =
|
|
74
|
-
type === this.CONST.MEDIA.TYPES.VIDEO
|
|
75
|
-
? document.createElement("video")
|
|
76
|
-
: new this.CONST.MEDIA.CONSTRUCTORS[type]();
|
|
73
|
+
const media = type === this.CONST.MEDIA.TYPES.VIDEO ? document.createElement("video") : new this.CONST.MEDIA.CONSTRUCTORS[type]();
|
|
77
74
|
media.setAttribute("ext", ext);
|
|
78
75
|
media.setAttribute("type", type);
|
|
79
76
|
// IOS - mediaSrc
|
|
@@ -86,10 +83,9 @@ export class MediaLoad extends Module {
|
|
|
86
83
|
|
|
87
84
|
await this.emit(this.EVENTS.MEDIA.SET, { media, mediaId, isConstant, isTmp });
|
|
88
85
|
|
|
89
|
-
if (priority && !this.shared.mediaNoTimeoutSources.length)
|
|
90
|
-
await this.waitTimeout(Math.round(25 * priority * (Math.random() + 0.618)));
|
|
86
|
+
if (priority && !this.shared.mediaNoTimeoutSources.length) await this.waitTimeout(Math.round(25 * priority * (Math.random() + 0.618)));
|
|
91
87
|
|
|
92
|
-
this.
|
|
88
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "load end", mediaId, type, priority, isConstant, isTmp } });
|
|
93
89
|
|
|
94
90
|
return media;
|
|
95
91
|
};
|
package/modules/media.js
CHANGED
|
@@ -17,15 +17,14 @@ export class Media extends Module {
|
|
|
17
17
|
|
|
18
18
|
if (!realMediaId) return null;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
let media = await this.emitOne(this.EVENTS.MEDIA.MEMORY_GET, { mediaId: realMediaId });
|
|
21
|
+
|
|
22
|
+
if (!media) media = await this.loadMedia(type, name, mediaType, quality, postfix);
|
|
23
23
|
|
|
24
24
|
return this.prepareMedia(media);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
onMediaSet = async ({ mediaId, media, isConstant, isTmp } = {}) =>
|
|
28
|
-
this.emit(this.EVENTS.MEDIA.MEMORY_SET, { mediaId, media, isConstant, isTmp });
|
|
27
|
+
onMediaSet = async ({ mediaId, media, isConstant, isTmp } = {}) => this.emit(this.EVENTS.MEDIA.MEMORY_SET, { mediaId, media, isConstant, isTmp });
|
|
29
28
|
|
|
30
29
|
loadMedia = (type, name, mediaType, quality, postfix) => {
|
|
31
30
|
const priority = this.CONST.MEDIA.PRIORITIES.HIGH;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.core.media",
|
|
3
|
-
"version": "0.
|
|
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"
|
|
@@ -13,10 +16,5 @@
|
|
|
13
16
|
"description": "",
|
|
14
17
|
"dependencies": {
|
|
15
18
|
"decode-gif": "1.0.1"
|
|
16
|
-
},
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"@vnejs/shared": "*",
|
|
19
|
-
"@vnejs/module": "*",
|
|
20
|
-
"@vnejs/semaphore": "*"
|
|
21
19
|
}
|
|
22
20
|
}
|