@vonage/media-processor 2.0.2 → 2.0.4

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