@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.
- package/dist/media-processor.es.js +446 -363
- package/dist/media-processor.min.js +1 -1
- package/dist/media-processor.static.js +446 -363
- package/dist/media-processor.umd.js +2 -2
- package/dist/types/lib/src/core/MediaProcessor.d.ts +14 -14
- package/dist/types/lib/src/core/MediaProcessorConnector.d.ts +3 -3
- package/dist/types/lib/src/core/pipeline.d.ts +1 -1
- package/dist/types/lib/src/telemetry/QosReporter.d.ts +1 -1
- package/package.json +12 -8
|
@@ -1,224 +1,227 @@
|
|
|
1
|
-
|
|
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(
|
|
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
|
-
|
|
10
|
+
l.updates = {
|
|
12
11
|
transformer_new: "New transformer",
|
|
13
12
|
transformer_null: "Null transformer"
|
|
14
|
-
}
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
31
|
+
function b(t) {
|
|
29
32
|
if (typeof t != "function")
|
|
30
33
|
throw new TypeError("listener must be a function");
|
|
31
34
|
}
|
|
32
|
-
function
|
|
33
|
-
const r =
|
|
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
|
|
37
|
-
const r = typeof e == "string" || typeof e == "symbol" ? e :
|
|
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
|
|
41
|
-
const s =
|
|
43
|
+
function B(t, e, r) {
|
|
44
|
+
const s = g.get(t);
|
|
42
45
|
if (s.has(e))
|
|
43
|
-
for (const
|
|
44
|
-
|
|
45
|
-
if (s.has(
|
|
46
|
-
const
|
|
47
|
-
for (const
|
|
48
|
-
|
|
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
|
|
54
|
+
function D(t, e) {
|
|
52
55
|
e = Array.isArray(e) ? e : [e];
|
|
53
56
|
let r = !1, s = () => {
|
|
54
|
-
},
|
|
55
|
-
const
|
|
56
|
-
enqueue(
|
|
57
|
-
|
|
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
|
|
64
|
-
|
|
66
|
+
for (const o of e)
|
|
67
|
+
_(t, o).add(n);
|
|
65
68
|
return {
|
|
66
69
|
async next() {
|
|
67
|
-
return
|
|
68
|
-
s =
|
|
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
|
|
74
|
+
value: await i.shift()
|
|
72
75
|
} : { done: !0 };
|
|
73
76
|
},
|
|
74
|
-
async return(
|
|
75
|
-
|
|
76
|
-
for (const
|
|
77
|
-
|
|
78
|
-
return s(), arguments.length > 0 ? { done: !0, value: await
|
|
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
|
|
88
|
+
function $(t) {
|
|
86
89
|
if (t === void 0)
|
|
87
|
-
return
|
|
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 (!
|
|
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
|
|
96
|
-
class
|
|
98
|
+
const M = (t) => t === S || t === R;
|
|
99
|
+
class d {
|
|
97
100
|
static mixin(e, r) {
|
|
98
|
-
return r =
|
|
101
|
+
return r = $(r), (s) => {
|
|
99
102
|
if (typeof s != "function")
|
|
100
103
|
throw new TypeError("`target` must be function");
|
|
101
|
-
for (const
|
|
102
|
-
if (s.prototype[
|
|
103
|
-
throw new Error(`The property \`${
|
|
104
|
-
function
|
|
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
|
|
110
|
+
value: new d()
|
|
108
111
|
}), this[e];
|
|
109
112
|
}
|
|
110
113
|
Object.defineProperty(s.prototype, e, {
|
|
111
114
|
enumerable: !1,
|
|
112
|
-
get:
|
|
115
|
+
get: i
|
|
113
116
|
});
|
|
114
|
-
const
|
|
115
|
-
return this[e][
|
|
117
|
+
const n = (o) => function(...a) {
|
|
118
|
+
return this[e][o](...a);
|
|
116
119
|
};
|
|
117
|
-
for (const
|
|
118
|
-
Object.defineProperty(s.prototype,
|
|
120
|
+
for (const o of r)
|
|
121
|
+
Object.defineProperty(s.prototype, o, {
|
|
119
122
|
enumerable: !1,
|
|
120
|
-
value:
|
|
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
|
|
130
|
+
return A;
|
|
128
131
|
const { env: e } = process || { env: {} };
|
|
129
|
-
return e.DEBUG === "emittery" || e.DEBUG === "*" ||
|
|
132
|
+
return e.DEBUG === "emittery" || e.DEBUG === "*" || A;
|
|
130
133
|
}
|
|
131
134
|
static set isDebugEnabled(e) {
|
|
132
|
-
|
|
135
|
+
A = e;
|
|
133
136
|
}
|
|
134
137
|
constructor(e = {}) {
|
|
135
|
-
|
|
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
|
-
|
|
140
|
+
n = JSON.stringify(n);
|
|
138
141
|
} catch {
|
|
139
|
-
|
|
142
|
+
n = `Object with the following keys failed to stringify: ${Object.keys(n).join(",")}`;
|
|
140
143
|
}
|
|
141
|
-
typeof
|
|
142
|
-
const
|
|
143
|
-
console.log(`[${
|
|
144
|
-
data: ${
|
|
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
|
-
(
|
|
151
|
+
(d.isDebugEnabled || this.debug.enabled) && this.debug.logger(e, this.debug.name, r, s);
|
|
149
152
|
}
|
|
150
153
|
on(e, r) {
|
|
151
|
-
|
|
154
|
+
b(r), e = Array.isArray(e) ? e : [e];
|
|
152
155
|
for (const s of e)
|
|
153
|
-
|
|
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
|
-
|
|
160
|
+
b(r), e = Array.isArray(e) ? e : [e];
|
|
158
161
|
for (const s of e)
|
|
159
|
-
|
|
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, (
|
|
164
|
-
s(), r(
|
|
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
|
-
|
|
172
|
-
return
|
|
174
|
+
p(r);
|
|
175
|
+
return D(this, e);
|
|
173
176
|
}
|
|
174
177
|
async emit(e, r) {
|
|
175
|
-
|
|
176
|
-
const s =
|
|
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
|
-
...
|
|
179
|
-
if (s.has(
|
|
180
|
-
return
|
|
181
|
+
...n.map(async (a) => {
|
|
182
|
+
if (s.has(a))
|
|
183
|
+
return a(r);
|
|
181
184
|
}),
|
|
182
|
-
...
|
|
183
|
-
if (
|
|
184
|
-
return
|
|
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
|
-
|
|
190
|
-
const s =
|
|
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
|
|
193
|
-
s.has(
|
|
194
|
-
for (const
|
|
195
|
-
|
|
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
|
|
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
|
|
204
|
+
return D(this);
|
|
202
205
|
}
|
|
203
206
|
offAny(e) {
|
|
204
|
-
|
|
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
|
-
|
|
211
|
-
const s =
|
|
212
|
-
for (const
|
|
213
|
-
|
|
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
|
-
|
|
217
|
-
for (const s of
|
|
219
|
+
f.get(this).clear();
|
|
220
|
+
for (const s of T.get(this).values())
|
|
218
221
|
s.clear();
|
|
219
|
-
for (const s of
|
|
220
|
-
for (const
|
|
221
|
-
|
|
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 +=
|
|
234
|
+
r += f.get(this).size + m(this, s).size + _(this, s).size + _(this).size;
|
|
232
235
|
continue;
|
|
233
236
|
}
|
|
234
|
-
typeof s < "u" &&
|
|
235
|
-
for (const
|
|
236
|
-
r +=
|
|
237
|
-
for (const
|
|
238
|
-
r +=
|
|
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 =
|
|
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
|
|
257
|
-
Object.defineProperty(
|
|
258
|
-
value:
|
|
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(
|
|
264
|
-
value:
|
|
266
|
+
Object.defineProperty(d, "listenerRemoved", {
|
|
267
|
+
value: R,
|
|
265
268
|
writable: !1,
|
|
266
269
|
enumerable: !0,
|
|
267
270
|
configurable: !1
|
|
268
271
|
});
|
|
269
|
-
var
|
|
270
|
-
|
|
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
|
|
274
|
-
if (
|
|
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
|
|
283
|
-
return
|
|
286
|
+
function I(t) {
|
|
287
|
+
return J(t).message;
|
|
284
288
|
}
|
|
285
|
-
var
|
|
286
|
-
const
|
|
287
|
-
let
|
|
288
|
-
const
|
|
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 (!
|
|
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
|
|
296
|
+
return w(se);
|
|
293
297
|
}
|
|
294
|
-
const
|
|
298
|
+
const c = [];
|
|
295
299
|
for (let t = 0; t < 256; ++t)
|
|
296
|
-
|
|
300
|
+
c.push((t + 256).toString(16).slice(1));
|
|
297
301
|
function ne(t, e = 0) {
|
|
298
|
-
return (
|
|
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
|
|
301
|
-
randomUUID:
|
|
304
|
+
const oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), H = {
|
|
305
|
+
randomUUID: oe
|
|
302
306
|
};
|
|
303
|
-
function
|
|
304
|
-
if (
|
|
305
|
-
return
|
|
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
|
|
311
|
-
e[r +
|
|
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
|
|
317
|
-
|
|
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
|
|
325
|
+
const h = F(
|
|
320
326
|
"globals",
|
|
321
327
|
{}
|
|
322
328
|
);
|
|
323
|
-
var
|
|
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((
|
|
331
|
+
return [ImageBitmap, ReadableStream, WritableStream].some((r) => t instanceof r);
|
|
326
332
|
}
|
|
327
|
-
let
|
|
328
|
-
function le(t, e, r, s,
|
|
329
|
-
const
|
|
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:
|
|
338
|
+
id: n,
|
|
333
339
|
type: e,
|
|
334
340
|
functionName: r,
|
|
335
341
|
args: s
|
|
336
342
|
},
|
|
337
|
-
s.filter((
|
|
338
|
-
), new Promise((
|
|
339
|
-
|
|
343
|
+
s.filter((a) => z(a))
|
|
344
|
+
), new Promise((a) => {
|
|
345
|
+
i == null || i.set(n, a);
|
|
340
346
|
});
|
|
341
347
|
}
|
|
342
|
-
function
|
|
343
|
-
const { id: r, type: s } = t,
|
|
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
|
-
|
|
356
|
+
i.filter((n) => z(n))
|
|
351
357
|
);
|
|
352
358
|
}
|
|
353
|
-
const
|
|
354
|
-
function
|
|
359
|
+
const Q = F("workerized", {});
|
|
360
|
+
function V() {
|
|
355
361
|
return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope;
|
|
356
362
|
}
|
|
357
|
-
async function
|
|
358
|
-
if (
|
|
359
|
-
|
|
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
|
|
363
|
-
const { worker: r, resolvers: s } =
|
|
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
|
-
|
|
373
|
+
u.GLOBALS_SYNC,
|
|
368
374
|
"",
|
|
369
|
-
[
|
|
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
|
|
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] = [],
|
|
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
|
-
|
|
400
|
+
y(t, await e.instance[r](...s ?? []));
|
|
395
401
|
}
|
|
396
|
-
const
|
|
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,
|
|
401
|
-
if (
|
|
402
|
-
e.instance = new
|
|
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
|
-
|
|
411
|
+
P(s, h), y(t, typeof e.instance !== void 0);
|
|
406
412
|
}
|
|
407
|
-
async function
|
|
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
|
|
418
|
+
e.instance.terminate && (s = await e.instance.terminate(...r ?? [])), y(t, s);
|
|
413
419
|
}
|
|
414
|
-
function
|
|
420
|
+
function me(t) {
|
|
415
421
|
if (!t.args)
|
|
416
422
|
throw "Missing globals while syncing";
|
|
417
|
-
|
|
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
|
|
430
|
+
case u.INIT:
|
|
425
431
|
de(r, t);
|
|
426
432
|
break;
|
|
427
|
-
case
|
|
433
|
+
case u.FORWARD:
|
|
428
434
|
he(r, t);
|
|
429
435
|
break;
|
|
430
|
-
case
|
|
431
|
-
|
|
436
|
+
case u.TERMINATE:
|
|
437
|
+
pe(r, t);
|
|
432
438
|
break;
|
|
433
|
-
case
|
|
434
|
-
|
|
439
|
+
case u.GLOBALS_SYNC:
|
|
440
|
+
me(r);
|
|
435
441
|
break;
|
|
436
442
|
}
|
|
437
443
|
};
|
|
438
444
|
}
|
|
439
|
-
|
|
440
|
-
function
|
|
441
|
-
return
|
|
442
|
-
() =>
|
|
445
|
+
V() && ge();
|
|
446
|
+
function _e(t, e) {
|
|
447
|
+
return h[t] || (h[t] = e), [
|
|
448
|
+
() => h[t],
|
|
443
449
|
async (r) => {
|
|
444
|
-
|
|
450
|
+
h[t] = r, await fe();
|
|
445
451
|
}
|
|
446
452
|
];
|
|
447
453
|
}
|
|
448
|
-
function
|
|
449
|
-
return
|
|
454
|
+
function ye(t, e) {
|
|
455
|
+
return _e(t, e);
|
|
450
456
|
}
|
|
451
|
-
const [
|
|
452
|
-
function
|
|
453
|
-
|
|
457
|
+
const [be, we] = ye("metadata");
|
|
458
|
+
function xe(t) {
|
|
459
|
+
we(t);
|
|
454
460
|
}
|
|
455
|
-
function
|
|
456
|
-
return
|
|
461
|
+
function x() {
|
|
462
|
+
return be();
|
|
457
463
|
}
|
|
458
|
-
class
|
|
459
|
-
constructor(e) {
|
|
460
|
-
|
|
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,
|
|
464
|
-
const { appId:
|
|
465
|
-
if (!
|
|
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
|
|
468
|
-
return await ((
|
|
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:
|
|
473
|
-
}), clearTimeout(
|
|
478
|
+
signal: a.signal
|
|
479
|
+
}), clearTimeout(k), "success";
|
|
474
480
|
}
|
|
475
481
|
getUrl() {
|
|
476
482
|
var e;
|
|
477
|
-
let r = (e =
|
|
478
|
-
return r += (r.at(-1) === "/" ? "" : "/") +
|
|
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 =
|
|
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
|
|
498
|
-
class
|
|
499
|
-
constructor(e) {
|
|
500
|
-
|
|
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,
|
|
511
|
-
return r /
|
|
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:
|
|
516
|
-
return r || this.frameTransformedCount >= this.config.loggingIntervalFrameCount ? (this.frameFromSourceCount = 0, this.frameTransformedCount = 0, this.startAt =
|
|
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:
|
|
520
|
-
transformedFps:
|
|
521
|
-
framesTransformed:
|
|
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 || {}),
|
|
527
|
-
const
|
|
528
|
-
class
|
|
529
|
-
constructor(
|
|
530
|
-
super()
|
|
531
|
-
|
|
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:
|
|
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(
|
|
553
|
-
this.trackExpectedRate_ =
|
|
541
|
+
setTrackExpectedRate(e) {
|
|
542
|
+
this.trackExpectedRate_ = e;
|
|
554
543
|
}
|
|
555
|
-
async start(
|
|
556
|
-
if (this.controller_ =
|
|
544
|
+
async start(e) {
|
|
545
|
+
if (this.controller_ = e, this.transformer_ && typeof this.transformer_.start == "function")
|
|
557
546
|
try {
|
|
558
|
-
await this.transformer_.start(
|
|
559
|
-
} catch (
|
|
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:
|
|
552
|
+
error: I(r)
|
|
564
553
|
});
|
|
565
|
-
const
|
|
566
|
-
|
|
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(
|
|
570
|
-
var
|
|
571
|
-
if (this.mediaTransformerQosReportStartTimestamp_ === 0 && (this.mediaTransformerQosReportStartTimestamp_ = Date.now()),
|
|
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"),
|
|
567
|
+
console.warn("[Pipeline] flush from transform"), e.close(), this.flush(r), r.terminate();
|
|
574
568
|
else {
|
|
575
569
|
try {
|
|
576
|
-
await ((
|
|
577
|
-
} catch (
|
|
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:
|
|
575
|
+
error: I(n)
|
|
582
576
|
});
|
|
583
|
-
const
|
|
584
|
-
|
|
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
|
|
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",
|
|
596
|
+
this.emit("warn", n);
|
|
598
597
|
}
|
|
599
598
|
}
|
|
600
599
|
}
|
|
601
|
-
async flush(
|
|
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(
|
|
606
|
-
} catch (
|
|
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:
|
|
609
|
+
error: I(r)
|
|
611
610
|
});
|
|
612
|
-
const
|
|
613
|
-
|
|
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(
|
|
627
|
+
report(e) {
|
|
624
628
|
this.reporter_.send({
|
|
625
|
-
version:
|
|
629
|
+
version: E,
|
|
626
630
|
action: "MediaTransformer",
|
|
627
631
|
transformerType: this.transformerType_,
|
|
628
|
-
...
|
|
632
|
+
...e
|
|
629
633
|
});
|
|
630
634
|
}
|
|
631
|
-
reportQos(
|
|
635
|
+
reportQos(e = !1) {
|
|
632
636
|
this.reporterQos_.config = {
|
|
633
637
|
...this.reporterQos_.config
|
|
634
|
-
}, this.reporterQos_.onFrameTransformed(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
this.transformers_ = [], this.trackExpectedRate_ = -1;
|
|
649
|
-
for (let
|
|
650
|
-
let
|
|
651
|
-
|
|
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
|
-
}),
|
|
657
|
+
}), s.on("warn", (i) => {
|
|
654
658
|
this.emit("warn", i);
|
|
655
|
-
}), this.transformers_.push(
|
|
659
|
+
}), this.transformers_.push(s);
|
|
656
660
|
}
|
|
657
661
|
}
|
|
658
|
-
setTrackExpectedRate(
|
|
659
|
-
this.trackExpectedRate_ =
|
|
660
|
-
for (let
|
|
661
|
-
|
|
662
|
+
setTrackExpectedRate(e) {
|
|
663
|
+
this.trackExpectedRate_ = e;
|
|
664
|
+
for (let r of this.transformers_)
|
|
665
|
+
r.setTrackExpectedRate(this.trackExpectedRate_);
|
|
662
666
|
}
|
|
663
|
-
async start(
|
|
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
|
|
673
|
+
let s = e;
|
|
670
674
|
for (let i of this.transformers_)
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
-
|
|
676
|
-
console.log(
|
|
685
|
+
e.cancel().then(() => {
|
|
686
|
+
console.log(
|
|
687
|
+
"[Pipeline] Shutting down streams after abort."
|
|
688
|
+
);
|
|
677
689
|
}).catch((n) => {
|
|
678
|
-
console.error(
|
|
679
|
-
|
|
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(
|
|
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(
|
|
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
|
|
690
|
-
|
|
716
|
+
for (let e of this.transformers_)
|
|
717
|
+
e.stop();
|
|
691
718
|
}
|
|
692
719
|
}
|
|
693
|
-
class
|
|
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
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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 (
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
777
|
+
}), r("[MediaProcessor] Writable is null.");
|
|
733
778
|
return;
|
|
734
779
|
}
|
|
735
|
-
let
|
|
736
|
-
this.pipeline_ && (
|
|
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
|
-
|
|
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
|
-
|
|
788
|
+
e();
|
|
744
789
|
}).catch((i) => {
|
|
745
|
-
|
|
790
|
+
r(i);
|
|
746
791
|
});
|
|
747
792
|
});
|
|
748
793
|
}
|
|
749
|
-
|
|
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_ =
|
|
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 (
|
|
757
|
-
this.pipeline_ && this.pipeline_.destroy(), this.report({ variation: "Delete" }),
|
|
813
|
+
return new Promise(async (e) => {
|
|
814
|
+
this.pipeline_ && this.pipeline_.destroy(), this.report({ variation: "Delete" }), e();
|
|
758
815
|
});
|
|
759
816
|
}
|
|
760
|
-
report(
|
|
817
|
+
report(e) {
|
|
761
818
|
this.reporter_.send({
|
|
762
|
-
version:
|
|
819
|
+
version: E,
|
|
763
820
|
action: "MediaProcessor",
|
|
764
|
-
...
|
|
821
|
+
...e
|
|
765
822
|
});
|
|
766
823
|
}
|
|
767
824
|
}
|
|
768
|
-
class
|
|
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 (
|
|
779
|
-
console.log(
|
|
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({
|
|
783
|
-
|
|
784
|
-
|
|
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
|
|
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
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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(
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
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((
|
|
814
|
-
s(
|
|
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
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
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
|
-
|
|
836
|
-
|
|
837
|
-
|
|
918
|
+
x as getVonageMetadata,
|
|
919
|
+
Ie as isSupported,
|
|
920
|
+
xe as setVonageMetadata
|
|
838
921
|
};
|