@vonage/media-processor 2.0.3 → 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"), A = Symbol("listenerRemoved");
23
- let x = !1;
24
- function g(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 _(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 === A;
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
- g(s), _(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
- g(s), _(this, s).delete(r), this.logIfDebugEnabled("unsubscribe", s, void 0), I(s) || this.emit(A, { 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
- g(r);
172
- return $(this, e);
174
+ p(r);
175
+ return D(this, e);
173
176
  }
174
177
  async emit(e, r) {
175
- g(e), this.logIfDebugEnabled("emit", e, r), q(this, e, r);
176
- const s = _(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
- g(e), this.logIfDebugEnabled("emitSerial", e, r);
190
- const s = _(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(A, { 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
- _(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 + _(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" && g(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: A,
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,96 +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), z = {
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 (z.randomUUID && !e && !t)
305
- return z.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) {
320
+ function F(t, e) {
317
321
  globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {});
318
322
  let r = globalThis.vonage.workerizer;
319
323
  return r[t] || (r[t] = e), r[t];
320
324
  }
321
- const p = W(
325
+ const h = F(
322
326
  "globals",
323
327
  {}
324
328
  );
325
- var d = /* @__PURE__ */ ((t) => (t.INIT = "INIT", t.FORWARD = "FORWARD", t.TERMINATE = "TERMINATE", t.GLOBALS_SYNC = "GLOBALS_SYNC", t))(d || {});
326
- function j(t) {
327
- return [ImageBitmap, ReadableStream, WritableStream].some((e) => t instanceof e);
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);
328
332
  }
329
- let fe = 0;
330
- function le(t, e, r, s, o) {
331
- const i = fe++;
333
+ let ce = 0;
334
+ function le(t, e, r, s, i) {
335
+ const n = ce++;
332
336
  return t.postMessage(
333
337
  {
334
- id: i,
338
+ id: n,
335
339
  type: e,
336
340
  functionName: r,
337
341
  args: s
338
342
  },
339
- s.filter((n) => j(n))
340
- ), new Promise((n) => {
341
- o == null || o.set(i, n);
343
+ s.filter((a) => z(a))
344
+ ), new Promise((a) => {
345
+ i == null || i.set(n, a);
342
346
  });
343
347
  }
344
- function w(t, e) {
345
- 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];
346
350
  postMessage(
347
351
  {
348
352
  id: r,
349
353
  type: s,
350
354
  result: e
351
355
  },
352
- o.filter((i) => j(i))
356
+ i.filter((n) => z(n))
353
357
  );
354
358
  }
355
- const G = W("workerized", {});
356
- function B() {
359
+ const Q = F("workerized", {});
360
+ function V() {
357
361
  return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
358
362
  }
359
- async function ue() {
360
- if (B())
361
- w({ type: d.GLOBALS_SYNC }, p);
363
+ async function fe() {
364
+ if (V())
365
+ y({ type: u.GLOBALS_SYNC }, h);
362
366
  else {
363
367
  const t = [];
364
- for (const e in G) {
365
- const { worker: r, resolvers: s } = G[e].workerContext;
368
+ for (const e in Q) {
369
+ const { worker: r, resolvers: s } = Q[e].workerContext;
366
370
  r && t.push(
367
371
  le(
368
372
  r,
369
- d.GLOBALS_SYNC,
373
+ u.GLOBALS_SYNC,
370
374
  "",
371
- [p],
375
+ [h],
372
376
  s
373
377
  )
374
378
  );
@@ -393,91 +397,91 @@ async function he(t, e) {
393
397
  throw "missing function name to call";
394
398
  if (!e.instance[r])
395
399
  throw `undefined function [${r}] in class ${e.instance.constructor.workerId}`;
396
- w(t, await e.instance[r](...s != null ? s : []));
400
+ y(t, await e.instance[r](...s ?? []));
397
401
  }
398
- const pe = W("registeredWorkers", {});
402
+ const ue = F("registeredWorkers", {});
399
403
  function de(t, e) {
400
404
  if (!t.args)
401
405
  throw "Missing className while initializing worker";
402
- const [r, s] = t.args, o = pe[r];
403
- if (o)
404
- 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));
405
409
  else
406
410
  throw `unknown worker class ${r}`;
407
- P(s, p), w(t, typeof e.instance !== void 0);
411
+ P(s, h), y(t, typeof e.instance !== void 0);
408
412
  }
409
- async function me(t, e) {
413
+ async function pe(t, e) {
410
414
  const { args: r } = t;
411
415
  if (!e.instance)
412
416
  throw "instance not initialized";
413
417
  let s;
414
- 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);
415
419
  }
416
- function ge(t) {
420
+ function me(t) {
417
421
  if (!t.args)
418
422
  throw "Missing globals while syncing";
419
- P(t.args[0], p), w(t, {});
423
+ P(t.args[0], h), y(t, {});
420
424
  }
421
- function _e() {
425
+ function ge() {
422
426
  const t = {};
423
427
  onmessage = async (e) => {
424
428
  const r = e.data;
425
429
  switch (r.type) {
426
- case d.INIT:
430
+ case u.INIT:
427
431
  de(r, t);
428
432
  break;
429
- case d.FORWARD:
433
+ case u.FORWARD:
430
434
  he(r, t);
431
435
  break;
432
- case d.TERMINATE:
433
- me(r, t);
436
+ case u.TERMINATE:
437
+ pe(r, t);
434
438
  break;
435
- case d.GLOBALS_SYNC:
436
- ge(r);
439
+ case u.GLOBALS_SYNC:
440
+ me(r);
437
441
  break;
438
442
  }
439
443
  };
440
444
  }
441
- B() && _e();
442
- function ye(t, e) {
443
- return p[t] || (p[t] = e), [
444
- () => p[t],
445
+ V() && ge();
446
+ function _e(t, e) {
447
+ return h[t] || (h[t] = e), [
448
+ () => h[t],
445
449
  async (r) => {
446
- p[t] = r, await ue();
450
+ h[t] = r, await fe();
447
451
  }
448
452
  ];
449
453
  }
450
- function be(t, e) {
451
- return ye(t, e);
454
+ function ye(t, e) {
455
+ return _e(t, e);
452
456
  }
453
- const [we, Te] = be("metadata");
454
- function Ce(t) {
455
- Te(t);
457
+ const [be, we] = ye("metadata");
458
+ function xe(t) {
459
+ we(t);
456
460
  }
457
- function C() {
458
- return we();
461
+ function x() {
462
+ return be();
459
463
  }
460
- class D {
461
- constructor(e) {
462
- 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();
463
467
  }
464
468
  async send(e) {
465
- var r, s, o;
466
- const { appId: i, sourceType: n } = (r = C()) != null ? r : {};
467
- if (!i || !n)
469
+ var r, s, i;
470
+ const { appId: n, sourceType: o } = (r = x()) != null ? r : {};
471
+ if (!n || !o)
468
472
  return "metadata missing";
469
- const c = new AbortController(), u = setTimeout(() => c.abort(), se);
470
- 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(), {
471
475
  method: "POST",
472
476
  headers: this.getHeaders(),
473
477
  body: JSON.stringify(this.buildReport(e)),
474
- signal: c.signal
475
- }), clearTimeout(u), "success";
478
+ signal: a.signal
479
+ }), clearTimeout(k), "success";
476
480
  }
477
481
  getUrl() {
478
482
  var e;
479
- let r = (e = C().proxyUrl) != null ? e : te;
480
- return r += (r.at(-1) === "/" ? "" : "/") + re, r;
483
+ let r = (e = x().proxyUrl) != null ? e : re;
484
+ return r += (r.at(-1) === "/" ? "" : "/") + ee, r;
481
485
  }
482
486
  getHeaders() {
483
487
  return {
@@ -485,7 +489,7 @@ class D {
485
489
  };
486
490
  }
487
491
  buildReport(e) {
488
- const r = C();
492
+ const r = x();
489
493
  return {
490
494
  guid: this.uuid,
491
495
  ...e,
@@ -496,97 +500,90 @@ class D {
496
500
  };
497
501
  }
498
502
  }
499
- const R = "2.0.3";
500
- class Se {
501
- constructor(e) {
502
- a(this, "frameTransformedCount", 0);
503
- a(this, "frameFromSourceCount", 0);
504
- a(this, "startAt", 0);
505
- a(this, "reporter");
506
- 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);
507
507
  }
508
508
  async onFrameFromSource() {
509
509
  this.frameFromSourceCount++;
510
510
  }
511
511
  get fps() {
512
- const { startAt: e, frameFromSourceCount: r } = this, o = (Date.now() - e) / 1e3;
513
- return r / o;
512
+ const { startAt: e, frameFromSourceCount: r } = this, i = (Date.now() - e) / 1e3;
513
+ return r / i;
514
514
  }
515
515
  async onFrameTransformed(e = {}, r = !1) {
516
516
  this.startAt === 0 && (this.startAt = Date.now()), this.frameTransformedCount++;
517
- const { startAt: s, frameTransformedCount: o, frameFromSourceCount: i } = this, n = Date.now(), c = (n - s) / 1e3, u = o / c, M = i / c;
518
- 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({
519
519
  ...this.config.report,
520
520
  variation: "QoS",
521
- fps: M,
522
- transformedFps: u,
523
- framesTransformed: o,
521
+ fps: W,
522
+ transformedFps: k,
523
+ framesTransformed: i,
524
524
  ...e
525
525
  })) : "success";
526
526
  }
527
527
  }
528
- 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 || {});
529
- const ke = 500, Ae = 0.8;
530
- class Pe extends L {
531
- constructor(r, s) {
532
- super();
533
- a(this, "reporter_", new D());
534
- a(this, "reporterQos_", new Se({
535
- 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,
536
534
  report: {
537
- version: R
535
+ version: E
538
536
  }
539
- }));
540
- a(this, "transformerType_");
541
- a(this, "transformer_");
542
- a(this, "shouldStop_");
543
- a(this, "isFlashed_");
544
- a(this, "mediaTransformerQosReportStartTimestamp_");
545
- a(this, "videoHeight_");
546
- a(this, "videoWidth_");
547
- a(this, "trackExpectedRate_");
548
- a(this, "index_");
549
- a(this, "controller_");
550
- 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({
551
538
  variation: "Create"
552
539
  });
553
540
  }
554
- setTrackExpectedRate(r) {
555
- this.trackExpectedRate_ = r;
541
+ setTrackExpectedRate(e) {
542
+ this.trackExpectedRate_ = e;
556
543
  }
557
- async start(r) {
558
- 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")
559
546
  try {
560
- await this.transformer_.start(r);
561
- } catch (s) {
547
+ await this.transformer_.start(e);
548
+ } catch (r) {
562
549
  this.report({
563
550
  message: l.errors.transformer_start,
564
551
  variation: "Error",
565
- error: v(s)
552
+ error: I(r)
566
553
  });
567
- const o = { eventMetaData: { transformerIndex: this.index_ }, error: s, function: "start" };
568
- 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);
569
561
  }
570
562
  }
571
- async transform(r, s) {
572
- var o, i, n, c;
573
- 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_)
574
566
  if (this.shouldStop_)
575
- 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();
576
568
  else {
577
569
  try {
578
- await ((c = (n = this.transformer_).transform) == null ? void 0 : c.call(n, r, s)), this.reportQos();
579
- } catch (u) {
570
+ await ((i = (s = this.transformer_).transform) == null ? void 0 : i.call(s, e, r)), this.reportQos();
571
+ } catch (n) {
580
572
  this.report({
581
573
  message: l.errors.transformer_transform,
582
574
  variation: "Error",
583
- error: v(u)
575
+ error: I(n)
584
576
  });
585
- const M = { eventMetaData: { transformerIndex: this.index_ }, error: u, function: "transform" };
586
- 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);
587
584
  }
588
- if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * Ae > this.reporterQos_.fps) {
589
- const u = {
585
+ if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * Pe > this.reporterQos_.fps) {
586
+ const n = {
590
587
  eventMetaData: {
591
588
  transformerIndex: this.index_
592
589
  },
@@ -596,23 +593,28 @@ class Pe extends L {
596
593
  current: this.reporterQos_.fps
597
594
  }
598
595
  };
599
- this.emit("warn", u);
596
+ this.emit("warn", n);
600
597
  }
601
598
  }
602
599
  }
603
- async flush(r) {
600
+ async flush(e) {
604
601
  if (this.transformer_ && typeof this.transformer_.flush == "function" && !this.isFlashed_) {
605
602
  this.isFlashed_ = !0;
606
603
  try {
607
- await this.transformer_.flush(r);
608
- } catch (s) {
604
+ await this.transformer_.flush(e);
605
+ } catch (r) {
609
606
  this.report({
610
607
  message: l.errors.transformer_flush,
611
608
  variation: "Error",
612
- error: v(s)
609
+ error: I(r)
613
610
  });
614
- const o = { eventMetaData: { transformerIndex: this.index_ }, error: s, function: "flush" };
615
- 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);
616
618
  }
617
619
  }
618
620
  this.reportQos(!0), this.report({
@@ -622,168 +624,227 @@ class Pe extends L {
622
624
  stop() {
623
625
  console.log("[Pipeline] Stop stream."), this.controller_ && (this.flush(this.controller_), this.controller_.terminate()), this.shouldStop_ = !0;
624
626
  }
625
- report(r) {
627
+ report(e) {
626
628
  this.reporter_.send({
627
- version: R,
629
+ version: E,
628
630
  action: "MediaTransformer",
629
631
  transformerType: this.transformerType_,
630
- ...r
632
+ ...e
631
633
  });
632
634
  }
633
- reportQos(r = !1) {
635
+ reportQos(e = !1) {
634
636
  this.reporterQos_.config = {
635
637
  ...this.reporterQos_.config
636
- }, this.reporterQos_.onFrameTransformed({
637
- version: R,
638
- action: "MediaTransformer",
639
- transformerType: this.transformerType_,
640
- videoWidth: this.videoWidth_,
641
- videoHeight: this.videoHeight_
642
- }, r);
643
- }
644
- }
645
- class Me extends L {
646
- constructor(r) {
647
- super();
648
- a(this, "transformers_");
649
- a(this, "trackExpectedRate_");
650
- this.transformers_ = [], this.trackExpectedRate_ = -1;
651
- for (let s = 0; s < r.length; s++) {
652
- let o = new Pe(r[s], s);
653
- 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) => {
654
656
  this.emit("error", i);
655
- }), o.on("warn", (i) => {
657
+ }), s.on("warn", (i) => {
656
658
  this.emit("warn", i);
657
- }), this.transformers_.push(o);
659
+ }), this.transformers_.push(s);
658
660
  }
659
661
  }
660
- setTrackExpectedRate(r) {
661
- this.trackExpectedRate_ = r;
662
- for (let s of this.transformers_)
663
- s.setTrackExpectedRate(this.trackExpectedRate_);
662
+ setTrackExpectedRate(e) {
663
+ this.trackExpectedRate_ = e;
664
+ for (let r of this.transformers_)
665
+ r.setTrackExpectedRate(this.trackExpectedRate_);
664
666
  }
665
- async start(r, s) {
667
+ async start(e, r) {
666
668
  if (!this.transformers_ || this.transformers_.length === 0) {
667
669
  console.log("[Pipeline] No transformers.");
668
670
  return;
669
671
  }
670
672
  try {
671
- let o = r;
673
+ let s = e;
672
674
  for (let i of this.transformers_)
673
- r = r.pipeThrough(new TransformStream(i));
674
- r.pipeTo(s).then(async () => {
675
- 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
+ );
676
684
  }).catch(async (i) => {
677
- r.cancel().then(() => {
678
- console.log("[Pipeline] Shutting down streams after abort.");
685
+ e.cancel().then(() => {
686
+ console.log(
687
+ "[Pipeline] Shutting down streams after abort."
688
+ );
679
689
  }).catch((n) => {
680
- console.error("[Pipeline] Error from stream transform:", n);
681
- }), 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
+ );
682
699
  });
683
700
  } catch {
684
- 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();
685
706
  return;
686
707
  }
687
- 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.");
688
713
  }
689
714
  async destroy() {
690
715
  console.log("[Pipeline] Destroying Pipeline.");
691
- for (let r of this.transformers_)
692
- r.stop();
716
+ for (let e of this.transformers_)
717
+ e.stop();
693
718
  }
694
719
  }
695
- class Oe extends L {
720
+ class Ce extends v {
696
721
  constructor() {
697
- super();
698
- a(this, "reporter_");
699
- a(this, "pipeline_");
700
- a(this, "transformers_");
701
- a(this, "readable_");
702
- a(this, "writable_");
703
- a(this, "trackExpectedRate_");
704
- this.reporter_ = new D(), this.trackExpectedRate_ = -1, this.report({
722
+ super(), this.reporter_ = new L(), this.trackExpectedRate_ = -1, this.report({
705
723
  variation: "Create"
706
724
  });
707
725
  }
708
- setTrackExpectedRate(r) {
709
- this.trackExpectedRate_ = r, this.pipeline_ && this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_);
710
- }
711
- transform(r, s) {
712
- return this.readable_ = r, this.writable_ = s, this.transformInternal();
713
- }
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
+ */
714
757
  transformInternal() {
715
- return new Promise(async (r, s) => {
758
+ return new Promise(async (e, r) => {
716
759
  if (!this.transformers_ || this.transformers_.length === 0) {
717
760
  this.report({
718
761
  message: l.errors.transformer_none,
719
762
  variation: "Error"
720
- }), s("[MediaProcessor] Need to set transformers.");
763
+ }), r("[MediaProcessor] Need to set transformers.");
721
764
  return;
722
765
  }
723
766
  if (!this.readable_) {
724
767
  this.report({
725
768
  variation: "Error",
726
769
  message: l.errors.readable_null
727
- }), s("[MediaProcessor] Readable is null.");
770
+ }), r("[MediaProcessor] Readable is null.");
728
771
  return;
729
772
  }
730
773
  if (!this.writable_) {
731
774
  this.report({
732
775
  variation: "Error",
733
776
  message: l.errors.writable_null
734
- }), s("[MediaProcessor] Writable is null.");
777
+ }), r("[MediaProcessor] Writable is null.");
735
778
  return;
736
779
  }
737
- let o = !1;
738
- 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) => {
739
782
  this.emit("warn", i);
740
783
  }), this.pipeline_.on("error", (i) => {
741
784
  this.emit("error", i);
742
785
  }), this.pipeline_.on("pipelineInfo", (i) => {
743
- 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);
744
787
  }), this.trackExpectedRate_ != -1 && this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_), this.pipeline_.start(this.readable_, this.writable_).then(() => {
745
- r();
788
+ e();
746
789
  }).catch((i) => {
747
- s(i);
790
+ r(i);
748
791
  });
749
792
  });
750
793
  }
751
- 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) {
752
803
  return this.report({
753
804
  variation: "Update",
754
805
  message: l.updates.transformer_new
755
- }), this.transformers_ = r, this.readable_ && this.writable_ ? this.transformInternal() : Promise.resolve();
806
+ }), this.transformers_ = e, this.readable_ && this.writable_ ? this.transformInternal() : Promise.resolve();
756
807
  }
808
+ /**
809
+ * Stops running the tranformation logic performed by the media processor instance.
810
+ * @returns
811
+ */
757
812
  destroy() {
758
- return new Promise(async (r) => {
759
- 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();
760
815
  });
761
816
  }
762
- report(r) {
817
+ report(e) {
763
818
  this.reporter_.send({
764
- version: R,
819
+ version: E,
765
820
  action: "MediaProcessor",
766
- ...r
821
+ ...e
767
822
  });
768
823
  }
769
824
  }
770
- class xe {
825
+ class Me {
771
826
  constructor() {
772
- a(this, "processor_");
773
- a(this, "generator_");
774
827
  this.processor_ = null, this.generator_ = null;
775
828
  }
776
829
  init(e) {
777
830
  return new Promise((r, s) => {
778
831
  try {
779
832
  this.processor_ = new MediaStreamTrackProcessor(e);
780
- } catch (o) {
781
- console.log(`[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${o}`), s(o);
833
+ } catch (i) {
834
+ console.log(
835
+ `[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${i}`
836
+ ), s(i);
782
837
  }
783
838
  try {
784
- e.kind === "audio" ? this.generator_ = new MediaStreamTrackGenerator({ kind: "audio" }) : e.kind === "video" ? this.generator_ = new MediaStreamTrackGenerator({ kind: "video" }) : s("kind not supported");
785
- } catch (o) {
786
- 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);
787
848
  }
788
849
  r();
789
850
  });
@@ -798,25 +859,45 @@ class xe {
798
859
  return this.generator_;
799
860
  }
800
861
  }
801
- 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
+ */
802
868
  constructor(e) {
803
- a(this, "insertableStreamHelper_");
804
- a(this, "mediaProcessor_");
805
- this.insertableStreamHelper_ = new xe(), this.mediaProcessor_ = e;
806
- }
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
+ */
807
879
  setTrack(e) {
808
880
  return new Promise((r, s) => {
809
881
  this.insertableStreamHelper_.init(e).then(() => {
810
- this.mediaProcessor_.transform(this.insertableStreamHelper_.getReadable(), this.insertableStreamHelper_.getWriteable()).then(() => {
811
- r(this.insertableStreamHelper_.getProccesorTrack());
812
- }).catch((o) => {
813
- 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);
814
891
  });
815
- }).catch((o) => {
816
- s(o);
892
+ }).catch((i) => {
893
+ s(i);
817
894
  });
818
895
  });
819
896
  }
897
+ /**
898
+ * @private
899
+ * Stops the media processing being performed.
900
+ */
820
901
  destroy() {
821
902
  return new Promise((e, r) => {
822
903
  this.mediaProcessor_ ? this.mediaProcessor_.destroy().then(() => {
@@ -828,13 +909,13 @@ class Fe {
828
909
  }
829
910
  }
830
911
  export {
831
- Re as ErrorFunction,
832
- Oe as MediaProcessor,
833
- Fe as MediaProcessorConnector,
834
- F as PipelineInfoData,
835
- ee as VonageSourceType,
912
+ Se as ErrorFunction,
913
+ Ce as MediaProcessor,
914
+ Oe as MediaProcessorConnector,
915
+ O as PipelineInfoData,
916
+ N as VonageSourceType,
836
917
  Ee as WarningType,
837
- C as getVonageMetadata,
838
- ve as isSupported,
839
- Ce as setVonageMetadata
918
+ x as getVonageMetadata,
919
+ Ie as isSupported,
920
+ xe as setVonageMetadata
840
921
  };