@iyio/media-common 0.6.5 → 0.7.2
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/esm/src/lib/MediaRecording.js +110 -115
- package/esm/src/lib/MediaRecording.js.map +1 -1
- package/esm/src/lib/VideoElementMonitor.js +11 -13
- package/esm/src/lib/VideoElementMonitor.js.map +1 -1
- package/esm/src/lib/blurhash.js +5 -7
- package/esm/src/lib/blurhash.js.map +1 -1
- package/esm/src/lib/media-lib.js +24 -30
- package/esm/src/lib/media-lib.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/MediaRecording.js +110 -115
- package/src/lib/MediaRecording.js.map +1 -1
- package/src/lib/VideoElementMonitor.js +11 -13
- package/src/lib/VideoElementMonitor.js.map +1 -1
- package/src/lib/blurhash.js +5 -7
- package/src/lib/blurhash.js.map +1 -1
- package/src/lib/media-lib.js +24 -30
- package/src/lib/media-lib.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iyio/media-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"blurhash": ">=2.0.5",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"zod": ">=3.21.4"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@iyio/common": "^0.
|
|
13
|
+
"@iyio/common": "^0.7.2"
|
|
14
14
|
},
|
|
15
15
|
"main": "./src/index.js",
|
|
16
16
|
"module": "./esm/src/index.js"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MediaRecording = exports.defaultMediaRecordingVideoKBPerSecond = exports.defaultMediaRecordingAudioKBPerSecond = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const common_1 = require("@iyio/common");
|
|
6
5
|
const rxjs_1 = require("rxjs");
|
|
7
6
|
exports.defaultMediaRecordingAudioKBPerSecond = 2;
|
|
@@ -23,170 +22,166 @@ class MediaRecording {
|
|
|
23
22
|
this.isPaused = false;
|
|
24
23
|
this.recordPromise = null;
|
|
25
24
|
this.endSource = null;
|
|
26
|
-
this.options =
|
|
25
|
+
this.options = { ...options };
|
|
27
26
|
}
|
|
28
27
|
get isDisposed() { return this._isDisposed; }
|
|
29
28
|
get isStopped() { return this._isDisposed; }
|
|
30
29
|
dispose() {
|
|
31
|
-
var _a, _b;
|
|
32
30
|
if (this._isDisposed) {
|
|
33
31
|
return;
|
|
34
32
|
}
|
|
35
33
|
this._isDisposed = true;
|
|
36
34
|
try {
|
|
37
|
-
|
|
35
|
+
this._recorder.value?.stop();
|
|
38
36
|
}
|
|
39
|
-
catch
|
|
37
|
+
catch {
|
|
40
38
|
//
|
|
41
39
|
}
|
|
42
|
-
|
|
40
|
+
this.endSource?.resolve();
|
|
43
41
|
}
|
|
44
42
|
start() {
|
|
45
43
|
this.recordAsync();
|
|
46
44
|
}
|
|
47
|
-
recordAsync() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return yield this.recordPromise;
|
|
53
|
-
});
|
|
45
|
+
async recordAsync() {
|
|
46
|
+
if (!this.recordPromise) {
|
|
47
|
+
this.recordPromise = this._recordAsync();
|
|
48
|
+
}
|
|
49
|
+
return await this.recordPromise;
|
|
54
50
|
}
|
|
55
|
-
_recordAsync() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
async _recordAsync() {
|
|
52
|
+
if (this._isDisposed) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const getOptions = () => {
|
|
56
|
+
const mo = {
|
|
57
|
+
audioBitsPerSecond: (this.options.audioKBPerSecond ?? exports.defaultMediaRecordingAudioKBPerSecond) * 8000,
|
|
58
|
+
videoBitsPerSecond: (this.options.videoKBPerSecond ?? exports.defaultMediaRecordingVideoKBPerSecond) * 8000,
|
|
59
|
+
mimeType: this.options.mimeType,
|
|
60
|
+
...this.options.recorderOptions,
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
recorder = new MediaRecorder(stream, getOptions());
|
|
79
|
-
}
|
|
80
|
-
if (!recorder && this.options.stream) {
|
|
81
|
-
recorder = new MediaRecorder(this.options.stream, getOptions());
|
|
82
|
-
}
|
|
83
|
-
let disposeStream = null;
|
|
84
|
-
if (!recorder && this.options.mediaConstraints) {
|
|
85
|
-
const ary = (_a = (0, common_1.asArray)(this.options.mediaConstraints)) !== null && _a !== void 0 ? _a : [];
|
|
86
|
-
for (const mc of ary) {
|
|
87
|
-
if (!mc) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
const stream = yield navigator.mediaDevices.getUserMedia(mc);
|
|
92
|
-
if (!stream) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
disposeStream = stream;
|
|
96
|
-
recorder = new MediaRecorder(stream, getOptions());
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
catch (_c) {
|
|
100
|
-
//
|
|
101
|
-
}
|
|
62
|
+
return mo;
|
|
63
|
+
};
|
|
64
|
+
let recorder = this.options.recorder;
|
|
65
|
+
if (!recorder && this.options.streams) {
|
|
66
|
+
const stream = new MediaStream();
|
|
67
|
+
const streams = this.options.stream ?
|
|
68
|
+
[this.options.stream, ...this.options.streams] :
|
|
69
|
+
this.options.streams;
|
|
70
|
+
for (const s of streams) {
|
|
71
|
+
const tracks = s.getTracks();
|
|
72
|
+
for (const t of tracks) {
|
|
73
|
+
stream.addTrack(t);
|
|
102
74
|
}
|
|
103
75
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
76
|
+
recorder = new MediaRecorder(stream, getOptions());
|
|
77
|
+
}
|
|
78
|
+
if (!recorder && this.options.stream) {
|
|
79
|
+
recorder = new MediaRecorder(this.options.stream, getOptions());
|
|
80
|
+
}
|
|
81
|
+
let disposeStream = null;
|
|
82
|
+
if (!recorder && this.options.mediaConstraints) {
|
|
83
|
+
const ary = (0, common_1.asArray)(this.options.mediaConstraints) ?? [];
|
|
84
|
+
for (const mc of ary) {
|
|
85
|
+
if (!mc) {
|
|
86
|
+
continue;
|
|
115
87
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (!
|
|
119
|
-
|
|
88
|
+
try {
|
|
89
|
+
const stream = await navigator.mediaDevices.getUserMedia(mc);
|
|
90
|
+
if (!stream) {
|
|
91
|
+
continue;
|
|
120
92
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
recorder.addEventListener('pause', () => this.isPaused = true);
|
|
126
|
-
recorder.addEventListener('resume', () => this.isPaused = false);
|
|
127
|
-
recorder.addEventListener('stop', () => { this._recording.next(false); endSource.resolve(); });
|
|
128
|
-
recorder.addEventListener('start', () => this._recording.next(true));
|
|
129
|
-
recorder.addEventListener('error', e => endSource.reject(e));
|
|
130
|
-
if (this.options.timesliceMs) {
|
|
131
|
-
recorder.start(this.options.timesliceMs);
|
|
93
|
+
disposeStream = stream;
|
|
94
|
+
recorder = new MediaRecorder(stream, getOptions());
|
|
95
|
+
break;
|
|
132
96
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
if (this.isPaused) {
|
|
137
|
-
recorder.pause();
|
|
138
|
-
}
|
|
139
|
-
this.endSource = endSource;
|
|
140
|
-
this._recorder.next(recorder);
|
|
141
|
-
yield endSource.promise;
|
|
142
|
-
const start = Date.now();
|
|
143
|
-
while (!data.length && Date.now() - start < 2000) {
|
|
144
|
-
yield (0, common_1.delayAsync)(1);
|
|
97
|
+
catch {
|
|
98
|
+
//
|
|
145
99
|
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!recorder) {
|
|
103
|
+
throw new Error('Unable to stream for recording');
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const data = [];
|
|
107
|
+
if (this._isDisposed) {
|
|
146
108
|
return {
|
|
147
109
|
recorder,
|
|
148
110
|
data,
|
|
149
|
-
mimeType:
|
|
111
|
+
mimeType: '',
|
|
150
112
|
};
|
|
151
113
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
t.stop();
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
catch (_d) {
|
|
160
|
-
//
|
|
161
|
-
}
|
|
114
|
+
const endSource = (0, common_1.createPromiseSource)();
|
|
115
|
+
recorder.addEventListener('dataavailable', e => {
|
|
116
|
+
if (!this.options.storeAllData) {
|
|
117
|
+
data.splice(0, data.length);
|
|
162
118
|
}
|
|
119
|
+
data.push(e.data);
|
|
120
|
+
this._data.next([...data]);
|
|
121
|
+
this._onData.next(e.data);
|
|
122
|
+
});
|
|
123
|
+
recorder.addEventListener('pause', () => this.isPaused = true);
|
|
124
|
+
recorder.addEventListener('resume', () => this.isPaused = false);
|
|
125
|
+
recorder.addEventListener('stop', () => { this._recording.next(false); endSource.resolve(); });
|
|
126
|
+
recorder.addEventListener('start', () => this._recording.next(true));
|
|
127
|
+
recorder.addEventListener('error', e => endSource.reject(e));
|
|
128
|
+
if (this.options.timesliceMs) {
|
|
129
|
+
recorder.start(this.options.timesliceMs);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
recorder.start();
|
|
133
|
+
}
|
|
134
|
+
if (this.isPaused) {
|
|
135
|
+
recorder.pause();
|
|
136
|
+
}
|
|
137
|
+
this.endSource = endSource;
|
|
138
|
+
this._recorder.next(recorder);
|
|
139
|
+
await endSource.promise;
|
|
140
|
+
const start = Date.now();
|
|
141
|
+
while (!data.length && Date.now() - start < 2000) {
|
|
142
|
+
await (0, common_1.delayAsync)(1);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
recorder,
|
|
146
|
+
data,
|
|
147
|
+
mimeType: recorder.mimeType,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
if (disposeStream) {
|
|
163
152
|
try {
|
|
164
|
-
(
|
|
153
|
+
disposeStream.getTracks().forEach(t => {
|
|
154
|
+
t.stop();
|
|
155
|
+
});
|
|
165
156
|
}
|
|
166
|
-
catch
|
|
157
|
+
catch {
|
|
167
158
|
//
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
|
-
|
|
161
|
+
try {
|
|
162
|
+
this._recorder.value?.stop();
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
//
|
|
166
|
+
}
|
|
167
|
+
}
|
|
171
168
|
}
|
|
172
169
|
stop() {
|
|
173
170
|
this.dispose();
|
|
174
171
|
}
|
|
175
172
|
pause() {
|
|
176
|
-
var _a;
|
|
177
173
|
if (this.isPaused) {
|
|
178
174
|
return;
|
|
179
175
|
}
|
|
180
176
|
this.isPaused = true;
|
|
181
|
-
|
|
177
|
+
this._recorder.value?.pause();
|
|
182
178
|
}
|
|
183
179
|
resume() {
|
|
184
|
-
var _a;
|
|
185
180
|
if (!this.isPaused) {
|
|
186
181
|
return;
|
|
187
182
|
}
|
|
188
183
|
this.isPaused = false;
|
|
189
|
-
|
|
184
|
+
this._recorder.value?.resume();
|
|
190
185
|
}
|
|
191
186
|
}
|
|
192
187
|
exports.MediaRecording = MediaRecording;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MediaRecording.js","sourceRoot":"","sources":["../../../../../packages/media-common/src/lib/MediaRecording.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MediaRecording.js","sourceRoot":"","sources":["../../../../../packages/media-common/src/lib/MediaRecording.ts"],"names":[],"mappings":";;;AAAA,yCAAwG;AACxG,+BAA4D;AAG/C,QAAA,qCAAqC,GAAC,CAAC,CAAC;AACxC,QAAA,qCAAqC,GAAC,EAAE,CAAC;AAsCtD,MAAa,cAAc;IAMvB,IAAW,eAAe,KAAuC,OAAO,IAAI,CAAC,SAAS,CAAA,CAAA,CAAC;IACvF,IAAW,QAAQ,KAAG,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAA,CAAA,CAAC;IAGlD,IAAW,WAAW,KAA2B,OAAO,IAAI,CAAC,KAAK,CAAA,CAAA,CAAC;IACnE,IAAW,IAAI,KAAG,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA,CAAA,CAAC;IAG1C,IAAW,gBAAgB,KAA4B,OAAO,IAAI,CAAC,UAAU,CAAA,CAAA,CAAC;IAC9E,IAAW,SAAS,KAAG,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAA,CAAA,CAAC;IAGpD,IAAW,MAAM,KAAoB,OAAO,IAAI,CAAC,OAAO,CAAA,CAAA,CAAC;IAGzD,YAAmB,OAA6B;QAhB/B,cAAS,GAAqC,IAAI,sBAAe,CAAqB,IAAI,CAAC,CAAC;QAI5F,UAAK,GAAyB,IAAI,sBAAe,CAAS,EAAE,CAAC,CAAC;QAI9D,eAAU,GAA0B,IAAI,sBAAe,CAAU,KAAK,CAAC,CAAC;QAIxE,YAAO,GAAC,IAAI,cAAO,EAAQ,CAAC;QASrC,gBAAW,GAAC,KAAK,CAAC;QAiBlB,aAAQ,GAAC,KAAK,CAAC;QAOf,kBAAa,GAAyC,IAAI,CAAC;QAS3D,cAAS,GAA0B,IAAI,CAAC;QApC5C,IAAI,CAAC,OAAO,GAAC,EAAC,GAAG,OAAO,EAAC,CAAC;IAC9B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AC,QAAQ;aAC7B,CAAA;QACL,CAAC;gBAAO,CAAC;YACL,IAAG,aAAa,EAAC,CAAC;gBACd,IAAG,CAAC;oBACA,aAAa,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA,EAAE;wBACjC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACb,CAAC,CAAC,CAAA;gBACN,CAAC;gBAAA,MAAK,CAAC;oBACH,EAAE;gBACN,CAAC;YACL,CAAC;YACD,IAAG,CAAC;gBACA,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC;YACjC,CAAC;YAAA,MAAK,CAAC;gBACH,EAAE;YACN,CAAC;QACL,CAAC;IACL,CAAC;IAEM,IAAI;QAEP,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAEM,KAAK;QAER,IAAG,IAAI,CAAC,QAAQ,EAAC,CAAC;YACd,OAAO;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,GAAC,IAAI,CAAC;QACnB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAElC,CAAC;IAEM,MAAM;QAET,IAAG,CAAC,IAAI,CAAC,QAAQ,EAAC,CAAC;YACf,OAAO;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,GAAC,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;IACnC,CAAC;CACJ;AArND,wCAqNC"}
|
|
@@ -46,7 +46,6 @@ class VideoElementMonitor {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
init() {
|
|
49
|
-
var _a, _b, _c, _d, _e;
|
|
50
49
|
if (this._isDisposed) {
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
@@ -58,11 +57,11 @@ class VideoElementMonitor {
|
|
|
58
57
|
this._frozen.next(false);
|
|
59
58
|
}
|
|
60
59
|
if (this.disableOnWindowBlur) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
globalThis.window?.addEventListener('blur', this._updateFocus);
|
|
61
|
+
globalThis.document?.addEventListener('blur', this._updateFocus);
|
|
62
|
+
globalThis.window?.addEventListener('focus', this._updateFocus);
|
|
63
|
+
globalThis.document?.addEventListener('focus', this._updateFocus);
|
|
64
|
+
globalThis.document?.addEventListener('visibilitychange', this._updateFocus);
|
|
66
65
|
this.hasFocus = windowHasFocus();
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
@@ -71,18 +70,17 @@ class VideoElementMonitor {
|
|
|
71
70
|
}
|
|
72
71
|
get isDisposed() { return this._isDisposed; }
|
|
73
72
|
dispose() {
|
|
74
|
-
var _a, _b, _c, _d, _e;
|
|
75
73
|
if (this._isDisposed) {
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
76
|
this._isDisposed = true;
|
|
79
77
|
clearInterval(this.iv);
|
|
80
78
|
if (this.disableOnWindowBlur) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
globalThis.window?.removeEventListener('blur', this._updateFocus);
|
|
80
|
+
globalThis.document?.removeEventListener('blur', this._updateFocus);
|
|
81
|
+
globalThis.window?.removeEventListener('focus', this._updateFocus);
|
|
82
|
+
globalThis.document?.removeEventListener('focus', this._updateFocus);
|
|
83
|
+
globalThis.document?.removeEventListener('visibilitychange', this._updateFocus);
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
updateFocus() {
|
|
@@ -98,5 +96,5 @@ class VideoElementMonitor {
|
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
exports.VideoElementMonitor = VideoElementMonitor;
|
|
101
|
-
const windowHasFocus = () =>
|
|
99
|
+
const windowHasFocus = () => globalThis.document?.hasFocus() ?? true;
|
|
102
100
|
//# sourceMappingURL=VideoElementMonitor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VideoElementMonitor.js","sourceRoot":"","s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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;YACD,UAAU,CAAC,GAAE,EAAE,CAAA,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,IAAI,CAAC,aAAa,CAAC,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7F,CAAC,CAAA;QAEgB,iBAAY,GAAC,GAAE,EAAE;YAC9B,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,UAAU,CAAC,GAAE,EAAE,CAAA,IAAI,CAAC,WAAW,EAAE,EAAC,CAAC,CAAC,CAAC;QACzC,CAAC,CAAA;QAjFG,IAAI,CAAC,KAAK,GAAC,KAAK,CAAC;QACjB,IAAI,CAAC,SAAS,GAAE,KAAa,CAAC,yBAAyB,CAAA,CAAC,CAAA,IAAI,CAAA,CAAC,CAAA,KAAK,CAAC;QACnE,IAAI,CAAC,UAAU,GAAC,UAAU,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAC,aAAa,CAAC;QACjC,IAAI,CAAC,mBAAmB,GAAC,mBAAmB,CAAC;QAE7C,IAAG,cAAc,EAAC,CAAC;YACf,UAAU,CAAC,GAAE,EAAE,CAAA,IAAI,CAAC,IAAI,EAAE,EAAC,cAAc,CAAC,CAAA;QAC9C,CAAC;aAAI,CAAC;YACF,IAAI,CAAC,IAAI,EAAE,CAAC;QAChB,CAAC;IAEL,CAAC;IAEO,IAAI
|
|
1
|
+
{"version":3,"file":"VideoElementMonitor.js","sourceRoot":"","sources":["../../../../../packages/media-common/src/lib/VideoElementMonitor.ts"],"names":[],"mappings":";;;AACA,+BAAuC;AAWvC,MAAa,mBAAmB;IAI5B,IAAW,aAAa,KAAiC,OAAO,IAAI,CAAC,OAAO,CAAA,CAAA,CAAC;IAC7E,IAAW,MAAM,KAAG,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAA,CAAA,CAAC;IAkB9C,YAAmB,EACf,KAAK,EACL,UAAU,GAAC,IAAI,EACf,aAAa,GAAC,UAAU,GAA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C;YACzB,OAAO;QACX,CAAC;QAED,IAAI,CAAC,QAAQ,GAAC,QAAQ,CAAC;QACvB,IAAI,CAAC,aAAa,GAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAClC,CAAC;CACJ;AA9HD,kDA8HC;AAED,MAAM,cAAc,GAAC,GAAE,EAAE,CAAA,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAE,IAAI,CAAC"}
|
package/src/lib/blurhash.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.imageToBlurHashAsync = exports.blurHashToDataUri = exports.blurHashToCanvas = exports.defaultHashBlurHeight = exports.defaultHashBlurWidth = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const blurhash_1 = require("blurhash");
|
|
6
5
|
const media_lib_1 = require("./media-lib");
|
|
7
6
|
exports.defaultHashBlurWidth = 32;
|
|
@@ -26,19 +25,18 @@ const blurHashToDataUri = (hash, options) => {
|
|
|
26
25
|
if (!canvas) {
|
|
27
26
|
return undefined;
|
|
28
27
|
}
|
|
29
|
-
return canvas.toDataURL(options
|
|
28
|
+
return canvas.toDataURL(options?.imageType, options?.quality);
|
|
30
29
|
};
|
|
31
30
|
exports.blurHashToDataUri = blurHashToDataUri;
|
|
32
|
-
const imageToBlurHashAsync = (src, options) =>
|
|
33
|
-
var _a, _b, _c, _d;
|
|
31
|
+
const imageToBlurHashAsync = async (src, options) => {
|
|
34
32
|
try {
|
|
35
|
-
const imageData =
|
|
36
|
-
return (0, blurhash_1.encode)(imageData.data, imageData.width, imageData.height,
|
|
33
|
+
const imageData = await (0, media_lib_1.imageSourceToImageDataAsync)(src, options?.width ?? exports.defaultHashBlurWidth, options?.height ?? exports.defaultHashBlurHeight);
|
|
34
|
+
return (0, blurhash_1.encode)(imageData.data, imageData.width, imageData.height, options?.componentX ?? 4, options?.componentY ?? 4);
|
|
37
35
|
}
|
|
38
36
|
catch (ex) {
|
|
39
37
|
console.error('Unable to convert image source to blur hash', ex);
|
|
40
38
|
return undefined;
|
|
41
39
|
}
|
|
42
|
-
}
|
|
40
|
+
};
|
|
43
41
|
exports.imageToBlurHashAsync = imageToBlurHashAsync;
|
|
44
42
|
//# sourceMappingURL=blurhash.js.map
|
package/src/lib/blurhash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blurhash.js","sourceRoot":"","sources":["../../../../../packages/media-common/src/lib/blurhash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blurhash.js","sourceRoot":"","sources":["../../../../../packages/media-common/src/lib/blurhash.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAC1C,2CAA0D;AAE7C,QAAA,oBAAoB,GAAC,EAAE,CAAC;AACxB,QAAA,qBAAqB,GAAC,EAAE,CAAC;AAS/B,MAAM,gBAAgB,GAAC,CAAC,IAAW,EAAC,EACvC,KAAK,GAAC,4BAAoB,EAC1B,MAAM,GAAC,6BAAqB,EAC5B,KAAK,GAAC,CAAC,KACe,EAAE,EAA6B,EAAE;IACvD,MAAM,MAAM,GAAC,IAAA,iBAAM,EAAC,IAAI,EAAC,KAAK,EAAC,MAAM,EAAC,KAAK,CAAC,CAAC;IAE7C,MAAM,MAAM,GAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,GAAC,KAAK,CAAC;IACnB,MAAM,CAAC,MAAM,GAAC,MAAM,CAAC;IACrB,MAAM,GAAG,GAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClC,IAAG,CAAC,GAAG,EAAC,CAAC;QACL,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,SAAS,GAAC,GAAG,CAAC,eAAe,CAAC,KAAK,EAAC,MAAM,CAAC,CAAC;IAClD,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC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ToBlob = exports.getVideoAsync = exports.getVideoInfoAsync = exports.fetchBlobAsync = exports.imageSourceToImageDataAsync = exports.loadAudioAsync = exports.loadImageAsync = exports.getImageSizeAsync = exports.getContentTypeFileExt = exports.getImageDataStats = exports.getSnapshot = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const common_1 = require("@iyio/common");
|
|
6
5
|
const getCanvas = () => {
|
|
7
6
|
const canvasHost = document.createElement('div');
|
|
@@ -22,14 +21,13 @@ const getCanvas = () => {
|
|
|
22
21
|
};
|
|
23
22
|
};
|
|
24
23
|
const getSnapshot = ({ source, type = 'image/jpeg', width, height, viewBoxWidth, viewBoxHeight, flipHorizontal, flipVertical, includeStats, }) => {
|
|
25
|
-
var _a, _b;
|
|
26
24
|
let tw = width;
|
|
27
25
|
let th = height;
|
|
28
26
|
if (tw === undefined || th === undefined) {
|
|
29
27
|
const vid = source;
|
|
30
|
-
const stream = vid
|
|
28
|
+
const stream = vid?.srcObject;
|
|
31
29
|
if (stream) {
|
|
32
|
-
const trackSettings =
|
|
30
|
+
const trackSettings = stream.getVideoTracks()?.[0]?.getSettings();
|
|
33
31
|
if (trackSettings) {
|
|
34
32
|
if (tw === undefined) {
|
|
35
33
|
tw = trackSettings.width;
|
|
@@ -56,8 +54,8 @@ const getSnapshot = ({ source, type = 'image/jpeg', width, height, viewBoxWidth,
|
|
|
56
54
|
return null;
|
|
57
55
|
}
|
|
58
56
|
const tr = tw / th;
|
|
59
|
-
const vw = (viewBoxWidth
|
|
60
|
-
const vh = (viewBoxHeight
|
|
57
|
+
const vw = (viewBoxWidth ?? tw) || 1;
|
|
58
|
+
const vh = (viewBoxHeight ?? th) || 1;
|
|
61
59
|
const vr = vw / vh;
|
|
62
60
|
let cw = 0; // capture width
|
|
63
61
|
let ch = 0; // capture height;
|
|
@@ -123,22 +121,21 @@ const getImageDataStats = (data, { trueAverage } = {}) => {
|
|
|
123
121
|
};
|
|
124
122
|
exports.getImageDataStats = getImageDataStats;
|
|
125
123
|
const getContentTypeFileExt = (contentType) => {
|
|
126
|
-
var _a;
|
|
127
124
|
switch (contentType.toLowerCase()) {
|
|
128
125
|
case 'image/jpeg':
|
|
129
126
|
return 'jpg';
|
|
130
127
|
default:
|
|
131
|
-
return
|
|
128
|
+
return contentType.split('/')[1] ?? 'jpg';
|
|
132
129
|
}
|
|
133
130
|
};
|
|
134
131
|
exports.getContentTypeFileExt = getContentTypeFileExt;
|
|
135
|
-
const getImageSizeAsync = (src) =>
|
|
136
|
-
const img =
|
|
132
|
+
const getImageSizeAsync = async (src) => {
|
|
133
|
+
const img = await (0, exports.loadImageAsync)(src);
|
|
137
134
|
return {
|
|
138
135
|
width: img.width,
|
|
139
136
|
height: img.height,
|
|
140
137
|
};
|
|
141
|
-
}
|
|
138
|
+
};
|
|
142
139
|
exports.getImageSizeAsync = getImageSizeAsync;
|
|
143
140
|
const loadImageAsync = (src) => {
|
|
144
141
|
let revokeUrl = false;
|
|
@@ -190,31 +187,30 @@ const loadAudioAsync = (src) => {
|
|
|
190
187
|
});
|
|
191
188
|
};
|
|
192
189
|
exports.loadAudioAsync = loadAudioAsync;
|
|
193
|
-
const imageSourceToImageDataAsync = (src, width, height) =>
|
|
194
|
-
const img =
|
|
190
|
+
const imageSourceToImageDataAsync = async (src, width, height) => {
|
|
191
|
+
const img = await (0, exports.loadImageAsync)(src);
|
|
195
192
|
const canvas = document.createElement('canvas');
|
|
196
|
-
canvas.width = width
|
|
197
|
-
canvas.height = height
|
|
193
|
+
canvas.width = width ?? img.width;
|
|
194
|
+
canvas.height = height ?? img.height;
|
|
198
195
|
const context = canvas.getContext('2d');
|
|
199
196
|
if (!context) {
|
|
200
197
|
throw new Error('Unable to create canvas 2d context');
|
|
201
198
|
}
|
|
202
|
-
context.drawImage(img, 0, 0, width
|
|
203
|
-
return context.getImageData(0, 0, width
|
|
204
|
-
}
|
|
199
|
+
context.drawImage(img, 0, 0, width ?? img.width, height ?? img.height);
|
|
200
|
+
return context.getImageData(0, 0, width ?? img.width, height ?? img.height);
|
|
201
|
+
};
|
|
205
202
|
exports.imageSourceToImageDataAsync = imageSourceToImageDataAsync;
|
|
206
|
-
const fetchBlobAsync =
|
|
203
|
+
const fetchBlobAsync = async (url, bustCache = false) => {
|
|
207
204
|
if (bustCache) {
|
|
208
205
|
url = (0, common_1.addQueryToPath)(url, { _: (0, common_1.uuid)() });
|
|
209
206
|
}
|
|
210
|
-
const r =
|
|
211
|
-
return
|
|
212
|
-
}
|
|
207
|
+
const r = await fetch(url);
|
|
208
|
+
return await r.blob();
|
|
209
|
+
};
|
|
213
210
|
exports.fetchBlobAsync = fetchBlobAsync;
|
|
214
211
|
const getVideoInfoAsync = (src) => {
|
|
215
212
|
return new Promise((resolve, reject) => {
|
|
216
|
-
|
|
217
|
-
const video = (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.createElement('video');
|
|
213
|
+
const video = globalThis.window?.document?.createElement('video');
|
|
218
214
|
if (!video) {
|
|
219
215
|
resolve({ width: 0, height: 0, durationSeconds: 0 });
|
|
220
216
|
return;
|
|
@@ -229,8 +225,7 @@ const getVideoInfoAsync = (src) => {
|
|
|
229
225
|
video.src = '';
|
|
230
226
|
};
|
|
231
227
|
const onMeta = () => {
|
|
232
|
-
|
|
233
|
-
resolve({ width: video.videoWidth, height: video.videoHeight, durationSeconds: (_a = (0, common_1.safeParseNumberOrUndefined)(video.duration)) !== null && _a !== void 0 ? _a : 0 });
|
|
228
|
+
resolve({ width: video.videoWidth, height: video.videoHeight, durationSeconds: (0, common_1.safeParseNumberOrUndefined)(video.duration) ?? 0 });
|
|
234
229
|
cleanUp();
|
|
235
230
|
};
|
|
236
231
|
const onError = (e) => {
|
|
@@ -239,14 +234,13 @@ const getVideoInfoAsync = (src) => {
|
|
|
239
234
|
};
|
|
240
235
|
video.addEventListener('loadedmetadata', onMeta);
|
|
241
236
|
video.addEventListener('error', onError);
|
|
242
|
-
video.src = blobUrl
|
|
237
|
+
video.src = blobUrl ?? src;
|
|
243
238
|
});
|
|
244
239
|
};
|
|
245
240
|
exports.getVideoInfoAsync = getVideoInfoAsync;
|
|
246
241
|
const getVideoAsync = (src, forPreview) => {
|
|
247
242
|
return new Promise((resolve, reject) => {
|
|
248
|
-
|
|
249
|
-
const video = (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.createElement('video');
|
|
243
|
+
const video = globalThis.window?.document?.createElement('video');
|
|
250
244
|
if (!video) {
|
|
251
245
|
reject();
|
|
252
246
|
return;
|
|
@@ -267,7 +261,7 @@ const getVideoAsync = (src, forPreview) => {
|
|
|
267
261
|
else {
|
|
268
262
|
video.addEventListener('loadedmetadata', onMeta);
|
|
269
263
|
}
|
|
270
|
-
video.src = blobUrl
|
|
264
|
+
video.src = blobUrl ?? src;
|
|
271
265
|
});
|
|
272
266
|
};
|
|
273
267
|
exports.getVideoAsync = getVideoAsync;
|