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