@vonage/media-processor 3.0.0-alpha.2 → 3.0.1-alpha.0
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/dist/media-processor.es.js +312 -306
- package/dist/media-processor.min.js +2 -2
- package/dist/media-processor.static.js +312 -306
- package/dist/media-processor.umd.js +2 -2
- package/dist/types/lib/main.d.ts +0 -2
- package/dist/types/lib/src/utils/getMediaStreamTrackGenerator.d.ts +7 -0
- package/dist/types/lib/src/utils/getMediaStreamTrackProcessor.d.ts +5 -0
- package/package.json +1 -1
- package/dist/types/lib/src/utils/MediaStreamTrackGenerator.polyfill.d.ts +0 -0
- package/dist/types/lib/src/utils/MediaStreamTrackProcessor.polyfill.d.ts +0 -0
|
@@ -1,148 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
self.MediaStreamTrackProcessor || (self.MediaStreamTrackProcessor = (T = class {
|
|
3
|
-
constructor(e) {
|
|
4
|
-
const t = e.track ?? e;
|
|
5
|
-
t.kind == "video" ? this.readable = new ReadableStream({
|
|
6
|
-
async start(s) {
|
|
7
|
-
t.addEventListener(
|
|
8
|
-
"ended",
|
|
9
|
-
() => s.close(),
|
|
10
|
-
{ once: !0 }
|
|
11
|
-
), this.video = document.createElement("video"), this.video.srcObject = new MediaStream([t]), await Promise.all([
|
|
12
|
-
this.video.play(),
|
|
13
|
-
new Promise(
|
|
14
|
-
(i) => this.video.onloadedmetadata = i
|
|
15
|
-
)
|
|
16
|
-
]), this.track = t, this.canvas = new OffscreenCanvas(
|
|
17
|
-
this.video.videoWidth,
|
|
18
|
-
this.video.videoHeight
|
|
19
|
-
), this.ctx = this.canvas.getContext("2d", {
|
|
20
|
-
desynchronized: !0
|
|
21
|
-
}), this.t1 = performance.now();
|
|
22
|
-
},
|
|
23
|
-
async pull(s) {
|
|
24
|
-
if (t.readyState == "ended")
|
|
25
|
-
return s.close();
|
|
26
|
-
const i = t.getSettings().frameRate || 30;
|
|
27
|
-
for (; performance.now() - this.t1 < 1e3 / i; )
|
|
28
|
-
if (await new Promise((n) => requestAnimationFrame(n)), t.readyState == "ended")
|
|
29
|
-
return s.close();
|
|
30
|
-
this.canvas.width = this.video.videoWidth, this.canvas.height = this.video.videoHeight, this.t1 = performance.now(), this.ctx.drawImage(this.video, 0, 0), s.enqueue(
|
|
31
|
-
new VideoFrame(this.canvas, {
|
|
32
|
-
timestamp: this.t1
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
}) : t.kind == "audio" && (this.readable = new ReadableStream({
|
|
37
|
-
async start(s) {
|
|
38
|
-
t.addEventListener(
|
|
39
|
-
"ended",
|
|
40
|
-
() => s.close(),
|
|
41
|
-
{ once: !0 }
|
|
42
|
-
), this.ac = new AudioContext(), this.arrays = [];
|
|
43
|
-
function i() {
|
|
44
|
-
registerProcessor(
|
|
45
|
-
"mstp-shim",
|
|
46
|
-
class extends AudioWorkletProcessor {
|
|
47
|
-
process(o) {
|
|
48
|
-
return this.port.postMessage(o), !0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
await this.ac.audioWorklet.addModule(
|
|
54
|
-
`data:text/javascript,(${i.toString()})()`
|
|
55
|
-
), this.node = new AudioWorkletNode(this.ac, "mstp-shim"), this.ac.createMediaStreamSource(new MediaStream([t])).connect(this.node), this.node.port.addEventListener(
|
|
56
|
-
"message",
|
|
57
|
-
({ data: n }) => n[0][0] && this.arrays.push(n)
|
|
58
|
-
);
|
|
59
|
-
},
|
|
60
|
-
async pull(s) {
|
|
61
|
-
if (t.readyState == "ended")
|
|
62
|
-
return s.close();
|
|
63
|
-
for (; !this.arrays.length; )
|
|
64
|
-
if (await new Promise(
|
|
65
|
-
(o) => this.node.port.onmessage = o
|
|
66
|
-
), t.readyState == "ended")
|
|
67
|
-
return s.close();
|
|
68
|
-
const [i] = this.arrays.shift(), n = new Float32Array(
|
|
69
|
-
i.reduce((o, a) => o + a.length, 0)
|
|
70
|
-
);
|
|
71
|
-
i.reduce(
|
|
72
|
-
(o, a) => (n.set(a, o), o + a.length),
|
|
73
|
-
0
|
|
74
|
-
), s.enqueue(
|
|
75
|
-
new AudioData({
|
|
76
|
-
format: "f32-planar",
|
|
77
|
-
sampleRate: this.ac.sampleRate,
|
|
78
|
-
numberOfFrames: i[0].length,
|
|
79
|
-
numberOfChannels: i.length,
|
|
80
|
-
timestamp: this.ac.currentTime * 1e6 | 0,
|
|
81
|
-
data: n,
|
|
82
|
-
transfer: [n.buffer]
|
|
83
|
-
})
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
}, T.__POLYFILLED = !0, T));
|
|
89
|
-
var S;
|
|
90
|
-
self.MediaStreamTrackGenerator || (self.MediaStreamTrackGenerator = (S = class {
|
|
91
|
-
constructor({ kind: e }) {
|
|
92
|
-
if (e == "video") {
|
|
93
|
-
const t = document.createElement("canvas"), s = t.getContext("2d", {
|
|
94
|
-
desynchronized: !0
|
|
95
|
-
}), i = t.captureStream().getVideoTracks()[0];
|
|
96
|
-
return i.writable = new WritableStream({
|
|
97
|
-
write(n) {
|
|
98
|
-
t.width = n.displayWidth, t.height = n.displayHeight, s.drawImage(n, 0, 0, t.width, t.height), n.close();
|
|
99
|
-
}
|
|
100
|
-
}), i;
|
|
101
|
-
} else if (e == "audio") {
|
|
102
|
-
const t = new AudioContext(), s = t.createMediaStreamDestination(), [i] = s.stream.getAudioTracks();
|
|
103
|
-
return i.writable = new WritableStream({
|
|
104
|
-
async start(n) {
|
|
105
|
-
this.arrays = [];
|
|
106
|
-
function o() {
|
|
107
|
-
registerProcessor(
|
|
108
|
-
"mstg-shim",
|
|
109
|
-
class extends AudioWorkletProcessor {
|
|
110
|
-
constructor() {
|
|
111
|
-
super(), this.arrays = [], this.arrayOffset = 0, this.port.onmessage = ({ data: l }) => this.arrays.push(l), this.emptyArray = new Float32Array(0);
|
|
112
|
-
}
|
|
113
|
-
process(l, [[w]]) {
|
|
114
|
-
for (let F = 0; F < w.length; F++)
|
|
115
|
-
(!this.array || this.arrayOffset >= this.array.length) && (this.array = this.arrays.shift() || this.emptyArray, this.arrayOffset = 0), w[F] = this.array[this.arrayOffset++] || 0;
|
|
116
|
-
return !0;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
return await t.audioWorklet.addModule(
|
|
122
|
-
`data:text/javascript,(${o.toString()})()`
|
|
123
|
-
), this.node = new AudioWorkletNode(t, "mstg-shim"), this.node.connect(s), i;
|
|
124
|
-
},
|
|
125
|
-
write(n) {
|
|
126
|
-
const o = new Float32Array(
|
|
127
|
-
n.numberOfFrames * n.numberOfChannels
|
|
128
|
-
);
|
|
129
|
-
n.copyTo(o, { planeIndex: 0 }), this.node.port.postMessage(o, [o.buffer]), n.close();
|
|
130
|
-
}
|
|
131
|
-
}), i;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}, S.__POLYFILLED = !0, S));
|
|
135
|
-
async function $e() {
|
|
1
|
+
async function Ue() {
|
|
136
2
|
return new Promise(async (r, e) => {
|
|
137
|
-
await
|
|
3
|
+
await Y() || B() ? r() : e(
|
|
138
4
|
"Your browser does not support the MediaStreamTrack API for Insertable Streams of Media."
|
|
139
5
|
);
|
|
140
6
|
});
|
|
141
7
|
}
|
|
142
|
-
function
|
|
143
|
-
return self.MediaStreamTrackProcessor !== void 0 && self.MediaStreamTrackGenerator !== void 0
|
|
8
|
+
function B() {
|
|
9
|
+
return self.MediaStreamTrackProcessor !== void 0 && self.MediaStreamTrackGenerator !== void 0 || Z();
|
|
144
10
|
}
|
|
145
|
-
function
|
|
11
|
+
function Z() {
|
|
146
12
|
return [
|
|
147
13
|
self.ReadableStream,
|
|
148
14
|
self.WritableStream,
|
|
@@ -153,7 +19,7 @@ function N() {
|
|
|
153
19
|
self.AudioWorkletNode
|
|
154
20
|
].filter((r) => r === void 0).length === 0;
|
|
155
21
|
}
|
|
156
|
-
function
|
|
22
|
+
function Y() {
|
|
157
23
|
return new Promise((r) => {
|
|
158
24
|
function e() {
|
|
159
25
|
self.postMessage(
|
|
@@ -164,14 +30,14 @@ function X() {
|
|
|
164
30
|
t.onmessage = ({ data: s }) => r(s);
|
|
165
31
|
});
|
|
166
32
|
}
|
|
167
|
-
const u = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(),
|
|
168
|
-
let
|
|
169
|
-
const
|
|
170
|
-
function
|
|
171
|
-
if (!
|
|
33
|
+
const u = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ Symbol("anyProducer"), D = Promise.resolve(), M = /* @__PURE__ */ Symbol("listenerAdded"), R = /* @__PURE__ */ Symbol("listenerRemoved");
|
|
34
|
+
let I = !1, F = !1;
|
|
35
|
+
const x = (r) => typeof r == "string" || typeof r == "symbol" || typeof r == "number";
|
|
36
|
+
function w(r) {
|
|
37
|
+
if (!x(r))
|
|
172
38
|
throw new TypeError("`eventName` must be a string, symbol, or number");
|
|
173
39
|
}
|
|
174
|
-
function
|
|
40
|
+
function k(r) {
|
|
175
41
|
if (typeof r != "function")
|
|
176
42
|
throw new TypeError("listener must be a function");
|
|
177
43
|
}
|
|
@@ -180,23 +46,23 @@ function _(r, e) {
|
|
|
180
46
|
if (t.has(e))
|
|
181
47
|
return t.get(e);
|
|
182
48
|
}
|
|
183
|
-
function
|
|
184
|
-
const t =
|
|
49
|
+
function T(r, e) {
|
|
50
|
+
const t = x(e) ? e : A, s = d.get(r);
|
|
185
51
|
if (s.has(t))
|
|
186
52
|
return s.get(t);
|
|
187
53
|
}
|
|
188
|
-
function
|
|
54
|
+
function K(r, e, t) {
|
|
189
55
|
const s = d.get(r);
|
|
190
56
|
if (s.has(e))
|
|
191
57
|
for (const i of s.get(e))
|
|
192
58
|
i.enqueue(t);
|
|
193
|
-
if (s.has(
|
|
59
|
+
if (s.has(A)) {
|
|
194
60
|
const i = Promise.all([e, t]);
|
|
195
|
-
for (const n of s.get(
|
|
61
|
+
for (const n of s.get(A))
|
|
196
62
|
n.enqueue(i);
|
|
197
63
|
}
|
|
198
64
|
}
|
|
199
|
-
function
|
|
65
|
+
function V(r, e) {
|
|
200
66
|
e = Array.isArray(e) ? e : [e];
|
|
201
67
|
let t = !1, s = () => {
|
|
202
68
|
}, i = [];
|
|
@@ -209,7 +75,7 @@ function H(r, e) {
|
|
|
209
75
|
}
|
|
210
76
|
};
|
|
211
77
|
for (const o of e) {
|
|
212
|
-
let a =
|
|
78
|
+
let a = T(r, o);
|
|
213
79
|
a || (a = /* @__PURE__ */ new Set(), d.get(r).set(o, a)), a.add(n);
|
|
214
80
|
}
|
|
215
81
|
return {
|
|
@@ -224,7 +90,7 @@ function H(r, e) {
|
|
|
224
90
|
async return(o) {
|
|
225
91
|
i = void 0;
|
|
226
92
|
for (const a of e) {
|
|
227
|
-
const l =
|
|
93
|
+
const l = T(r, a);
|
|
228
94
|
l && (l.delete(n), l.size === 0 && d.get(r).delete(a));
|
|
229
95
|
}
|
|
230
96
|
return s(), arguments.length > 0 ? { done: !0, value: await o } : { done: !0 };
|
|
@@ -234,28 +100,28 @@ function H(r, e) {
|
|
|
234
100
|
}
|
|
235
101
|
};
|
|
236
102
|
}
|
|
237
|
-
function
|
|
103
|
+
function j(r) {
|
|
238
104
|
if (r === void 0)
|
|
239
|
-
return
|
|
105
|
+
return H;
|
|
240
106
|
if (!Array.isArray(r))
|
|
241
107
|
throw new TypeError("`methodNames` must be an array of strings");
|
|
242
108
|
for (const e of r)
|
|
243
|
-
if (!
|
|
109
|
+
if (!H.includes(e))
|
|
244
110
|
throw typeof e != "string" ? new TypeError("`methodNames` element must be a string") : new Error(`${e} is not Emittery method`);
|
|
245
111
|
return r;
|
|
246
112
|
}
|
|
247
|
-
const b = (r) => r ===
|
|
248
|
-
function
|
|
113
|
+
const b = (r) => r === M || r === R;
|
|
114
|
+
function E(r, e, t) {
|
|
249
115
|
if (b(e))
|
|
250
116
|
try {
|
|
251
|
-
|
|
117
|
+
I = !0, r.emit(e, t);
|
|
252
118
|
} finally {
|
|
253
|
-
|
|
119
|
+
I = !1;
|
|
254
120
|
}
|
|
255
121
|
}
|
|
256
122
|
class h {
|
|
257
123
|
static mixin(e, t) {
|
|
258
|
-
return t =
|
|
124
|
+
return t = j(t), (s) => {
|
|
259
125
|
if (typeof s != "function")
|
|
260
126
|
throw new TypeError("`target` must be function");
|
|
261
127
|
for (const o of t)
|
|
@@ -284,15 +150,15 @@ class h {
|
|
|
284
150
|
}
|
|
285
151
|
static get isDebugEnabled() {
|
|
286
152
|
if (typeof globalThis.process?.env != "object")
|
|
287
|
-
return
|
|
153
|
+
return F;
|
|
288
154
|
const { env: e } = globalThis.process ?? { env: {} };
|
|
289
|
-
return e.DEBUG === "emittery" || e.DEBUG === "*" ||
|
|
155
|
+
return e.DEBUG === "emittery" || e.DEBUG === "*" || F;
|
|
290
156
|
}
|
|
291
157
|
static set isDebugEnabled(e) {
|
|
292
|
-
|
|
158
|
+
F = e;
|
|
293
159
|
}
|
|
294
160
|
constructor(e = {}) {
|
|
295
|
-
u.set(this, /* @__PURE__ */ new Set()), m.set(this, /* @__PURE__ */ new Map()), d.set(this, /* @__PURE__ */ new Map()), d.get(this).set(
|
|
161
|
+
u.set(this, /* @__PURE__ */ new Set()), m.set(this, /* @__PURE__ */ new Map()), d.set(this, /* @__PURE__ */ new Map()), d.get(this).set(A, /* @__PURE__ */ new Set()), this.debug = e.debug ?? {}, this.debug.enabled === void 0 && (this.debug.enabled = !1), this.debug.logger || (this.debug.logger = (t, s, i, n) => {
|
|
296
162
|
try {
|
|
297
163
|
n = JSON.stringify(n);
|
|
298
164
|
} catch {
|
|
@@ -308,11 +174,11 @@ class h {
|
|
|
308
174
|
(h.isDebugEnabled || this.debug.enabled) && this.debug.logger(e, this.debug.name, t, s);
|
|
309
175
|
}
|
|
310
176
|
on(e, t, { signal: s } = {}) {
|
|
311
|
-
|
|
177
|
+
k(t), e = Array.isArray(e) ? e : [e];
|
|
312
178
|
for (const n of e) {
|
|
313
|
-
|
|
179
|
+
w(n);
|
|
314
180
|
let o = _(this, n);
|
|
315
|
-
o || (o = /* @__PURE__ */ new Set(), m.get(this).set(n, o)), o.add(t), this.logIfDebugEnabled("subscribe", n, void 0), b(n) ||
|
|
181
|
+
o || (o = /* @__PURE__ */ new Set(), m.get(this).set(n, o)), o.add(t), this.logIfDebugEnabled("subscribe", n, void 0), b(n) || E(this, M, { eventName: n, listener: t });
|
|
316
182
|
}
|
|
317
183
|
const i = () => {
|
|
318
184
|
this.off(e, t), s?.removeEventListener("abort", i);
|
|
@@ -320,11 +186,11 @@ class h {
|
|
|
320
186
|
return s?.addEventListener("abort", i, { once: !0 }), s?.aborted && i(), i;
|
|
321
187
|
}
|
|
322
188
|
off(e, t) {
|
|
323
|
-
|
|
189
|
+
k(t), e = Array.isArray(e) ? e : [e];
|
|
324
190
|
for (const s of e) {
|
|
325
|
-
|
|
191
|
+
w(s);
|
|
326
192
|
const i = _(this, s);
|
|
327
|
-
i && (i.delete(t), i.size === 0 && m.get(this).delete(s)), this.logIfDebugEnabled("unsubscribe", s, void 0), b(s) ||
|
|
193
|
+
i && (i.delete(t), i.size === 0 && m.get(this).delete(s)), this.logIfDebugEnabled("unsubscribe", s, void 0), b(s) || E(this, R, { eventName: s, listener: t });
|
|
328
194
|
}
|
|
329
195
|
}
|
|
330
196
|
once(e, t) {
|
|
@@ -341,15 +207,15 @@ class h {
|
|
|
341
207
|
events(e) {
|
|
342
208
|
e = Array.isArray(e) ? e : [e];
|
|
343
209
|
for (const t of e)
|
|
344
|
-
|
|
345
|
-
return
|
|
210
|
+
w(t);
|
|
211
|
+
return V(this, e);
|
|
346
212
|
}
|
|
347
213
|
async emit(e, t) {
|
|
348
|
-
if (
|
|
214
|
+
if (w(e), b(e) && !I)
|
|
349
215
|
throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
|
|
350
|
-
this.logIfDebugEnabled("emit", e, t),
|
|
216
|
+
this.logIfDebugEnabled("emit", e, t), K(this, e, t);
|
|
351
217
|
const s = _(this, e) ?? /* @__PURE__ */ new Set(), i = u.get(this), n = [...s], o = b(e) ? [] : [...i];
|
|
352
|
-
await
|
|
218
|
+
await D, await Promise.all([
|
|
353
219
|
...n.map(async (a) => {
|
|
354
220
|
if (s.has(a))
|
|
355
221
|
return a(t);
|
|
@@ -361,36 +227,36 @@ class h {
|
|
|
361
227
|
]);
|
|
362
228
|
}
|
|
363
229
|
async emitSerial(e, t) {
|
|
364
|
-
if (
|
|
230
|
+
if (w(e), b(e) && !I)
|
|
365
231
|
throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");
|
|
366
232
|
this.logIfDebugEnabled("emitSerial", e, t);
|
|
367
233
|
const s = _(this, e) ?? /* @__PURE__ */ new Set(), i = u.get(this), n = [...s], o = [...i];
|
|
368
|
-
await
|
|
234
|
+
await D;
|
|
369
235
|
for (const a of n)
|
|
370
236
|
s.has(a) && await a(t);
|
|
371
237
|
for (const a of o)
|
|
372
238
|
i.has(a) && await a(e, t);
|
|
373
239
|
}
|
|
374
240
|
onAny(e, { signal: t } = {}) {
|
|
375
|
-
|
|
241
|
+
k(e), this.logIfDebugEnabled("subscribeAny", void 0, void 0), u.get(this).add(e), E(this, M, { listener: e });
|
|
376
242
|
const s = () => {
|
|
377
243
|
this.offAny(e), t?.removeEventListener("abort", s);
|
|
378
244
|
};
|
|
379
245
|
return t?.addEventListener("abort", s, { once: !0 }), t?.aborted && s(), s;
|
|
380
246
|
}
|
|
381
247
|
anyEvent() {
|
|
382
|
-
return
|
|
248
|
+
return V(this);
|
|
383
249
|
}
|
|
384
250
|
offAny(e) {
|
|
385
|
-
|
|
251
|
+
k(e), this.logIfDebugEnabled("unsubscribeAny", void 0, void 0), E(this, R, { listener: e }), u.get(this).delete(e);
|
|
386
252
|
}
|
|
387
253
|
clearListeners(e) {
|
|
388
254
|
e = Array.isArray(e) ? e : [e];
|
|
389
255
|
for (const t of e)
|
|
390
|
-
if (this.logIfDebugEnabled("clear", t, void 0),
|
|
256
|
+
if (this.logIfDebugEnabled("clear", t, void 0), x(t)) {
|
|
391
257
|
const s = _(this, t);
|
|
392
258
|
s && s.clear();
|
|
393
|
-
const i =
|
|
259
|
+
const i = T(this, t);
|
|
394
260
|
if (i) {
|
|
395
261
|
for (const n of i)
|
|
396
262
|
n.finish();
|
|
@@ -411,11 +277,11 @@ class h {
|
|
|
411
277
|
e = Array.isArray(e) ? e : [e];
|
|
412
278
|
let t = 0;
|
|
413
279
|
for (const s of e) {
|
|
414
|
-
if (
|
|
415
|
-
t += u.get(this).size + (_(this, s)?.size ?? 0) + (
|
|
280
|
+
if (x(s)) {
|
|
281
|
+
t += u.get(this).size + (_(this, s)?.size ?? 0) + (T(this, s)?.size ?? 0) + (T(this)?.size ?? 0);
|
|
416
282
|
continue;
|
|
417
283
|
}
|
|
418
|
-
s !== void 0 &&
|
|
284
|
+
s !== void 0 && w(s), t += u.get(this).size;
|
|
419
285
|
for (const i of m.get(this).values())
|
|
420
286
|
t += i.size;
|
|
421
287
|
for (const i of d.get(this).values())
|
|
@@ -426,7 +292,7 @@ class h {
|
|
|
426
292
|
bindMethods(e, t) {
|
|
427
293
|
if (typeof e != "object" || e === null)
|
|
428
294
|
throw new TypeError("`target` must be an object");
|
|
429
|
-
t =
|
|
295
|
+
t = j(t);
|
|
430
296
|
for (const s of t) {
|
|
431
297
|
if (e[s] !== void 0)
|
|
432
298
|
throw new Error(`The property \`${s}\` already exists on \`target\``);
|
|
@@ -437,60 +303,60 @@ class h {
|
|
|
437
303
|
}
|
|
438
304
|
}
|
|
439
305
|
}
|
|
440
|
-
const
|
|
306
|
+
const H = Object.getOwnPropertyNames(h.prototype).filter((r) => r !== "constructor");
|
|
441
307
|
Object.defineProperty(h, "listenerAdded", {
|
|
442
|
-
value:
|
|
308
|
+
value: M,
|
|
443
309
|
writable: !1,
|
|
444
310
|
enumerable: !0,
|
|
445
311
|
configurable: !1
|
|
446
312
|
});
|
|
447
313
|
Object.defineProperty(h, "listenerRemoved", {
|
|
448
|
-
value:
|
|
314
|
+
value: R,
|
|
449
315
|
writable: !1,
|
|
450
316
|
enumerable: !0,
|
|
451
317
|
configurable: !1
|
|
452
318
|
});
|
|
453
|
-
var
|
|
454
|
-
const
|
|
455
|
-
let
|
|
456
|
-
const
|
|
457
|
-
function
|
|
458
|
-
if (!
|
|
319
|
+
var N = Object.defineProperty, ee = (r, e, t) => e in r ? N(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, te = (r, e, t) => (ee(r, e + "", t), t), re = /* @__PURE__ */ ((r) => (r.automation = "automation", r.test = "test", r.vbc = "vbc", r.video = "video", r.voice = "voice", r))(re || {});
|
|
320
|
+
const se = "hlg.tokbox.com/prod/logging/vcp_webrtc", ie = "https://", ne = 1e4;
|
|
321
|
+
let v;
|
|
322
|
+
const oe = new Uint8Array(16);
|
|
323
|
+
function ae() {
|
|
324
|
+
if (!v && (v = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !v))
|
|
459
325
|
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
460
|
-
return
|
|
326
|
+
return v(oe);
|
|
461
327
|
}
|
|
462
328
|
const c = [];
|
|
463
329
|
for (let r = 0; r < 256; ++r)
|
|
464
330
|
c.push((r + 256).toString(16).slice(1));
|
|
465
|
-
function
|
|
331
|
+
function ce(r, e = 0) {
|
|
466
332
|
return (c[r[e + 0]] + c[r[e + 1]] + c[r[e + 2]] + c[r[e + 3]] + "-" + c[r[e + 4]] + c[r[e + 5]] + "-" + c[r[e + 6]] + c[r[e + 7]] + "-" + c[r[e + 8]] + c[r[e + 9]] + "-" + c[r[e + 10]] + c[r[e + 11]] + c[r[e + 12]] + c[r[e + 13]] + c[r[e + 14]] + c[r[e + 15]]).toLowerCase();
|
|
467
333
|
}
|
|
468
|
-
const
|
|
469
|
-
randomUUID:
|
|
334
|
+
const le = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Q = {
|
|
335
|
+
randomUUID: le
|
|
470
336
|
};
|
|
471
|
-
function
|
|
472
|
-
if (
|
|
473
|
-
return
|
|
337
|
+
function de(r, e, t) {
|
|
338
|
+
if (Q.randomUUID && !r)
|
|
339
|
+
return Q.randomUUID();
|
|
474
340
|
r = r || {};
|
|
475
|
-
const s = r.random || (r.rng ||
|
|
476
|
-
return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128,
|
|
341
|
+
const s = r.random || (r.rng || ae)();
|
|
342
|
+
return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, ce(s);
|
|
477
343
|
}
|
|
478
|
-
function
|
|
344
|
+
function U(r, e) {
|
|
479
345
|
globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {});
|
|
480
346
|
let t = globalThis.vonage.workerizer;
|
|
481
347
|
return t[r] || (t[r] = e), t[r];
|
|
482
348
|
}
|
|
483
|
-
const p =
|
|
349
|
+
const p = U(
|
|
484
350
|
"globals",
|
|
485
351
|
{}
|
|
486
352
|
);
|
|
487
353
|
var g = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERMINATE = "TERMINATE", r.GLOBALS_SYNC = "GLOBALS_SYNC", r))(g || {});
|
|
488
|
-
function
|
|
354
|
+
function J(r) {
|
|
489
355
|
return [ImageBitmap, ReadableStream, WritableStream].some((t) => r instanceof t);
|
|
490
356
|
}
|
|
491
|
-
let
|
|
492
|
-
function
|
|
493
|
-
const n =
|
|
357
|
+
let fe = 0;
|
|
358
|
+
function he(r, e, t, s, i) {
|
|
359
|
+
const n = fe++;
|
|
494
360
|
return r.postMessage(
|
|
495
361
|
{
|
|
496
362
|
id: n,
|
|
@@ -498,12 +364,12 @@ function pe(r, e, t, s, i) {
|
|
|
498
364
|
functionName: t,
|
|
499
365
|
args: s
|
|
500
366
|
},
|
|
501
|
-
s.filter((a) =>
|
|
367
|
+
s.filter((a) => J(a))
|
|
502
368
|
), new Promise((a) => {
|
|
503
369
|
i?.set(n, a);
|
|
504
370
|
});
|
|
505
371
|
}
|
|
506
|
-
function
|
|
372
|
+
function S(r, e) {
|
|
507
373
|
const { id: t, type: s } = r, i = Array.isArray(e) ? e : [e];
|
|
508
374
|
postMessage(
|
|
509
375
|
{
|
|
@@ -511,22 +377,22 @@ function k(r, e) {
|
|
|
511
377
|
type: s,
|
|
512
378
|
result: e
|
|
513
379
|
},
|
|
514
|
-
i.filter((n) =>
|
|
380
|
+
i.filter((n) => J(n))
|
|
515
381
|
);
|
|
516
382
|
}
|
|
517
|
-
const
|
|
518
|
-
function
|
|
383
|
+
const q = U("workerized", {});
|
|
384
|
+
function X() {
|
|
519
385
|
return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
|
|
520
386
|
}
|
|
521
|
-
async function
|
|
522
|
-
if (
|
|
523
|
-
|
|
387
|
+
async function ue() {
|
|
388
|
+
if (X())
|
|
389
|
+
S({ type: g.GLOBALS_SYNC }, p);
|
|
524
390
|
else {
|
|
525
391
|
const r = [];
|
|
526
|
-
for (const e in
|
|
527
|
-
const { worker: t, resolvers: s } =
|
|
392
|
+
for (const e in q) {
|
|
393
|
+
const { worker: t, resolvers: s } = q[e].workerContext;
|
|
528
394
|
t && r.push(
|
|
529
|
-
|
|
395
|
+
he(
|
|
530
396
|
t,
|
|
531
397
|
g.GLOBALS_SYNC,
|
|
532
398
|
"",
|
|
@@ -538,16 +404,16 @@ async function me() {
|
|
|
538
404
|
await Promise.all(r);
|
|
539
405
|
}
|
|
540
406
|
}
|
|
541
|
-
function
|
|
407
|
+
function C(r, e) {
|
|
542
408
|
if (Array.isArray(e))
|
|
543
409
|
e.splice(0, e.length);
|
|
544
410
|
else if (typeof e == "object")
|
|
545
411
|
for (const t in e)
|
|
546
412
|
delete e[t];
|
|
547
413
|
for (const t in r)
|
|
548
|
-
Array.isArray(r[t]) ? (e[t] = [],
|
|
414
|
+
Array.isArray(r[t]) ? (e[t] = [], C(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, C(r[t], e[t])) : e[t] = r[t];
|
|
549
415
|
}
|
|
550
|
-
async function
|
|
416
|
+
async function pe(r, e) {
|
|
551
417
|
const { functionName: t, args: s } = r;
|
|
552
418
|
if (!e.instance)
|
|
553
419
|
throw "instance not initialized";
|
|
@@ -555,80 +421,80 @@ async function ge(r, e) {
|
|
|
555
421
|
throw "missing function name to call";
|
|
556
422
|
if (!e.instance[t])
|
|
557
423
|
throw `undefined function [${t}] in class ${e.instance.constructor.workerId}`;
|
|
558
|
-
|
|
424
|
+
S(r, await e.instance[t](...s ?? []));
|
|
559
425
|
}
|
|
560
|
-
const
|
|
561
|
-
function
|
|
426
|
+
const me = U("registeredWorkers", {});
|
|
427
|
+
function ge(r, e) {
|
|
562
428
|
if (!r.args)
|
|
563
429
|
throw "Missing className while initializing worker";
|
|
564
|
-
const [t, s] = r.args, i =
|
|
430
|
+
const [t, s] = r.args, i = me[t];
|
|
565
431
|
if (i)
|
|
566
432
|
e.instance = new i(r.args.slice(1));
|
|
567
433
|
else
|
|
568
434
|
throw `unknown worker class ${t}`;
|
|
569
|
-
|
|
435
|
+
C(s, p), S(r, typeof e.instance !== void 0);
|
|
570
436
|
}
|
|
571
|
-
async function
|
|
437
|
+
async function ye(r, e) {
|
|
572
438
|
const { args: t } = r;
|
|
573
439
|
if (!e.instance)
|
|
574
440
|
throw "instance not initialized";
|
|
575
441
|
let s;
|
|
576
|
-
e.instance.terminate && (s = await e.instance.terminate(...t ?? [])),
|
|
442
|
+
e.instance.terminate && (s = await e.instance.terminate(...t ?? [])), S(r, s);
|
|
577
443
|
}
|
|
578
|
-
function
|
|
444
|
+
function we(r) {
|
|
579
445
|
if (!r.args)
|
|
580
446
|
throw "Missing globals while syncing";
|
|
581
|
-
|
|
447
|
+
C(r.args[0], p), S(r, {});
|
|
582
448
|
}
|
|
583
|
-
function
|
|
449
|
+
function _e() {
|
|
584
450
|
const r = {};
|
|
585
451
|
onmessage = async (e) => {
|
|
586
452
|
const t = e.data;
|
|
587
453
|
switch (t.type) {
|
|
588
454
|
case g.INIT:
|
|
589
|
-
|
|
455
|
+
ge(t, r);
|
|
590
456
|
break;
|
|
591
457
|
case g.FORWARD:
|
|
592
|
-
|
|
458
|
+
pe(t, r);
|
|
593
459
|
break;
|
|
594
460
|
case g.TERMINATE:
|
|
595
|
-
|
|
461
|
+
ye(t, r);
|
|
596
462
|
break;
|
|
597
463
|
case g.GLOBALS_SYNC:
|
|
598
|
-
|
|
464
|
+
we(t);
|
|
599
465
|
break;
|
|
600
466
|
}
|
|
601
467
|
};
|
|
602
468
|
}
|
|
603
|
-
|
|
604
|
-
function
|
|
469
|
+
X() && _e();
|
|
470
|
+
function be(r, e) {
|
|
605
471
|
return p[r] || (p[r] = e), [
|
|
606
472
|
() => p[r],
|
|
607
473
|
async (t) => {
|
|
608
|
-
p[r] = t, await
|
|
474
|
+
p[r] = t, await ue();
|
|
609
475
|
}
|
|
610
476
|
];
|
|
611
477
|
}
|
|
612
|
-
function
|
|
613
|
-
return
|
|
478
|
+
function Te(r, e) {
|
|
479
|
+
return be(r, e);
|
|
614
480
|
}
|
|
615
|
-
const [
|
|
616
|
-
function
|
|
617
|
-
|
|
481
|
+
const [Se, ke] = Te("metadata");
|
|
482
|
+
function ze(r) {
|
|
483
|
+
ke(r);
|
|
618
484
|
}
|
|
619
|
-
function
|
|
620
|
-
return
|
|
485
|
+
function L() {
|
|
486
|
+
return Se();
|
|
621
487
|
}
|
|
622
|
-
class
|
|
488
|
+
class z {
|
|
623
489
|
constructor(e, t) {
|
|
624
|
-
|
|
490
|
+
te(this, "uuid"), this.config = e, this.uuid = t ?? de();
|
|
625
491
|
}
|
|
626
492
|
async send(e) {
|
|
627
493
|
var t, s, i;
|
|
628
|
-
const { appId: n, sourceType: o } = (t =
|
|
494
|
+
const { appId: n, sourceType: o } = (t = L()) != null ? t : {};
|
|
629
495
|
if (!n || !o)
|
|
630
496
|
return "metadata missing";
|
|
631
|
-
const a = new AbortController(), l = setTimeout(() => a.abort(),
|
|
497
|
+
const a = new AbortController(), l = setTimeout(() => a.abort(), ne);
|
|
632
498
|
return await ((i = (s = this.config) == null ? void 0 : s.fetch) != null ? i : fetch)(this.getUrl(), {
|
|
633
499
|
method: "POST",
|
|
634
500
|
headers: this.getHeaders(),
|
|
@@ -638,8 +504,8 @@ class V {
|
|
|
638
504
|
}
|
|
639
505
|
getUrl() {
|
|
640
506
|
var e;
|
|
641
|
-
let t = (e =
|
|
642
|
-
return t += (t.at(-1) === "/" ? "" : "/") +
|
|
507
|
+
let t = (e = L().proxyUrl) != null ? e : ie;
|
|
508
|
+
return t += (t.at(-1) === "/" ? "" : "/") + se, t;
|
|
643
509
|
}
|
|
644
510
|
getHeaders() {
|
|
645
511
|
return {
|
|
@@ -647,7 +513,7 @@ class V {
|
|
|
647
513
|
};
|
|
648
514
|
}
|
|
649
515
|
buildReport(e) {
|
|
650
|
-
const t =
|
|
516
|
+
const t = L();
|
|
651
517
|
return {
|
|
652
518
|
guid: this.uuid,
|
|
653
519
|
...e,
|
|
@@ -658,12 +524,12 @@ class V {
|
|
|
658
524
|
};
|
|
659
525
|
}
|
|
660
526
|
}
|
|
661
|
-
const
|
|
527
|
+
const P = "3.0.1-alpha.0", O = class O {
|
|
662
528
|
};
|
|
663
|
-
|
|
529
|
+
O.updates = {
|
|
664
530
|
transformer_new: "New transformer",
|
|
665
531
|
transformer_null: "Null transformer"
|
|
666
|
-
},
|
|
532
|
+
}, O.errors = {
|
|
667
533
|
transformer_none: "No transformers provided",
|
|
668
534
|
transformer_start: "Cannot start transformer",
|
|
669
535
|
transformer_transform: "Cannot transform frame",
|
|
@@ -671,24 +537,24 @@ W.updates = {
|
|
|
671
537
|
readable_null: "Readable is null",
|
|
672
538
|
writable_null: "Writable is null"
|
|
673
539
|
};
|
|
674
|
-
let f =
|
|
675
|
-
function
|
|
540
|
+
let f = O;
|
|
541
|
+
function Ee(r) {
|
|
676
542
|
return typeof r == "object" && r !== null && "message" in r && typeof r.message == "string";
|
|
677
543
|
}
|
|
678
|
-
function
|
|
679
|
-
if (
|
|
544
|
+
function ve(r) {
|
|
545
|
+
if (Ee(r)) return r;
|
|
680
546
|
try {
|
|
681
547
|
return new Error(JSON.stringify(r));
|
|
682
548
|
} catch {
|
|
683
549
|
return new Error(String(r));
|
|
684
550
|
}
|
|
685
551
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
552
|
+
function G(r) {
|
|
553
|
+
return ve(r).message;
|
|
688
554
|
}
|
|
689
|
-
class
|
|
555
|
+
class Pe {
|
|
690
556
|
constructor(e, t) {
|
|
691
|
-
this.config = e, this.frameTransformedCount = 0, this.frameFromSourceCount = 0, this.startAt = 0, this.reporter = new
|
|
557
|
+
this.config = e, this.frameTransformedCount = 0, this.frameFromSourceCount = 0, this.startAt = 0, this.reporter = new z(e, t);
|
|
692
558
|
}
|
|
693
559
|
async onFrameFromSource() {
|
|
694
560
|
this.frameFromSourceCount++;
|
|
@@ -699,25 +565,25 @@ class Ae {
|
|
|
699
565
|
}
|
|
700
566
|
async onFrameTransformed(e = {}, t = !1) {
|
|
701
567
|
this.startAt === 0 && (this.startAt = Date.now()), this.frameTransformedCount++;
|
|
702
|
-
const { startAt: s, frameTransformedCount: i, frameFromSourceCount: n } = this, o = Date.now(), a = (o - s) / 1e3, l = i / a,
|
|
568
|
+
const { startAt: s, frameTransformedCount: i, frameFromSourceCount: n } = this, o = Date.now(), a = (o - s) / 1e3, l = i / a, y = n / a;
|
|
703
569
|
return t || this.frameTransformedCount >= this.config.loggingIntervalFrameCount ? (this.frameFromSourceCount = 0, this.frameTransformedCount = 0, this.startAt = o, this.reporter.config = this.config, this.reporter.send({
|
|
704
570
|
...this.config.report,
|
|
705
571
|
variation: "QoS",
|
|
706
|
-
fps:
|
|
572
|
+
fps: y,
|
|
707
573
|
transformedFps: l,
|
|
708
574
|
framesTransformed: i,
|
|
709
575
|
...e
|
|
710
576
|
})) : "success";
|
|
711
577
|
}
|
|
712
578
|
}
|
|
713
|
-
var
|
|
714
|
-
const
|
|
715
|
-
class
|
|
579
|
+
var Ae = /* @__PURE__ */ ((r) => (r.FPS_DROP = "fps_drop", r))(Ae || {}), Me = /* @__PURE__ */ ((r) => (r.start = "start", r.transform = "transform", r.flush = "flush", r))(Me || {}), $ = /* @__PURE__ */ ((r) => (r.pipeline_ended = "pipeline_ended", r.pipeline_ended_with_error = "pipeline_ended_with_error", r.pipeline_started = "pipeline_started", r.pipeline_started_with_error = "pipeline_started_with_error", r.pipeline_restarted = "pipeline_restarted", r.pipeline_restarted_with_error = "pipeline_restarted_with_error", r))($ || {});
|
|
580
|
+
const Re = 500, Ie = 0.8;
|
|
581
|
+
class xe extends h {
|
|
716
582
|
constructor(e, t) {
|
|
717
|
-
super(), this.reporter_ = new
|
|
718
|
-
loggingIntervalFrameCount:
|
|
583
|
+
super(), this.reporter_ = new z(), this.reporterQos_ = new Pe({
|
|
584
|
+
loggingIntervalFrameCount: Re,
|
|
719
585
|
report: {
|
|
720
|
-
version:
|
|
586
|
+
version: P
|
|
721
587
|
}
|
|
722
588
|
}), this.index_ = t, this.transformer_ = e, this.shouldStop_ = !1, this.isFlashed_ = !1, this.mediaTransformerQosReportStartTimestamp_ = 0, this.videoHeight_ = 0, this.videoWidth_ = 0, this.trackExpectedRate_ = -1, this.transformerType_ = "Custom", "getTransformerType" in e && (this.transformerType_ = e.getTransformerType()), this.report({
|
|
723
589
|
variation: "Create"
|
|
@@ -734,7 +600,7 @@ class Oe extends h {
|
|
|
734
600
|
this.report({
|
|
735
601
|
message: f.errors.transformer_start,
|
|
736
602
|
variation: "Error",
|
|
737
|
-
error:
|
|
603
|
+
error: G(t)
|
|
738
604
|
});
|
|
739
605
|
const s = {
|
|
740
606
|
eventMetaData: { transformerIndex: this.index_ },
|
|
@@ -756,7 +622,7 @@ class Oe extends h {
|
|
|
756
622
|
this.report({
|
|
757
623
|
message: f.errors.transformer_transform,
|
|
758
624
|
variation: "Error",
|
|
759
|
-
error:
|
|
625
|
+
error: G(s)
|
|
760
626
|
});
|
|
761
627
|
const i = {
|
|
762
628
|
eventMetaData: { transformerIndex: this.index_ },
|
|
@@ -766,7 +632,7 @@ class Oe extends h {
|
|
|
766
632
|
};
|
|
767
633
|
this.emit("error", i);
|
|
768
634
|
}
|
|
769
|
-
if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ *
|
|
635
|
+
if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * Ie > this.reporterQos_.fps) {
|
|
770
636
|
const s = {
|
|
771
637
|
eventMetaData: {
|
|
772
638
|
transformerIndex: this.index_
|
|
@@ -790,7 +656,7 @@ class Oe extends h {
|
|
|
790
656
|
this.report({
|
|
791
657
|
message: f.errors.transformer_flush,
|
|
792
658
|
variation: "Error",
|
|
793
|
-
error:
|
|
659
|
+
error: G(t)
|
|
794
660
|
});
|
|
795
661
|
const s = {
|
|
796
662
|
eventMetaData: { transformerIndex: this.index_ },
|
|
@@ -810,7 +676,7 @@ class Oe extends h {
|
|
|
810
676
|
}
|
|
811
677
|
report(e) {
|
|
812
678
|
this.reporter_.send({
|
|
813
|
-
version:
|
|
679
|
+
version: P,
|
|
814
680
|
action: "MediaTransformer",
|
|
815
681
|
transformerType: this.transformerType_,
|
|
816
682
|
...e
|
|
@@ -821,7 +687,7 @@ class Oe extends h {
|
|
|
821
687
|
...this.reporterQos_.config
|
|
822
688
|
}, this.reporterQos_.onFrameTransformed(
|
|
823
689
|
{
|
|
824
|
-
version:
|
|
690
|
+
version: P,
|
|
825
691
|
action: "MediaTransformer",
|
|
826
692
|
transformerType: this.transformerType_,
|
|
827
693
|
videoWidth: this.videoWidth_,
|
|
@@ -831,11 +697,11 @@ class Oe extends h {
|
|
|
831
697
|
);
|
|
832
698
|
}
|
|
833
699
|
}
|
|
834
|
-
class
|
|
700
|
+
class Ce extends h {
|
|
835
701
|
constructor(e) {
|
|
836
702
|
super(), this.transformers_ = [], this.trackExpectedRate_ = -1;
|
|
837
703
|
for (let t = 0; t < e.length; t++) {
|
|
838
|
-
let s = new
|
|
704
|
+
let s = new xe(e[t], t);
|
|
839
705
|
s.on("error", (i) => {
|
|
840
706
|
this.emit("error", i);
|
|
841
707
|
}), s.on("warn", (i) => {
|
|
@@ -901,9 +767,9 @@ class Le extends h {
|
|
|
901
767
|
e.stop();
|
|
902
768
|
}
|
|
903
769
|
}
|
|
904
|
-
class
|
|
770
|
+
class Oe extends h {
|
|
905
771
|
constructor() {
|
|
906
|
-
super(), this.reporter_ = new
|
|
772
|
+
super(), this.reporter_ = new z(), this.trackExpectedRate_ = -1, this.report({
|
|
907
773
|
variation: "Create"
|
|
908
774
|
});
|
|
909
775
|
}
|
|
@@ -959,12 +825,12 @@ class We extends h {
|
|
|
959
825
|
return;
|
|
960
826
|
}
|
|
961
827
|
let s = !1;
|
|
962
|
-
this.pipeline_ && (s = !0, this.pipeline_.clearListeners(), this.pipeline_.destroy()), this.pipeline_ = new
|
|
828
|
+
this.pipeline_ && (s = !0, this.pipeline_.clearListeners(), this.pipeline_.destroy()), this.pipeline_ = new Ce(this.transformers_), this.pipeline_.on("warn", (i) => {
|
|
963
829
|
this.emit("warn", i);
|
|
964
830
|
}), this.pipeline_.on("error", (i) => {
|
|
965
831
|
this.emit("error", i);
|
|
966
832
|
}), this.pipeline_.on("pipelineInfo", (i) => {
|
|
967
|
-
s && (i === "pipeline_started" ? i =
|
|
833
|
+
s && (i === "pipeline_started" ? i = $.pipeline_restarted : i === "pipeline_started_with_error" && (i = $.pipeline_restarted_with_error)), this.emit("pipelineInfo", i);
|
|
968
834
|
}), this.trackExpectedRate_ != -1 && this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_), this.pipeline_.start(this.readable_, this.writable_).then(() => {
|
|
969
835
|
e();
|
|
970
836
|
}).catch((i) => {
|
|
@@ -997,7 +863,7 @@ class We extends h {
|
|
|
997
863
|
}
|
|
998
864
|
report(e) {
|
|
999
865
|
this.reporter_.send({
|
|
1000
|
-
version:
|
|
866
|
+
version: P,
|
|
1001
867
|
action: "MediaProcessor",
|
|
1002
868
|
...e
|
|
1003
869
|
});
|
|
@@ -1006,23 +872,163 @@ class We extends h {
|
|
|
1006
872
|
return "kind" in e;
|
|
1007
873
|
}
|
|
1008
874
|
}
|
|
1009
|
-
class
|
|
875
|
+
class We {
|
|
876
|
+
constructor({ kind: e }) {
|
|
877
|
+
if (e == "video") {
|
|
878
|
+
const t = document.createElement("canvas"), s = t.getContext("2d", {
|
|
879
|
+
desynchronized: !0
|
|
880
|
+
}), i = t.captureStream().getVideoTracks()[0];
|
|
881
|
+
return i.writable = new WritableStream({
|
|
882
|
+
write(n) {
|
|
883
|
+
t.width = n.displayWidth, t.height = n.displayHeight, s.drawImage(n, 0, 0, t.width, t.height), n.close();
|
|
884
|
+
}
|
|
885
|
+
}), i;
|
|
886
|
+
} else if (e == "audio") {
|
|
887
|
+
const t = new AudioContext(), s = t.createMediaStreamDestination(), [i] = s.stream.getAudioTracks();
|
|
888
|
+
return i.writable = new WritableStream({
|
|
889
|
+
async start(n) {
|
|
890
|
+
this.arrays = [];
|
|
891
|
+
function o() {
|
|
892
|
+
registerProcessor(
|
|
893
|
+
"mstg-shim",
|
|
894
|
+
class extends AudioWorkletProcessor {
|
|
895
|
+
constructor() {
|
|
896
|
+
super(), this.arrays = [], this.arrayOffset = 0, this.port.onmessage = ({ data: l }) => this.arrays.push(l), this.emptyArray = new Float32Array(0);
|
|
897
|
+
}
|
|
898
|
+
process(l, [[y]]) {
|
|
899
|
+
for (let W = 0; W < y.length; W++)
|
|
900
|
+
(!this.array || this.arrayOffset >= this.array.length) && (this.array = this.arrays.shift() || this.emptyArray, this.arrayOffset = 0), y[W] = this.array[this.arrayOffset++] || 0;
|
|
901
|
+
return !0;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
return await t.audioWorklet.addModule(
|
|
907
|
+
`data:text/javascript,(${o.toString()})()`
|
|
908
|
+
), this.node = new AudioWorkletNode(t, "mstg-shim"), this.node.connect(s), i;
|
|
909
|
+
},
|
|
910
|
+
write(n) {
|
|
911
|
+
const o = new Float32Array(
|
|
912
|
+
n.numberOfFrames * n.numberOfChannels
|
|
913
|
+
);
|
|
914
|
+
n.copyTo(o, { planeIndex: 0 }), this.node.port.postMessage(o, [o.buffer]), n.close();
|
|
915
|
+
}
|
|
916
|
+
}), i;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function Fe() {
|
|
921
|
+
return self.MediaStreamTrackGenerator ? self.MediaStreamTrackGenerator : We;
|
|
922
|
+
}
|
|
923
|
+
class Le {
|
|
924
|
+
constructor(e) {
|
|
925
|
+
const t = e.track ?? e;
|
|
926
|
+
t.kind == "video" ? this.readable = new ReadableStream({
|
|
927
|
+
async start(s) {
|
|
928
|
+
t.addEventListener(
|
|
929
|
+
"ended",
|
|
930
|
+
() => s.close(),
|
|
931
|
+
{ once: !0 }
|
|
932
|
+
), this.video = document.createElement("video"), this.video.srcObject = new MediaStream([t]), await Promise.all([
|
|
933
|
+
this.video.play(),
|
|
934
|
+
new Promise(
|
|
935
|
+
(i) => this.video.onloadedmetadata = i
|
|
936
|
+
)
|
|
937
|
+
]), this.track = t, this.canvas = new OffscreenCanvas(
|
|
938
|
+
this.video.videoWidth,
|
|
939
|
+
this.video.videoHeight
|
|
940
|
+
), this.ctx = this.canvas.getContext("2d", {
|
|
941
|
+
desynchronized: !0
|
|
942
|
+
}), this.t1 = performance.now();
|
|
943
|
+
},
|
|
944
|
+
async pull(s) {
|
|
945
|
+
if (t.readyState == "ended")
|
|
946
|
+
return s.close();
|
|
947
|
+
const i = t.getSettings().frameRate || 30;
|
|
948
|
+
for (; performance.now() - this.t1 < 1e3 / i; )
|
|
949
|
+
if (await new Promise((n) => requestAnimationFrame(n)), t.readyState == "ended")
|
|
950
|
+
return s.close();
|
|
951
|
+
this.canvas.width = this.video.videoWidth, this.canvas.height = this.video.videoHeight, this.t1 = performance.now(), this.ctx.drawImage(this.video, 0, 0), s.enqueue(
|
|
952
|
+
new VideoFrame(this.canvas, {
|
|
953
|
+
timestamp: this.t1
|
|
954
|
+
})
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
}) : t.kind == "audio" && (this.readable = new ReadableStream({
|
|
958
|
+
async start(s) {
|
|
959
|
+
t.addEventListener(
|
|
960
|
+
"ended",
|
|
961
|
+
() => s.close(),
|
|
962
|
+
{ once: !0 }
|
|
963
|
+
), this.ac = new AudioContext(), this.arrays = [];
|
|
964
|
+
function i() {
|
|
965
|
+
registerProcessor(
|
|
966
|
+
"mstp-shim",
|
|
967
|
+
class extends AudioWorkletProcessor {
|
|
968
|
+
process(o) {
|
|
969
|
+
return this.port.postMessage(o), !0;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
await this.ac.audioWorklet.addModule(
|
|
975
|
+
`data:text/javascript,(${i.toString()})()`
|
|
976
|
+
), this.node = new AudioWorkletNode(this.ac, "mstp-shim"), this.ac.createMediaStreamSource(new MediaStream([t])).connect(this.node), this.node.port.addEventListener(
|
|
977
|
+
"message",
|
|
978
|
+
({ data: n }) => n[0][0] && this.arrays.push(n)
|
|
979
|
+
);
|
|
980
|
+
},
|
|
981
|
+
async pull(s) {
|
|
982
|
+
if (t.readyState == "ended")
|
|
983
|
+
return s.close();
|
|
984
|
+
for (; !this.arrays.length; )
|
|
985
|
+
if (await new Promise(
|
|
986
|
+
(o) => this.node.port.onmessage = o
|
|
987
|
+
), t.readyState == "ended")
|
|
988
|
+
return s.close();
|
|
989
|
+
const [i] = this.arrays.shift(), n = new Float32Array(
|
|
990
|
+
i.reduce((o, a) => o + a.length, 0)
|
|
991
|
+
);
|
|
992
|
+
i.reduce(
|
|
993
|
+
(o, a) => (n.set(a, o), o + a.length),
|
|
994
|
+
0
|
|
995
|
+
), s.enqueue(
|
|
996
|
+
new AudioData({
|
|
997
|
+
format: "f32-planar",
|
|
998
|
+
sampleRate: this.ac.sampleRate,
|
|
999
|
+
numberOfFrames: i[0].length,
|
|
1000
|
+
numberOfChannels: i.length,
|
|
1001
|
+
timestamp: this.ac.currentTime * 1e6 | 0,
|
|
1002
|
+
data: n,
|
|
1003
|
+
transfer: [n.buffer]
|
|
1004
|
+
})
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
}));
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
function Ge() {
|
|
1011
|
+
return self.MediaStreamTrackProcessor ? self.MediaStreamTrackProcessor : Le;
|
|
1012
|
+
}
|
|
1013
|
+
class $e {
|
|
1010
1014
|
constructor() {
|
|
1011
1015
|
this.processor_ = null, this.generator_ = null;
|
|
1012
1016
|
}
|
|
1013
1017
|
init(e) {
|
|
1014
1018
|
return new Promise((t, s) => {
|
|
1015
1019
|
try {
|
|
1016
|
-
|
|
1020
|
+
const i = Ge();
|
|
1021
|
+
this.processor_ = new i(e);
|
|
1017
1022
|
} catch (i) {
|
|
1018
1023
|
console.log(
|
|
1019
1024
|
`[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${i}`
|
|
1020
1025
|
), s(i);
|
|
1021
1026
|
}
|
|
1022
1027
|
try {
|
|
1023
|
-
|
|
1028
|
+
const i = Fe();
|
|
1029
|
+
e.kind === "audio" ? this.generator_ = new i({
|
|
1024
1030
|
kind: "audio"
|
|
1025
|
-
}) : e.kind === "video" ? this.generator_ = new
|
|
1031
|
+
}) : e.kind === "video" ? this.generator_ = new i({
|
|
1026
1032
|
kind: "video"
|
|
1027
1033
|
}) : s("kind not supported");
|
|
1028
1034
|
} catch (i) {
|
|
@@ -1043,7 +1049,7 @@ class Fe {
|
|
|
1043
1049
|
return this.generator_;
|
|
1044
1050
|
}
|
|
1045
1051
|
}
|
|
1046
|
-
class
|
|
1052
|
+
class je {
|
|
1047
1053
|
/**
|
|
1048
1054
|
* - When running insertable streams on the main `MediaProcessorInterface` should be instance of `MediaProcessor` class.
|
|
1049
1055
|
* - When running insertable streams on WebWorker `MediaProcessorInterface` should be instance of bridge calss created by the user. Example can be found [here](/docs/intro.md#using-the-transformer-on-webworker)
|
|
@@ -1060,13 +1066,13 @@ class ze {
|
|
|
1060
1066
|
* @returns New track to be used.
|
|
1061
1067
|
*/
|
|
1062
1068
|
async setTrack(e) {
|
|
1063
|
-
if (!(this.mediaProcessor_ instanceof
|
|
1069
|
+
if (!(this.mediaProcessor_ instanceof Oe) && await Y()) {
|
|
1064
1070
|
if (e.kind === "audio")
|
|
1065
1071
|
throw Error("Cannot process audio tracks inside a web worker when passing a track to transform");
|
|
1066
1072
|
return await this.mediaProcessor_.transform(e);
|
|
1067
1073
|
}
|
|
1068
|
-
if (
|
|
1069
|
-
const t = new
|
|
1074
|
+
if (B()) {
|
|
1075
|
+
const t = new $e();
|
|
1070
1076
|
return await t.init(e), await this.mediaProcessor_.transform(
|
|
1071
1077
|
t.getReadable(),
|
|
1072
1078
|
t.getWriteable()
|
|
@@ -1088,13 +1094,13 @@ class ze {
|
|
|
1088
1094
|
}
|
|
1089
1095
|
}
|
|
1090
1096
|
export {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1097
|
+
Me as ErrorFunction,
|
|
1098
|
+
Oe as MediaProcessor,
|
|
1099
|
+
je as MediaProcessorConnector,
|
|
1100
|
+
$ as PipelineInfoData,
|
|
1101
|
+
re as VonageSourceType,
|
|
1102
|
+
Ae as WarningType,
|
|
1103
|
+
L as getVonageMetadata,
|
|
1104
|
+
Ue as isSupported,
|
|
1105
|
+
ze as setVonageMetadata
|
|
1100
1106
|
};
|