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