@byteplus/vepusher 2.0.2 → 2.0.3
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/index.es.js +146 -129
- package/dist/index.umd.js +6 -6
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -130,7 +130,7 @@ function rn() {
|
|
|
130
130
|
var sn = rn();
|
|
131
131
|
const te = /* @__PURE__ */ Ge(sn);
|
|
132
132
|
var S = /* @__PURE__ */ ((r) => (r.Camera = "camera", r.Screen = "screen", r.VideoFile = "videoFile", r.Microphone = "microphone", r.AudioFile = "audioFile", r.Image = "image", r.MixAudio = "mixAudio", r.MixVideo = "mixVideo", r.CustomVideo = "customVideo", r.CustomAudio = "customAudio", r))(S || {}), j = /* @__PURE__ */ ((r) => (r.DeviceCaptured = "deviceCaptured", r.DeviceStopCapture = "deviceStopCapture", r.Error = "error", r.Interrupted = "interrupted", r))(j || {}), w = /* @__PURE__ */ ((r) => (r.PushStart = "pushStart", r.PushStop = "pushStop", r.PushError = "pushError", r.RTCConnectStateChanged = "rtcConnectStateChanged", r.CaptureFirstVideoFrame = "capturefirstvideoframe", r.CaptureFirstAudioFrame = "capturefirstaudioframe", r.NotAllowedAutoPlay = "notallowedautoplay", r))(w || {}), Ri = /* @__PURE__ */ ((r) => (r["120p"] = "160x120x15x200", r["180p"] = "320x180x15x350", r["240p"] = "320x240x15x400", r["360p"] = "640x360x15x800", r["480p"] = "640x480x15x900", r["720p-1"] = "1280x720x15x1500", r["720p-2"] = "1280x720x25x1500", r["720p-3"] = "1280x720x30x1500", r["1080p-1"] = "1920x1080x15x2080", r["1080p-2"] = "1920x1080x25x3000", r["1080p-3"] = "1920x1080x30x3150", r))(Ri || {}), Ai = /* @__PURE__ */ ((r) => (r["120p"] = "120x160x15x200", r["180p"] = "180x320x15x350", r["240p"] = "240x320x15x400", r["360p"] = "360x640x15x800", r["480p"] = "480x640x15x900", r["720p-1"] = "720x1280x15x1500", r["720p-2"] = "720x1280x25x1500", r["720p-3"] = "720x1280x30x1500", r["1080p-1"] = "1080x1920x15x2080", r["1080p-2"] = "1080x1920x25x3000", r["1080p-3"] = "1080x1920x30x3150", r))(Ai || {}), wi = /* @__PURE__ */ ((r) => (r.STANDARD = "48000x40", r.HIGH = "48000x128", r))(wi || {}), ie = /* @__PURE__ */ ((r) => (r.VideoStreamChange = "videoStreamChange", r.AudioStreamChange = "audioStreamChange", r))(ie || {}), Oi = /* @__PURE__ */ ((r) => (r[r.init = -1] = "init", r[r.new = 0] = "new", r[r.connecting = 1] = "connecting", r[r.connected = 2] = "connected", r[r.disconnected = 3] = "disconnected", r[r.failed = 4] = "failed", r[r.closed = 5] = "closed", r))(Oi || {}), Nt = /* @__PURE__ */ ((r) => (r.SizeChange = "sizeChange", r))(Nt || {}), gt = /* @__PURE__ */ ((r) => (r.Portrait = "portrait", r.Landscape = "landscape", r))(gt || {});
|
|
133
|
-
const Ii = "720p-1",
|
|
133
|
+
const Ii = "720p-1", Di = "STANDARD";
|
|
134
134
|
var y = /* @__PURE__ */ ((r) => (r.TRACK_NOT_AVAILABLE = "track-not-available", r.UNEXPECTED_TYPE = "unexpected-type", r.PLAY_FAILED = "play-failed", r.CAPTURE_FAILED = "capture-failed", r.NOT_SUPPORTED = "not-supported", r.UNEXPECTED_ERROR = "unexpected-error", r))(y || {}), E = /* @__PURE__ */ ((r) => (r.AUDIO = "audio", r.VIDEO = "video", r))(E || {}), I = /* @__PURE__ */ ((r) => (r.ENDED = "ended", r.MUTE = "mute", r.UNMUTE = "unmute", r.PLAY_FAILED = "play-failed", r.SIZE_CHANGE = "size-change", r))(I || {});
|
|
135
135
|
const O = [];
|
|
136
136
|
for (let r = 0; r < 256; ++r)
|
|
@@ -159,7 +159,7 @@ function oe(r, e, t) {
|
|
|
159
159
|
throw new Error("Random bytes length must be >= 16");
|
|
160
160
|
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, nn(i);
|
|
161
161
|
}
|
|
162
|
-
class
|
|
162
|
+
class Mi {
|
|
163
163
|
constructor() {
|
|
164
164
|
m(this, "id", oe());
|
|
165
165
|
m(this, "_nextNode");
|
|
@@ -190,7 +190,7 @@ class Di {
|
|
|
190
190
|
(e = this._node) == null || e.disconnect(), delete this._node;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
class Pr extends
|
|
193
|
+
class Pr extends Mi {
|
|
194
194
|
constructor(t, i) {
|
|
195
195
|
super();
|
|
196
196
|
m(this, "previousNode");
|
|
@@ -207,7 +207,7 @@ class Pr extends Di {
|
|
|
207
207
|
this._g = t, this._node && (this._node.gain.value = t);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
class dn extends
|
|
210
|
+
class dn extends Mi {
|
|
211
211
|
constructor(t) {
|
|
212
212
|
super();
|
|
213
213
|
m(this, "previousNode", null);
|
|
@@ -921,13 +921,13 @@ class Bi extends qe {
|
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
923
|
}
|
|
924
|
-
class
|
|
924
|
+
class Dn extends qe {
|
|
925
925
|
constructor() {
|
|
926
926
|
super(...arguments);
|
|
927
927
|
m(this, "logger", new L("CustomAudioTrack"));
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
|
-
let
|
|
930
|
+
let Mn = 1;
|
|
931
931
|
const ct = new L("PromiseQueue");
|
|
932
932
|
class Ln {
|
|
933
933
|
constructor(e) {
|
|
@@ -936,7 +936,7 @@ class Ln {
|
|
|
936
936
|
m(this, "name", "");
|
|
937
937
|
m(this, "lockId");
|
|
938
938
|
m(this, "closeReason");
|
|
939
|
-
this.lockId =
|
|
939
|
+
this.lockId = Mn++, e && (this.name = e), ct.info(`lock-${this.name}-${this.lockId}`, "is created.");
|
|
940
940
|
}
|
|
941
941
|
get isLocked() {
|
|
942
942
|
return this.locks > 0;
|
|
@@ -1491,14 +1491,14 @@ function ro(r) {
|
|
|
1491
1491
|
y.UNEXPECTED_TYPE,
|
|
1492
1492
|
"error custom audio track type"
|
|
1493
1493
|
);
|
|
1494
|
-
return new
|
|
1494
|
+
return new Dn(r);
|
|
1495
1495
|
}
|
|
1496
|
-
const io = q.invoke(Xn, "enumerateInputDevices"), so = q.invoke(Jn, "createCameraTrack"), no = q.invoke(Qn, "createPictureTrack"),
|
|
1496
|
+
const io = q.invoke(Xn, "enumerateInputDevices"), so = q.invoke(Jn, "createCameraTrack"), no = q.invoke(Qn, "createPictureTrack"), Dr = q.invoke(Zn, "createMediaTracks"), oo = q.invoke(eo, "createMicrophoneTrack"), ao = q.invoke(Yn, "createScreenTracks"), co = q.invoke(Kn, "onDeviceChanged"), uo = q.invoke(to, "createCustomVideoTrack"), ho = q.invoke(ro, "createCustomAudioTrack");
|
|
1497
1497
|
var Tt = /* @__PURE__ */ ((r) => (r.PAUSING = "pausing", r))(Tt || {});
|
|
1498
1498
|
const po = {
|
|
1499
1499
|
sampleRate: 48e3,
|
|
1500
1500
|
keepAlive: !0
|
|
1501
|
-
},
|
|
1501
|
+
}, Mr = /* @__PURE__ */ new Map(), ye = new L("Mixer");
|
|
1502
1502
|
class lo extends Bt {
|
|
1503
1503
|
constructor(t) {
|
|
1504
1504
|
super();
|
|
@@ -1557,8 +1557,8 @@ class lo extends Bt {
|
|
|
1557
1557
|
}
|
|
1558
1558
|
function mo(r) {
|
|
1559
1559
|
const { sampleRate: e, keepAlive: t } = r;
|
|
1560
|
-
let i =
|
|
1561
|
-
return (!i || i.state === "closed") && (i = new AudioContext({ sampleRate: e }),
|
|
1560
|
+
let i = Mr.get(e);
|
|
1561
|
+
return (!i || i.state === "closed") && (i = new AudioContext({ sampleRate: e }), Mr.set(e, i)), t && (i.onstatechange = () => {
|
|
1562
1562
|
Et(i);
|
|
1563
1563
|
}), i;
|
|
1564
1564
|
}
|
|
@@ -1949,7 +1949,7 @@ registerProcessor('vumeter', class extends AudioWorkletProcessor {
|
|
|
1949
1949
|
`, Io = URL.createObjectURL(
|
|
1950
1950
|
new Blob([Oo], { type: "application/javascript" })
|
|
1951
1951
|
);
|
|
1952
|
-
class
|
|
1952
|
+
class Do {
|
|
1953
1953
|
constructor() {
|
|
1954
1954
|
this._audioCtx = null, this._volume = 0;
|
|
1955
1955
|
}
|
|
@@ -2020,7 +2020,7 @@ class qi extends te {
|
|
|
2020
2020
|
return this._trackMap.audio && e.addTrack(this._trackMap.audio), this._trackMap.video && e.addTrack(this._trackMap.video), this._mediaStream = e, e;
|
|
2021
2021
|
}
|
|
2022
2022
|
async startVolumeDetect() {
|
|
2023
|
-
this.audioTrack && (this._volumeDetector || (this._volumeDetector = new
|
|
2023
|
+
this.audioTrack && (this._volumeDetector || (this._volumeDetector = new Do()), await this._volumeDetector.start(
|
|
2024
2024
|
this.audioTrack,
|
|
2025
2025
|
Ke.instance.volumeDetectScriptUrl
|
|
2026
2026
|
));
|
|
@@ -2058,7 +2058,7 @@ class Je extends qi {
|
|
|
2058
2058
|
return !0;
|
|
2059
2059
|
}
|
|
2060
2060
|
}
|
|
2061
|
-
class
|
|
2061
|
+
class Mo extends _e {
|
|
2062
2062
|
constructor(e) {
|
|
2063
2063
|
super({
|
|
2064
2064
|
type: S.Camera,
|
|
@@ -2112,11 +2112,11 @@ function Ki(r, e) {
|
|
|
2112
2112
|
s[t] = e(r[t], t, r);
|
|
2113
2113
|
return s;
|
|
2114
2114
|
}
|
|
2115
|
-
var
|
|
2115
|
+
var M = Array.isArray, Vr = Q ? Q.prototype : void 0, Ur = Vr ? Vr.toString : void 0;
|
|
2116
2116
|
function Ji(r) {
|
|
2117
2117
|
if (typeof r == "string")
|
|
2118
2118
|
return r;
|
|
2119
|
-
if (
|
|
2119
|
+
if (M(r))
|
|
2120
2120
|
return Ki(r, Ji) + "";
|
|
2121
2121
|
if (Ye(r))
|
|
2122
2122
|
return Ur ? Ur.call(r) : "";
|
|
@@ -2258,9 +2258,9 @@ var es = Object.prototype, Aa = es.hasOwnProperty, wa = es.propertyIsEnumerable,
|
|
|
2258
2258
|
function Oa() {
|
|
2259
2259
|
return !1;
|
|
2260
2260
|
}
|
|
2261
|
-
var rs = typeof exports == "object" && exports && !exports.nodeType && exports, zr = rs && typeof module == "object" && module && !module.nodeType && module, Ia = zr && zr.exports === rs, Gr = Ia ? W.Buffer : void 0,
|
|
2261
|
+
var rs = typeof exports == "object" && exports && !exports.nodeType && exports, zr = rs && typeof module == "object" && module && !module.nodeType && module, Ia = zr && zr.exports === rs, Gr = Ia ? W.Buffer : void 0, Da = Gr ? Gr.isBuffer : void 0, kt = Da || Oa, Ma = "[object Arguments]", La = "[object Array]", Fa = "[object Boolean]", Na = "[object Date]", Va = "[object Error]", Ua = "[object Function]", $a = "[object Map]", Ba = "[object Number]", ja = "[object Object]", za = "[object RegExp]", Ga = "[object Set]", Ha = "[object String]", qa = "[object WeakMap]", Wa = "[object ArrayBuffer]", Xa = "[object DataView]", Ka = "[object Float32Array]", Ja = "[object Float64Array]", Ya = "[object Int8Array]", Za = "[object Int16Array]", Qa = "[object Int32Array]", ec = "[object Uint8Array]", tc = "[object Uint8ClampedArray]", rc = "[object Uint16Array]", ic = "[object Uint32Array]", k = {};
|
|
2262
2262
|
k[Ka] = k[Ja] = k[Ya] = k[Za] = k[Qa] = k[ec] = k[tc] = k[rc] = k[ic] = !0;
|
|
2263
|
-
k[
|
|
2263
|
+
k[Ma] = k[La] = k[Wa] = k[Fa] = k[Xa] = k[Na] = k[Va] = k[Ua] = k[$a] = k[Ba] = k[ja] = k[za] = k[Ga] = k[Ha] = k[qa] = !1;
|
|
2264
2264
|
function sc(r) {
|
|
2265
2265
|
return me(r) && Gt(r.length) && !!k[ge(r)];
|
|
2266
2266
|
}
|
|
@@ -2277,7 +2277,7 @@ var is = typeof exports == "object" && exports && !exports.nodeType && exports,
|
|
|
2277
2277
|
}
|
|
2278
2278
|
}(), qr = Hr && Hr.isTypedArray, ss = qr ? nc(qr) : sc, ac = Object.prototype, cc = ac.hasOwnProperty;
|
|
2279
2279
|
function dc(r, e) {
|
|
2280
|
-
var t =
|
|
2280
|
+
var t = M(r), i = !t && ts(r), s = !t && !i && kt(r), n = !t && !i && !s && ss(r), a = t || i || s || n, o = a ? xa(r.length, String) : [], u = o.length;
|
|
2281
2281
|
for (var d in r)
|
|
2282
2282
|
cc.call(r, d) && !(a && // Safari 9 has enumerable `arguments.length` in strict mode.
|
|
2283
2283
|
(d == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
|
|
@@ -2305,7 +2305,7 @@ function Ae(r) {
|
|
|
2305
2305
|
}
|
|
2306
2306
|
var fc = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, _c = /^\w*$/;
|
|
2307
2307
|
function qt(r, e) {
|
|
2308
|
-
if (
|
|
2308
|
+
if (M(r))
|
|
2309
2309
|
return !1;
|
|
2310
2310
|
var t = typeof r;
|
|
2311
2311
|
return t == "number" || t == "symbol" || t == "boolean" || r == null || Ye(r) ? !0 : _c.test(r) || !fc.test(r) || e != null && r in Object(e);
|
|
@@ -2370,10 +2370,10 @@ function Ic(r) {
|
|
|
2370
2370
|
var e = this.__data__, t = Ze(e, r);
|
|
2371
2371
|
return t < 0 ? void 0 : e[t][1];
|
|
2372
2372
|
}
|
|
2373
|
-
function
|
|
2373
|
+
function Dc(r) {
|
|
2374
2374
|
return Ze(this.__data__, r) > -1;
|
|
2375
2375
|
}
|
|
2376
|
-
function
|
|
2376
|
+
function Mc(r, e) {
|
|
2377
2377
|
var t = this.__data__, i = Ze(t, r);
|
|
2378
2378
|
return i < 0 ? (++this.size, t.push([r, e])) : t[i][1] = e, this;
|
|
2379
2379
|
}
|
|
@@ -2387,8 +2387,8 @@ function X(r) {
|
|
|
2387
2387
|
X.prototype.clear = Rc;
|
|
2388
2388
|
X.prototype.delete = Oc;
|
|
2389
2389
|
X.prototype.get = Ic;
|
|
2390
|
-
X.prototype.has =
|
|
2391
|
-
X.prototype.set =
|
|
2390
|
+
X.prototype.has = Dc;
|
|
2391
|
+
X.prototype.set = Mc;
|
|
2392
2392
|
var xe = ve(W, "Map");
|
|
2393
2393
|
function Lc() {
|
|
2394
2394
|
this.size = 0, this.__data__ = {
|
|
@@ -2462,7 +2462,7 @@ function Wc(r) {
|
|
|
2462
2462
|
return r == null ? "" : Ji(r);
|
|
2463
2463
|
}
|
|
2464
2464
|
function ns(r, e) {
|
|
2465
|
-
return
|
|
2465
|
+
return M(r) ? r : qt(r, e) ? [r] : qc(Wc(r));
|
|
2466
2466
|
}
|
|
2467
2467
|
function et(r) {
|
|
2468
2468
|
if (typeof r == "string" || Ye(r))
|
|
@@ -2535,7 +2535,7 @@ var id = Object.prototype, sd = id.propertyIsEnumerable, Wr = Object.getOwnPrope
|
|
|
2535
2535
|
} : rd;
|
|
2536
2536
|
function od(r, e, t) {
|
|
2537
2537
|
var i = e(r);
|
|
2538
|
-
return
|
|
2538
|
+
return M(r) ? i : Kc(i, t(r));
|
|
2539
2539
|
}
|
|
2540
2540
|
function Xr(r) {
|
|
2541
2541
|
return od(r, Ae, nd);
|
|
@@ -2627,14 +2627,14 @@ function Sd(r) {
|
|
|
2627
2627
|
t[++e] = i;
|
|
2628
2628
|
}), t;
|
|
2629
2629
|
}
|
|
2630
|
-
var Td = 1, Ed = 2, bd = "[object Boolean]", kd = "[object Date]", Pd = "[object Error]", xd = "[object Map]", Rd = "[object Number]", Ad = "[object RegExp]", wd = "[object Set]", Od = "[object String]", Id = "[object Symbol]",
|
|
2630
|
+
var Td = 1, Ed = 2, bd = "[object Boolean]", kd = "[object Date]", Pd = "[object Error]", xd = "[object Map]", Rd = "[object Number]", Ad = "[object RegExp]", wd = "[object Set]", Od = "[object String]", Id = "[object Symbol]", Dd = "[object ArrayBuffer]", Md = "[object DataView]", ti = Q ? Q.prototype : void 0, ht = ti ? ti.valueOf : void 0;
|
|
2631
2631
|
function Ld(r, e, t, i, s, n, a) {
|
|
2632
2632
|
switch (t) {
|
|
2633
|
-
case
|
|
2633
|
+
case Md:
|
|
2634
2634
|
if (r.byteLength != e.byteLength || r.byteOffset != e.byteOffset)
|
|
2635
2635
|
return !1;
|
|
2636
2636
|
r = r.buffer, e = e.buffer;
|
|
2637
|
-
case
|
|
2637
|
+
case Dd:
|
|
2638
2638
|
return !(r.byteLength != e.byteLength || !n(new ei(r), new ei(e)));
|
|
2639
2639
|
case bd:
|
|
2640
2640
|
case kd:
|
|
@@ -2695,11 +2695,11 @@ function Ud(r, e, t, i, s, n) {
|
|
|
2695
2695
|
}
|
|
2696
2696
|
return n.delete(r), n.delete(e), g;
|
|
2697
2697
|
}
|
|
2698
|
-
var $d = 1, ri = "[object Arguments]", ii = "[object Array]",
|
|
2698
|
+
var $d = 1, ri = "[object Arguments]", ii = "[object Array]", De = "[object Object]", Bd = Object.prototype, si = Bd.hasOwnProperty;
|
|
2699
2699
|
function jd(r, e, t, i, s, n) {
|
|
2700
|
-
var a =
|
|
2701
|
-
u = u == ri ?
|
|
2702
|
-
var c = u ==
|
|
2700
|
+
var a = M(r), o = M(e), u = a ? ii : J(r), d = o ? ii : J(e);
|
|
2701
|
+
u = u == ri ? De : u, d = d == ri ? De : d;
|
|
2702
|
+
var c = u == De, h = d == De, p = u == d;
|
|
2703
2703
|
if (p && kt(r)) {
|
|
2704
2704
|
if (!kt(e))
|
|
2705
2705
|
return !1;
|
|
@@ -2775,7 +2775,7 @@ function Kd(r, e, t) {
|
|
|
2775
2775
|
break;
|
|
2776
2776
|
r = r[a];
|
|
2777
2777
|
}
|
|
2778
|
-
return n || ++i != s ? n : (s = r == null ? 0 : r.length, !!s && Gt(s) && Zi(a, s) && (
|
|
2778
|
+
return n || ++i != s ? n : (s = r == null ? 0 : r.length, !!s && Gt(s) && Zi(a, s) && (M(r) || ts(r)));
|
|
2779
2779
|
}
|
|
2780
2780
|
function Jd(r, e) {
|
|
2781
2781
|
return r != null && Kd(r, e, Xd);
|
|
@@ -2801,7 +2801,7 @@ function ru(r) {
|
|
|
2801
2801
|
return qt(r) ? eu(et(r)) : tu(r);
|
|
2802
2802
|
}
|
|
2803
2803
|
function Kt(r) {
|
|
2804
|
-
return typeof r == "function" ? r : r == null ? sa : typeof r == "object" ?
|
|
2804
|
+
return typeof r == "function" ? r : r == null ? sa : typeof r == "object" ? M(r) ? Qd(r[0], r[1]) : Wd(r) : ru(r);
|
|
2805
2805
|
}
|
|
2806
2806
|
function iu(r) {
|
|
2807
2807
|
return function(e, t, i) {
|
|
@@ -2836,7 +2836,7 @@ function cu(r, e) {
|
|
|
2836
2836
|
}), t;
|
|
2837
2837
|
}
|
|
2838
2838
|
function hs(r, e) {
|
|
2839
|
-
var t =
|
|
2839
|
+
var t = M(r) ? as : cu;
|
|
2840
2840
|
return t(r, Kt(e));
|
|
2841
2841
|
}
|
|
2842
2842
|
function du(r) {
|
|
@@ -3084,7 +3084,7 @@ class Tu extends te {
|
|
|
3084
3084
|
const { width: e, height: t, frameRate: i } = fe(
|
|
3085
3085
|
Ii,
|
|
3086
3086
|
"video"
|
|
3087
|
-
), { sampleRate: s } = fe(
|
|
3087
|
+
), { sampleRate: s } = fe(Di, "audio");
|
|
3088
3088
|
this._videoConstraints = {
|
|
3089
3089
|
width: e,
|
|
3090
3090
|
height: t,
|
|
@@ -3194,7 +3194,7 @@ class Tu extends te {
|
|
|
3194
3194
|
const i = await so({
|
|
3195
3195
|
...t,
|
|
3196
3196
|
...this._videoConstraints
|
|
3197
|
-
}), s = new
|
|
3197
|
+
}), s = new Mo(i);
|
|
3198
3198
|
return this._cameraStreams[s.id] = s, this._notifyCaptured(s), this._bindStreamEvent(s), s.id;
|
|
3199
3199
|
} catch (i) {
|
|
3200
3200
|
throw this._handleError(i, V.OPEN_CAMERA_FAILED), i;
|
|
@@ -3227,7 +3227,7 @@ class Tu extends te {
|
|
|
3227
3227
|
}
|
|
3228
3228
|
async startVideoFileCapture(e) {
|
|
3229
3229
|
try {
|
|
3230
|
-
const t = await
|
|
3230
|
+
const t = await Dr({
|
|
3231
3231
|
url: e,
|
|
3232
3232
|
video: !0,
|
|
3233
3233
|
audio: !0,
|
|
@@ -3243,7 +3243,7 @@ class Tu extends te {
|
|
|
3243
3243
|
}
|
|
3244
3244
|
async startAudioFileCapture(e) {
|
|
3245
3245
|
try {
|
|
3246
|
-
const t = await
|
|
3246
|
+
const t = await Dr({
|
|
3247
3247
|
url: e,
|
|
3248
3248
|
video: !1,
|
|
3249
3249
|
audio: !0,
|
|
@@ -4029,7 +4029,7 @@ class ls {
|
|
|
4029
4029
|
}
|
|
4030
4030
|
}
|
|
4031
4031
|
const he = new ce("PreviewConsumer");
|
|
4032
|
-
class
|
|
4032
|
+
class Du extends ls {
|
|
4033
4033
|
constructor(e, {
|
|
4034
4034
|
streamConsumeController: t
|
|
4035
4035
|
}) {
|
|
@@ -4567,7 +4567,7 @@ function Yt() {
|
|
|
4567
4567
|
}), lt.exports;
|
|
4568
4568
|
}
|
|
4569
4569
|
var ci;
|
|
4570
|
-
function
|
|
4570
|
+
function Mu() {
|
|
4571
4571
|
return ci || (ci = 1, function(r) {
|
|
4572
4572
|
var e = function(o) {
|
|
4573
4573
|
return String(Number(o)) === o ? Number(o) : o;
|
|
@@ -4705,11 +4705,11 @@ var ui;
|
|
|
4705
4705
|
function Fu() {
|
|
4706
4706
|
if (ui) return $;
|
|
4707
4707
|
ui = 1;
|
|
4708
|
-
var r =
|
|
4708
|
+
var r = Mu(), e = Lu(), t = Yt();
|
|
4709
4709
|
return $.grammar = t, $.write = e, $.parse = r.parse, $.parseParams = r.parseParams, $.parseFmtpConfig = r.parseFmtpConfig, $.parsePayloads = r.parsePayloads, $.parseRemoteCandidates = r.parseRemoteCandidates, $.parseImageAttributes = r.parseImageAttributes, $.parseSimulcastStreamList = r.parseSimulcastStreamList, $;
|
|
4710
4710
|
}
|
|
4711
4711
|
var Nu = Fu();
|
|
4712
|
-
const
|
|
4712
|
+
const Me = /* @__PURE__ */ Ge(Nu);
|
|
4713
4713
|
function ms(r) {
|
|
4714
4714
|
return new Promise((e) => {
|
|
4715
4715
|
setTimeout(e, r);
|
|
@@ -4829,7 +4829,8 @@ async function Uu(r, e, t) {
|
|
|
4829
4829
|
}
|
|
4830
4830
|
const $u = (r) => {
|
|
4831
4831
|
var t;
|
|
4832
|
-
if (!Fi)
|
|
4832
|
+
if (!Fi)
|
|
4833
|
+
return;
|
|
4833
4834
|
const e = (t = r.rtp.filter((i) => i.codec === "opus")[0]) == null ? void 0 : t.payload;
|
|
4834
4835
|
e && r.fmtp.forEach((i) => {
|
|
4835
4836
|
i.payload === e && (i.config = "minptime=10;useinbandfec=1");
|
|
@@ -4841,8 +4842,24 @@ const $u = (r) => {
|
|
|
4841
4842
|
return !((t = e.uri) != null && t.includes("video-orientation"));
|
|
4842
4843
|
}
|
|
4843
4844
|
));
|
|
4844
|
-
}
|
|
4845
|
-
|
|
4845
|
+
};
|
|
4846
|
+
function ju(r, e) {
|
|
4847
|
+
r == null || r.rtp.forEach(({ codec: t, payload: i }) => {
|
|
4848
|
+
if (["vp8", "h264"].includes(t.toLocaleLowerCase())) {
|
|
4849
|
+
const s = r.fmtp.find((n) => n.payload === i);
|
|
4850
|
+
s ? s.config = [
|
|
4851
|
+
...s.config.split(";"),
|
|
4852
|
+
"x-google-min-bitrate=100",
|
|
4853
|
+
`x-google-start-bitrate=${e}`
|
|
4854
|
+
].join(";") : r.fmtp.push({
|
|
4855
|
+
payload: i,
|
|
4856
|
+
config: `x-google-min-bitrate=100;x-google-start-bitrate=${e}`
|
|
4857
|
+
});
|
|
4858
|
+
}
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
const D = new ce("PCConnect");
|
|
4862
|
+
class zu {
|
|
4846
4863
|
constructor(e, t, i) {
|
|
4847
4864
|
this._pc = null, this._ms = new MediaStream(), this._signalUrl = "", this._videoTransceiver = null, this._audioTransceiver = null, this._opts = void 0, this._sessionId = Date.now(), this._signalUrl = e, this._opts = t, this._onConnectStateChange = i;
|
|
4848
4865
|
}
|
|
@@ -4864,17 +4881,17 @@ class ju {
|
|
|
4864
4881
|
direction: "sendonly",
|
|
4865
4882
|
sendEncodings: [{ maxBitrate: t[0] }],
|
|
4866
4883
|
streams: [this._ms]
|
|
4867
|
-
}),
|
|
4884
|
+
}), D.log("add track to pc,", s), this._videoTransceiver = i.addTransceiver(n || "video", {
|
|
4868
4885
|
direction: "sendonly",
|
|
4869
4886
|
sendEncodings: [{ maxBitrate: t[1] }],
|
|
4870
4887
|
streams: [this._ms]
|
|
4871
|
-
}),
|
|
4888
|
+
}), D.log("add track to pc,", n);
|
|
4872
4889
|
const a = await i.createOffer();
|
|
4873
|
-
|
|
4874
|
-
const o =
|
|
4890
|
+
D.groupCollapsed("local offer"), D.log(a.sdp);
|
|
4891
|
+
const o = Me.parse(a.sdp);
|
|
4875
4892
|
o.media.forEach((c) => {
|
|
4876
|
-
c.type === "audio" ? $u(c) : c.type === "video" && Bu(c);
|
|
4877
|
-
}), a.sdp =
|
|
4893
|
+
c.type === "audio" ? $u(c) : c.type === "video" && (Bu(c), ju(c, t[1]));
|
|
4894
|
+
}), a.sdp = Me.write(o), D.log("local offer modified"), D.log(a.sdp), await i.setLocalDescription(a);
|
|
4878
4895
|
const u = await fs(
|
|
4879
4896
|
this._signalUrl,
|
|
4880
4897
|
{
|
|
@@ -4896,19 +4913,19 @@ class ju {
|
|
|
4896
4913
|
code: u.code,
|
|
4897
4914
|
message: u.message
|
|
4898
4915
|
};
|
|
4899
|
-
|
|
4900
|
-
const d =
|
|
4916
|
+
D.log("remote answer:"), D.log(u.remoteSdp.sdp);
|
|
4917
|
+
const d = Me.parse(u.remoteSdp.sdp);
|
|
4901
4918
|
d.media.forEach((c) => {
|
|
4902
4919
|
var h;
|
|
4903
4920
|
(h = c.fingerprint) != null && h.hash && (c.fingerprint.hash = c.fingerprint.hash.toUpperCase());
|
|
4904
|
-
}), u.remoteSdp.sdp =
|
|
4921
|
+
}), u.remoteSdp.sdp = Me.write(d), D.log("remote answer modified"), D.log(u.remoteSdp.sdp), D.groupEnd(), await i.setRemoteDescription(u.remoteSdp);
|
|
4905
4922
|
}
|
|
4906
4923
|
async updatePublish(e, t) {
|
|
4907
4924
|
var n, a;
|
|
4908
4925
|
let i;
|
|
4909
4926
|
t === "video" ? i = this._videoTransceiver : i = this._audioTransceiver;
|
|
4910
4927
|
const s = (n = i == null ? void 0 : i.sender) == null ? void 0 : n.track;
|
|
4911
|
-
(s == null ? void 0 : s.id) !== (e == null ? void 0 : e.id) && (await ((a = i == null ? void 0 : i.sender) == null ? void 0 : a.replaceTrack(e)),
|
|
4928
|
+
(s == null ? void 0 : s.id) !== (e == null ? void 0 : e.id) && (await ((a = i == null ? void 0 : i.sender) == null ? void 0 : a.replaceTrack(e)), D.log(
|
|
4912
4929
|
`replace ${t} track done! ${s == null ? void 0 : s.label} -> ${e == null ? void 0 : e.label}`
|
|
4913
4930
|
));
|
|
4914
4931
|
}
|
|
@@ -4917,14 +4934,14 @@ class ju {
|
|
|
4917
4934
|
const s = t === "video" ? (a = this._videoTransceiver) == null ? void 0 : a.sender : (o = this._audioTransceiver) == null ? void 0 : o.sender;
|
|
4918
4935
|
if (!s) return;
|
|
4919
4936
|
const n = s.getParameters();
|
|
4920
|
-
n.encodings = (u = n.encodings) != null && u.length ? n.encodings : [{}], i ? n.encodings[0].minBitrate = e : n.encodings[0].maxBitrate = e, s.setParameters(n),
|
|
4937
|
+
n.encodings = (u = n.encodings) != null && u.length ? n.encodings : [{}], i ? n.encodings[0].minBitrate = e : n.encodings[0].maxBitrate = e, s.setParameters(n), D.log(`set bitrate for ${t}, ${e} bps, min:${i}`);
|
|
4921
4938
|
}
|
|
4922
4939
|
unpublish() {
|
|
4923
4940
|
var e, t;
|
|
4924
4941
|
(e = this._pc) == null || e.getSenders().forEach((i) => {
|
|
4925
4942
|
var s;
|
|
4926
4943
|
(s = this._pc) == null || s.removeTrack(i);
|
|
4927
|
-
}), (t = this._pc) == null || t.close(), this._audioTransceiver = null, this._videoTransceiver = null, this._pc = null,
|
|
4944
|
+
}), (t = this._pc) == null || t.close(), this._audioTransceiver = null, this._videoTransceiver = null, this._pc = null, D.log("close pc!");
|
|
4928
4945
|
}
|
|
4929
4946
|
getStats() {
|
|
4930
4947
|
var e, t;
|
|
@@ -4944,12 +4961,12 @@ class ju {
|
|
|
4944
4961
|
_bindRTCEvent() {
|
|
4945
4962
|
const e = this._pc;
|
|
4946
4963
|
e == null || e.addEventListener("connectionstatechange", () => {
|
|
4947
|
-
|
|
4964
|
+
D.log("onconnectionstatechange:", e.connectionState), this._onConnectStateChange(e.connectionState);
|
|
4948
4965
|
});
|
|
4949
4966
|
}
|
|
4950
4967
|
}
|
|
4951
4968
|
var se = /* @__PURE__ */ ((r) => (r.OnError = "onerror", r.OnConnectClosed = "onconnectclosed", r.OnFirstFramePushed = "onfirstframepushed", r))(se || {}), Z = /* @__PURE__ */ ((r) => (r.Video = "video", r.Audio = "audio", r))(Z || {}), N = /* @__PURE__ */ ((r) => (r.Init = "init", r.AvExist = "avexist", r.VideoFrame = "videoframe", r.MockVideoEncode = "mockvideoencode", r.AudioFrame = "audioframe", r.AdjustBitrate = "adjustbitrate", r.Publish = "publish", r.UnPublish = "unpublish", r.Download = "download", r.GetStats = "getstats", r.EncodeConfig = "encodeconfig", r))(N || {}), re = /* @__PURE__ */ ((r) => (r.Ready = "ready", r.Error = "error", r.FirstFramePushed = "firstframepushed", r.Flvfile = "flvfile", r.STATS = "stats", r.Close = "close", r))(re || {}), ft = { exports: {} }, hi;
|
|
4952
|
-
function
|
|
4969
|
+
function Gu() {
|
|
4953
4970
|
return hi || (hi = 1, function(r) {
|
|
4954
4971
|
var e = Object.prototype.hasOwnProperty, t = "~";
|
|
4955
4972
|
function i() {
|
|
@@ -5055,10 +5072,10 @@ function zu() {
|
|
|
5055
5072
|
}, o.prototype.off = o.prototype.removeListener, o.prototype.addListener = o.prototype.on, o.prefixed = t, o.EventEmitter = o, r.exports = o;
|
|
5056
5073
|
}(ft)), ft.exports;
|
|
5057
5074
|
}
|
|
5058
|
-
var
|
|
5059
|
-
const
|
|
5075
|
+
var Hu = Gu();
|
|
5076
|
+
const qu = /* @__PURE__ */ Ge(Hu);
|
|
5060
5077
|
var wt = /* @__PURE__ */ ((r) => (r[r.RTMP_INIT_FAIL = 3e3] = "RTMP_INIT_FAIL", r[r.AUDIO_ENCODER_INIT_FAIL = 3001] = "AUDIO_ENCODER_INIT_FAIL", r[r.AUDIO_RRNOISE_INIT_FAIL = 3002] = "AUDIO_RRNOISE_INIT_FAIL", r[r.AUDIO_ENCODE_FAIL = 3003] = "AUDIO_ENCODE_FAIL", r[r.VIDEO_ENCODE_CONFIGURE_FAIL = 3004] = "VIDEO_ENCODE_CONFIGURE_FAIL", r[r.VIDEO_ENCODE_FAIL = 3005] = "VIDEO_ENCODE_FAIL", r[r.WTP_OPEN_FAIL = 3006] = "WTP_OPEN_FAIL", r[r.WTP_CONNECT_FAIL = 3007] = "WTP_CONNECT_FAIL", r[r.WORKER_ERROR = 3008] = "WORKER_ERROR", r))(wt || {});
|
|
5061
|
-
class
|
|
5078
|
+
class Wu extends Error {
|
|
5062
5079
|
constructor(e, t, i) {
|
|
5063
5080
|
super(), this.code = e, this.message = t, i && (this.ext = i), this.toJson = () => ({
|
|
5064
5081
|
code: this.code,
|
|
@@ -5068,7 +5085,7 @@ class qu extends Error {
|
|
|
5068
5085
|
}
|
|
5069
5086
|
}
|
|
5070
5087
|
function pi(r, e, t) {
|
|
5071
|
-
return new
|
|
5088
|
+
return new Wu(r, e, t);
|
|
5072
5089
|
}
|
|
5073
5090
|
const pe = class pe {
|
|
5074
5091
|
constructor(e) {
|
|
@@ -5101,7 +5118,7 @@ const pe = class pe {
|
|
|
5101
5118
|
pe.enable = !1, pe.enableLong = !1;
|
|
5102
5119
|
let ee = pe;
|
|
5103
5120
|
const F = new ee("RTMP_Capture");
|
|
5104
|
-
class
|
|
5121
|
+
class Xu {
|
|
5105
5122
|
constructor(e) {
|
|
5106
5123
|
this._videoFirstframeCaptured = !1, this._audioFirstframeCaptured = !1, this._videoProcessorReader = null, this._audioProcessorReader = null, this._bridge = e;
|
|
5107
5124
|
}
|
|
@@ -5200,8 +5217,8 @@ class Wu {
|
|
|
5200
5217
|
});
|
|
5201
5218
|
}
|
|
5202
5219
|
}
|
|
5203
|
-
const _s = '(function(){"use strict";var l=(i=>(i.OnVideoCaptured="onvideocaptured",i.OnAudioCaptured="onaudiocaptured",i.OnVideoCaptureNoOutput="onvideocapturenooutput",i.OnVideoEncoded="onvideoencoded",i.OnAudioEncoded="onaudioencoded",i.OnEncodedFrame="onencodedframe",i.OnPacketed="onpacketed",i.OnUpstreamFeedback="onupstreamfeedback",i.OnBitrateChanged="onbitratechanged",i))(l||{}),O=(i=>(i.OnError="onerror",i.OnConnectClosed="onconnectclosed",i.OnFirstFramePushed="onfirstframepushed",i))(O||{}),S=(i=>(i.Video="video",i.Audio="audio",i))(S||{}),v=(i=>(i.Init="init",i.AvExist="avexist",i.VideoFrame="videoframe",i.MockVideoEncode="mockvideoencode",i.AudioFrame="audioframe",i.AdjustBitrate="adjustbitrate",i.Publish="publish",i.UnPublish="unpublish",i.Download="download",i.GetStats="getstats",i.EncodeConfig="encodeconfig",i))(v||{}),y=(i=>(i.Ready="ready",i.Error="error",i.FirstFramePushed="firstframepushed",i.Flvfile="flvfile",i.STATS="stats",i.Close="close",i))(y||{});function $(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var k={exports:{}},T;function q(){return T||(T=1,function(i){var t=Object.prototype.hasOwnProperty,e="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(e=!1));function n(u,a,r){this.fn=u,this.context=a,this.once=r||!1}function o(u,a,r,h,m){if(typeof r!="function")throw new TypeError("The listener must be a function");var g=new n(r,h||u,m),f=e?e+a:a;return u._events[f]?u._events[f].fn?u._events[f]=[u._events[f],g]:u._events[f].push(g):(u._events[f]=g,u._eventsCount++),u}function _(u,a){--u._eventsCount===0?u._events=new s:delete u._events[a]}function c(){this._events=new s,this._eventsCount=0}c.prototype.eventNames=function(){var a=[],r,h;if(this._eventsCount===0)return a;for(h in r=this._events)t.call(r,h)&&a.push(e?h.slice(1):h);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(r)):a},c.prototype.listeners=function(a){var r=e?e+a:a,h=this._events[r];if(!h)return[];if(h.fn)return[h.fn];for(var m=0,g=h.length,f=new Array(g);m<g;m++)f[m]=h[m].fn;return f},c.prototype.listenerCount=function(a){var r=e?e+a:a,h=this._events[r];return h?h.fn?1:h.length:0},c.prototype.emit=function(a,r,h,m,g,f){var w=e?e+a:a;if(!this._events[w])return!1;var d=this._events[w],F=arguments.length,V,p;if(d.fn){switch(d.once&&this.removeListener(a,d.fn,void 0,!0),F){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,r),!0;case 3:return d.fn.call(d.context,r,h),!0;case 4:return d.fn.call(d.context,r,h,m),!0;case 5:return d.fn.call(d.context,r,h,m,g),!0;case 6:return d.fn.call(d.context,r,h,m,g,f),!0}for(p=1,V=new Array(F-1);p<F;p++)V[p-1]=arguments[p];d.fn.apply(d.context,V)}else{var fe=d.length,R;for(p=0;p<fe;p++)switch(d[p].once&&this.removeListener(a,d[p].fn,void 0,!0),F){case 1:d[p].fn.call(d[p].context);break;case 2:d[p].fn.call(d[p].context,r);break;case 3:d[p].fn.call(d[p].context,r,h);break;case 4:d[p].fn.call(d[p].context,r,h,m);break;default:if(!V)for(R=1,V=new Array(F-1);R<F;R++)V[R-1]=arguments[R];d[p].fn.apply(d[p].context,V)}}return!0},c.prototype.on=function(a,r,h){return o(this,a,r,h,!1)},c.prototype.once=function(a,r,h){return o(this,a,r,h,!0)},c.prototype.removeListener=function(a,r,h,m){var g=e?e+a:a;if(!this._events[g])return this;if(!r)return _(this,g),this;var f=this._events[g];if(f.fn)f.fn===r&&(!m||f.once)&&(!h||f.context===h)&&_(this,g);else{for(var w=0,d=[],F=f.length;w<F;w++)(f[w].fn!==r||m&&!f[w].once||h&&f[w].context!==h)&&d.push(f[w]);d.length?this._events[g]=d.length===1?d[0]:d:_(this,g)}return this},c.prototype.removeAllListeners=function(a){var r;return a?(r=e?e+a:a,this._events[r]&&_(this,r)):(this._events=new s,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=e,c.EventEmitter=c,i.exports=c}(k)),k.exports}var z=q(),j=$(z);const N=class N{constructor(t){this.group=(...e)=>{this._enabled&&console.group(`[${this._prefix}]: `,...e)},this.groupCollapsed=(...e)=>{this._enabled&&console.groupCollapsed(`[${this._prefix}]: `,...e)},this.groupEnd=()=>{this._enabled&&console.groupEnd()},this.log=(...e)=>{this._enabled&&console.log(`[${this._prefix}]: `,...e)},this.warn=(...e)=>{this._enabled&&console.warn(`[${this._prefix}]: `,...e)},this.error=(...e)=>{this._enabled&&console.error(`[${this._prefix}]: `,...e)},this.table=(...e)=>{this._enabled&&console.table(...e)},this._prefix=t}get _enabled(){return N.enable}get _enableLong(){return N.enableLong}get long(){return this._enableLong}};N.enable=!1,N.enableLong=!1;let E=N;function D(i){i=i.filter(Boolean);const t=new Uint8Array(i.reduce((s,n)=>s+n.byteLength,0));let e=0;return i.forEach(s=>{t.set(s,e),e+=s.byteLength}),t}const A={codec:"avc1.4DE033",MaxCachedFrameSize:100,RealSpeedPercent:.8,UplinkBitrateCheckInterval:60*1e3,VideoBitrateDefault:1e6,AudioBitrateDefault:68e3,gopSize:90,sampleRate:48e3,channel:2,audioEncoderPath:"https://lf-unpkg.volccdn.com/obj/vcloudfe/sdk/Web_push/1.0.1/1735619140327/pcm2aac.js",audioEncoderWasmPath:"https://lf-unpkg.volccdn.com/obj/vcloudfe/sdk/Web_push/1.0.2/1735619208418/pcm2aac.wasm",rrnoiseAssetsPath:"https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/encoder/0.1.0",ignoreRelPublish:!1},U=new E("RTMP_AudioEncoder");class H{constructor(t){this._encodedFrameCount=0,this._ready=!1,this._lastFrame=null,this._aacOutput=(e,s)=>{const n=this._module.HEAPU8.subarray(e,e+s);if(!this._lastFrame)return;this._encodedFrameCount++;const{props:o}=this._lastFrame,_={buffer:new Uint8Array(n),props:{timestamp:parseInt(o.timestamp/1e3),originTs:parseInt(o.timestamp/1e3)}};this._core.emit(l.OnAudioEncoded,_)},this._core=t}async init(){const t=await fetch(A.audioEncoderPath).then(_=>_.text());new Function(`self.exports={};${t}`)();const e=self.exports.m;let s,n;const o=new Promise((_,c)=>{n=_,s=c});return e({instantiateWasm:function(_,c){fetch(A.audioEncoderWasmPath).then(u=>u.arrayBuffer()).then(u=>WebAssembly.instantiate(u,_)).then(function(u){return c(u.instance)}).then(()=>{n(),U.log("aac module inited")}).catch(u=>{s(u)})}}).then(_=>{const c=_.addFunction(this._aacOutput,"vii");_._init_callback(c),this._module=_}).catch(s),o}rnnoise(t){var s;const e=t.length;for(let n=0;n<e;n++)t[n]=t[n]*32768;(s=this._rnnoiseModule)==null||s.processFrame(t);for(let n=0;n<e;n++)t[n]=t[n]/32768}updateConfigure(){this._module._flush(),this._module._free_encoder(),this._ready=!1}encode(t){if(!this._ready){const o=this._start_encoder();if(o<0)throw new Error(`init aac encoder error, code:${o}`)}this._lastFrame=t;const e=t.buffer.buffer,s=this._module._malloc(e.byteLength);this._module.HEAPU8.subarray(s,s+e.byteLength).set(new Uint8Array(e));const n=this._module._encode_one_frame(s);if(n<0)throw new Error(`encode aac frame error, code:${n}`)}_start_encoder(){const t=this._core.getSetting(),e=this._module._init_encoder(t.sampleRate,t.channel,t.audioBitrate);if(e<0)return e;this._ready=!0,U.log(`init encoder: sampleRate=${t.sampleRate}, channel:${t.channel}, bitrate:${t.audioBitrate}`)}destroy(){var t;(t=this._module)==null||t._free_encoder()}}const P=1024;class M{constructor(){this._queue=[],this._sampleCount=0}compose(t){if(this._queue.push(t),this._sampleCount+=t.data.audioData.numberOfFrames,this._sampleCount>=P)return this._doCompose()}_doCompose(){const t=new Float32Array(P);let e=0,s=P;const n=this._queue[0];for(;;){const o=this._queue[0];if(!o)break;const _=Math.min(s,o.data.audioData.numberOfFrames-o.offset,480),c=o.data.buffer.slice(o.offset,o.offset+_);if(o.offset+=_,o.offset>=o.data.audioData.numberOfFrames&&this._queue.shift(),s-=_,this._sampleCount-=_,t.set(c,e),e+=_,s<=0)break}return{buffer:t,props:{timestamp:n.data.audioData.timestamp,sampleRate:n.data.audioData.sampleRate,numberOfChannels:n.data.audioData.numberOfChannels}}}}var C=(i=>(i[i.RTMP_INIT_FAIL=3e3]="RTMP_INIT_FAIL",i[i.AUDIO_ENCODER_INIT_FAIL=3001]="AUDIO_ENCODER_INIT_FAIL",i[i.AUDIO_RRNOISE_INIT_FAIL=3002]="AUDIO_RRNOISE_INIT_FAIL",i[i.AUDIO_ENCODE_FAIL=3003]="AUDIO_ENCODE_FAIL",i[i.VIDEO_ENCODE_CONFIGURE_FAIL=3004]="VIDEO_ENCODE_CONFIGURE_FAIL",i[i.VIDEO_ENCODE_FAIL=3005]="VIDEO_ENCODE_FAIL",i[i.WTP_OPEN_FAIL=3006]="WTP_OPEN_FAIL",i[i.WTP_CONNECT_FAIL=3007]="WTP_CONNECT_FAIL",i[i.WORKER_ERROR=3008]="WORKER_ERROR",i))(C||{});class W extends Error{constructor(t,e,s){super(),this.code=t,this.message=e,s&&(this.ext=s),this.toJson=()=>({code:this.code,message:this.message,ext:this.ext})}}function x(i,t,e){return new W(i,t,e)}class G{constructor(t){this._audioFrameQueue=new M,this.encode=e=>{const s=new Float32Array(e.numberOfFrames);e.copyTo(s,{planeIndex:0,frameOffset:0,frameCount:e.numberOfFrames});const n=this._audioFrameQueue.compose({offset:0,data:{audioData:e,buffer:s}});if(n)try{this._encoder.encode(n)}catch(o){this._core.emit(O.OnError,x(C.AUDIO_ENCODE_FAIL,o.message))}},this._core=t,this._encoder=new H(t)}async init(){try{await this._encoder.init()}catch(t){throw x(C.AUDIO_ENCODER_INIT_FAIL,t.message)}}setConfiguration(t){const e=Object.assign({},this._core.getSetting(),{audioBitrate:t});this._core.updateSetting(e),this._encoder.updateConfigure()}destroy(){this._encoder.destroy()}}const B=new E("RTMP_VEncoder");class J{constructor(t){this._encoder=null,this._queue=[],this._encodeTimer=0,this._loopEncodeTimer=0,this._frameIndex=0,this._gopSize=0,this._encodedFrameCount=0,this._lastFrame=null,this._startTimer=()=>{this._clearEncodeTimer(),this._encodeTimer=setInterval(()=>{const e=this._queue.shift();if(!(!e||!this._encoder||this._encoder.state==="closed"))try{this._encoder.encode(e,{keyFrame:this._frameIndex%this._gopSize===0}),this._frameIndex++,this._lastFrame&&this._lastFrame.close(),this._lastFrame=e}catch(s){B.log("encode frame error",s)}},5)},this._core=t}configurate(t){return this._gopSize=t.gopSize,this._encoder?this.flush().then(()=>this._configure(t)):this._configure(t)}_configure(t){return this._clearEncodeTimer(),B.log("start config encoder",t),VideoEncoder.isConfigSupported(t).then(e=>{if(!e.supported)throw new Error(`VideoEncoder not support config, ${JSON.stringify(t)}`);this._encoder=new VideoEncoder({output:(s,n)=>{const o=new Uint8Array(s.byteLength);s.copyTo(o),this._emitFrame(o,s,n)},error:s=>{this._clearEncodeTimer(),this._core.emit(O.OnError,x(C.VIDEO_ENCODE_FAIL,s.message))}}),this._encoder.configure(t),B.log("encoder configured")}).then(this._startTimer).catch(e=>{throw x(C.VIDEO_ENCODE_CONFIGURE_FAIL,e.message)})}_emitFrame(t,e,s){this._encodedFrameCount++,this._core.emit(l.OnVideoEncoded,{buffer:t,props:{byteLength:e.byteLength,duration:e.duration,timestamp:parseInt(e.timestamp/1e3),originTs:parseInt(e.timestamp/1e3),type:e.type},cfg:s.decoderConfig})}_clearEncodeTimer(){clearInterval(this._encodeTimer)}_clearLoopEncodeTimer(){this._loopEncodeTimer&&clearInterval(this._loopEncodeTimer)}flush(){return this._encoder?this._encoder.flush().then(()=>{var t;this._clearEncodeTimer(),(t=this._encoder)==null||t.close(),this._frameIndex=0,this._encoder=null,B.log("encoder flush & closed")}).catch(t=>{console.log("encoder flush & close error:",t)}):Promise.resolve()}encode(t){this._clearLoopEncodeTimer(),this._queue.push(t)}startLoop(t){if(!this._lastFrame)return;const e=Math.floor(1e3/t*1e3);B.log("start encode last frame looped, ",t,"increment:",e),this._loopEncodeTimer=setInterval(()=>{if(!this._lastFrame)return;const s=new VideoFrame(this._lastFrame,{duration:e,timestamp:(this._lastFrame.timestamp||0)+e});this._queue.push(s)},Math.floor(1e3/t))}destroy(){this._queue.forEach(t=>t.close()),this._lastFrame&&this._lastFrame.close(),this._clearEncodeTimer(),this._clearLoopEncodeTimer(),this.flush()}}const Q=new E("RTMP_VideoEncode");class K{constructor(t){this._core=t,this._encoder=new J(t)}async setConfiguration(t={}){const e=Object.assign({},this._core.getSetting(),t),s={width:e.width,height:e.height,displayWidth:e.width,displayHeight:e.height,bitrate:e.videoBitrate,framerate:Math.floor(e.frameRate),codec:e.codec,gopSize:e.gopSize,hardwareAcceleration:e.hardwareAcceleration};this._core.updateSetting(e),Q.log("set Configuration:",s,t);try{await this._encoder.configurate(s)}catch(n){this._core.emit(O.OnError,n)}}encode(t){this._encoder.encode(t)}startLoopEncodeLastFrame(){this._encoder.startLoop(this._core.getSetting().frameRate)}flushEncoder(){this._encoder.flush()}destroy(){this._encoder.destroy()}}const I=new E("RTMP_AVSync");class Z{constructor(t){this._videoFrameGot=!1,this._videoBaseDts=0,this._audioBaseDts=0,this._videoNextDts=0,this._videoLastDts=0,this._audioNextDts=0,this._lastVideoReceived=0,this._core=t}get avExist(){return this._core.getSetting().hasVideo&&this._core.getSetting().hasAudio}get videoRefDuration(){return parseInt(1e3/this._core.getSetting().frameRate)}get audioRefDuration(){return parseInt(1024/this._core.getSetting().sampleRate*1e3)}addVideoFrame(t){this._videoFrameGot||(this._videoFrameGot=!0);const e=t.props;if(Math.abs(this._videoNextDts-e.timestamp-this._videoBaseDts)>1e3){const n=Date.now()-this._lastVideoReceived;this._videoNextDts=this._videoNextDts===this._audioNextDts?this._videoNextDts+this.videoRefDuration:this._audioNextDts||this._videoNextDts+n,this._videoBaseDts=this._videoNextDts-e.timestamp,I.warn(`video stream timestamp breaked! dts:${this._videoNextDts} -> ${e.timestamp}, videoBaseDts=${this._videoBaseDts}, deltaToLastFrame=${n}`)}e.timestamp=e.timestamp+this._videoBaseDts;const s=e.timestamp-this._videoLastDts;return s>100&&I.warn("video frame large gap",s),this._videoLastDts=this._videoNextDts=e.timestamp,I.long&&I.log(`V frame, dts: ${e.timestamp}, originDts:${e.originTs}, videoBaseDts=${this._videoBaseDts}, type=${e.type}, duration=${s}`),this._lastVideoReceived=Date.now(),this._core.emit(l.OnEncodedFrame,S.Video,t),{size:t.buffer.length,duration:s,key:t.props.type==="key"}}addAudioFrame(t){if(this.avExist&&!this._videoFrameGot)return;const e=t.props;return this._audioBaseDts||(this._audioBaseDts=e.timestamp-this._videoNextDts),Math.abs(e.timestamp-this._audioBaseDts-this._audioNextDts)>1e3&&(this._audioBaseDts=this._audioNextDts+this.audioRefDuration-e.timestamp,I.warn(`audio stream timestamp breaked! dts:${this._audioNextDts} -> ${e.timestamp}, audioBaseDts=${this._audioBaseDts}`)),this._audioNextDts=e.timestamp=e.timestamp-this._audioBaseDts,I.long&&I.log(`A frame, dts: ${e.timestamp}, originDts:${e.originTs}`),this._core.emit(l.OnEncodedFrame,S.Audio,t),{size:t.buffer.length,duration:this.audioRefDuration}}}class X{constructor(){this._videoSize=0,this._videoDuration=0,this._videoBitrate=0,this._frameCount=0,this._fps=0,this._videoEncodedCount=0,this._keyCount=0,this._audioSize=0,this._audioDuration=0,this._audioBitrate=0,this._audioEncodedCount=0}get videoStats(){return{sendBitrate:this._videoBitrate,framesPerSecond:this._fps,framesEncoded:this._videoEncodedCount,keyFramesEncoded:this._keyCount}}get audioStats(){return{sendBitrate:this._audioBitrate,framesEncoded:this._audioEncodedCount}}addVideoSample({size:t,duration:e,key:s}){this._videoEncodedCount++,this._videoSize+=t,this._videoDuration+=e,this._frameCount++,s&&this._keyCount++,this._videoDuration>=1e3&&(this._videoBitrate=Math.floor(this._videoSize/this._videoDuration*8e3),this._fps=this._frameCount,this._frameCount=0,this._videoSize=0,this._videoDuration=0)}addAudioSample({size:t,duration:e}){this._audioEncodedCount++,this._audioSize+=t,this._audioDuration+=e,this._audioDuration>=1e3&&(this._audioBitrate=Math.floor(this._audioSize/this._audioDuration*1e3),this._audioSize=0,this._audioDuration=0)}}const Y=new E("RTMP_EncodeController");class ee{constructor(t){this._analyse=new X,this._gotFrame=!1,this._OnVideoCaptured=(e,s)=>{this._gotFrame=!0,this._videoSettingChanged(s)&&(Y.log("video track setting changed!",s),this._core.updateSetting({width:s.width,height:s.height,frameRate:s.frameRate,vDeviceId:s.deviceId}),this._videoEncode.setConfiguration()),this._videoEncode.encode(e)},this._OnVideoCaptureNoOutput=()=>{this._videoEncode.startLoopEncodeLastFrame()},this._OnAudioCaptured=e=>{this._gotFrame=!0,this._audioEncode.encode(e)},this._OnVideoEncoded=e=>{const s=this._avSync.addVideoFrame(e);this._analyse.addVideoSample(s)},this._OnAudioEncoded=e=>{if(!e.buffer.length)return;const s=this._avSync.addAudioFrame(e);s&&this._analyse.addAudioSample(s)},this._OnUpstreamFeedback=e=>{this._videoEncode.setConfiguration(e)},this._OnBitrateChanged=(e,s)=>{this._gotFrame&&(e===S.Video&&this._videoEncode.setConfiguration({videoBitrate:s}),e===S.Audio&&this._audioEncode.setConfiguration(s))},this._core=t,this._audioEncode=new G(t),this._videoEncode=new K(t),this._avSync=new Z(t),this._bindEvents()}getStats(){return{video:this._analyse.videoStats,audio:this._analyse.audioStats}}init(){return this._audioEncode.init()}_bindEvents(){this._core.on(l.OnVideoCaptured,this._OnVideoCaptured),this._core.on(l.OnAudioCaptured,this._OnAudioCaptured),this._core.on(l.OnVideoCaptureNoOutput,this._OnVideoCaptureNoOutput),this._core.on(l.OnVideoEncoded,this._OnVideoEncoded),this._core.on(l.OnAudioEncoded,this._OnAudioEncoded),this._core.on(l.OnUpstreamFeedback,this._OnUpstreamFeedback),this._core.on(l.OnBitrateChanged,this._OnBitrateChanged)}_videoSettingChanged(t){const e=this._core.getSetting();return t.width!==e.width||t.height!==e.height||Math.floor(t.frameRate)!==Math.floor(e.frameRate)||t.deviceId!==e.vDeviceId}destroy(){this._videoEncode.destroy(),this._audioEncode.destroy()}}var L=(i=>(i[i.AUDIO=8]="AUDIO",i[i.VIDEO=9]="VIDEO",i[i.SCRIPT_DATA=18]="SCRIPT_DATA",i))(L||{});const te=10,ie=1,se=7,oe={96e3:0,48e3:3,44100:4,22050:7,16e3:8,8e3:11};function ne(i){const t=(i[4]&3)+1;let e;const s=[],n=[];let o=6;const _=i[5]&31;let c;for(let r=0;r<_;r++){if(c=i[o]<<8|i[o+1],o+=2,!c)continue;const h=i.subarray(o,o+c);o+=c,s.push(h)}const u=i[o];o++;let a;for(let r=0;r<u;r++)a=i[o]<<8|i[o+1],o+=2,a&&(n.push(i.subarray(o,o+a)),o+=a);return{sps:e,spsArr:s,ppsArr:n,nalUnitSize:t}}class re{constructor(){this._cfg={hasVideo:!1,hasAudio:!1,sampleRate:48e3,channelCount:1},this._hasAudioSeqHeader=!1,this._hasVideoSeqHeader=!1}setConfig(t){this._cfg=Object.assign(this._cfg,t)}genHeader(){const t=[70,76,86,1,(this._cfg.hasAudio?1:0)<<2|(this._cfg.hasVideo?1:0),0,0,0,9,0,0,0,0];return new Uint8Array(t)}genSeqTag(t,e){let s;t===8?(s=this._genAudioTagPaylod(0,e),this._hasAudioSeqHeader=!0):(s=this._genVideoTagPayload(0,e),this._hasVideoSeqHeader=!0);const n=this._genTagHeader(t,s.length,e.props.timestamp),o=n.length+s.length;return D([n,s,new Uint8Array([o>>>24,o>>>16,o>>>8,o])])}genFrameTag(t,e){let s;t===8?s=this._genAudioTagPaylod(1,e):s=this._genVideoTagPayload(1,e);const n=this._genTagHeader(t,s.length,e.props.timestamp),o=n.length+s.length;return D([n,s,new Uint8Array([o>>>24,o>>>16,o>>>8,o])])}_genTagHeader(t,e,s){return new Uint8Array([t,e>>>16,e>>>8,e,s>>>16,s>>>8,s,s>>>24,0,0,0])}_genAudioTagPaylod(t,e){return D(t===0?[this._genAudioTagHeader(),this._genAudioSequenceHeader()]:[this._genAudioTagHeader(),this._genAudioData(e)])}_genAudioTagHeader(){return new Uint8Array([te<<4|12|ie<<1|this._cfg.channelCount-1])}_genAudioSequenceHeader(){const t=4096|oe[this._cfg.sampleRate]<<7|this._cfg.channelCount<<3;return new Uint8Array([0,t>>8,t])}_genAudioData(t){const e=new Uint8Array(1+t.buffer.length);return e.set([1],0),e.set(t.buffer,1),e}_genVideoTagPayload(t,e){return D(t===0?[this._genVideoTagHeader(e),this._genVideoSequenceHeader(e)]:[this._genVideoTagHeader(e),this._genVideoData(e)])}_genVideoTagHeader(t){return new Uint8Array([(t.props.type==="key"?1:2)<<4|se,this._hasVideoSeqHeader?1:0,0,0,0])}_genVideoSequenceHeader(t){return new Uint8Array(t.cfg.description)}_genVideoData(t){if(t.props.type==="delta")return t.buffer;const e=ne(new Uint8Array(t.cfg.description)),s=e.spsArr[0].length,n=e.ppsArr[0].length;return D([new Uint8Array([0,0,s>>8,s%256]),e.spsArr[0],new Uint8Array([0,0,n>>8,n%256]),e.ppsArr[0],t.buffer])}}const ae=new E("RTMP_Packet");class de{constructor(t){this._firstFrame=!0,this._flv=new re,this._OnEncodedFrame=(e,s)=>{if(this._firstFrame){const o=this._core.getSetting();this._flv.setConfig({hasVideo:o.hasVideo,hasAudio:o.hasAudio,sampleRate:o.sampleRate,channelCount:o.channel});const _=this._flv.genHeader();if(this._core.emit(l.OnPacketed,_),o.hasVideo){const c=this._flv.genSeqTag(L.VIDEO,s);this._core.emit(l.OnPacketed,c)}if(o.hasAudio){const c=this._flv.genSeqTag(L.AUDIO,s);this._core.emit(l.OnPacketed,c)}this._firstFrame=!1,ae.log("first frame encoded & packed")}const n=this._flv.genFrameTag(e==="video"?L.VIDEO:L.AUDIO,s);this._core.emit(l.OnPacketed,n,s.props.type==="key")},this._core=t,this._bindEvents()}_bindEvents(){this._core.on(l.OnEncodedFrame,this._OnEncodedFrame)}destroy(){}}class he{constructor(){this._lastDot=0,this._totalSize=0,this._speed=[]}addSample(t){this._lastDot||(this._lastDot=Date.now()),this._totalSize+=t;const e=Date.now()-this._lastDot;e>=500&&(this._addSpeedSample(this._totalSize/e*8e3),this._totalSize=0,this._lastDot=Date.now())}_addSpeedSample(t){this._speed.push(t),this._speed=this._speed.slice(-6)}reset(){this._speed=[]}getUpSpeed(){return this._speed.length?parseInt(this._speed.reduce((t,e)=>t+=e,0)/this._speed.length):0}}const b=new E("RTMP_Wtp");class ce{constructor(t){this._queue=[],this._url="",this._connectClosed=!1,this._upSpeed=new he,this._transport=null,this._writer=null,this._inWriting=!1,this._inAdjustEncode=!1,this._increaseTimer=0,this._firstFramePushed=!1,this._core=t,this._bindEvents()}get sendSpeed(){return this._upSpeed.getUpSpeed()}getStats(){var t;return(t=this._transport)==null?void 0:t.getStats()}_bindEvents(){this._core.on(l.OnPacketed,(t,e=!1)=>{this._checkDecreaseBitrate(),this._checkDeleteCache(e),this._queue.push(t),this._inWriting||this._write()})}_checkDecreaseBitrate(){if(this._inAdjustEncode)return;const t=this._upSpeed.getUpSpeed();if(!t||this._queue.length<A.MaxCachedFrameSize)return;b.log(`up speed: ${t} low, ajust encode setting`);const e=this._core.getSetting();this._core.emit(l.OnUpstreamFeedback,{videoBitrate:t*A.RealSpeedPercent,width:e.width,height:e.height,frameRate:e.frameRate}),this._inAdjustEncode=!0,this._checkIncreaseBitrate()}_checkIncreaseBitrate(){b.log("add timer to check uplink speed increased"),clearInterval(this._increaseTimer),this._increaseTimer=setTimeout(()=>{const t=this._core.getSetting();b.log(`set encode bitrate to specified ${t.videoBitrate}`),this._core.emit(l.OnUpstreamFeedback,{videoBitrate:t.videoBitrate,width:t.width,height:t.height,frameRate:t.frameRate}),this._inAdjustEncode=!0},A.UplinkBitrateCheckInterval)}_checkDeleteCache(t){this._inAdjustEncode&&t&&(b.log(`ajust encode setting finish, delete cached ${this._queue.length} frame`),this._queue=[],this._upSpeed.reset(),this._inAdjustEncode=!1)}async start(t){this._url=t;try{await this._connect()}catch(e){throw x(C.WTP_OPEN_FAIL,e.message)}}async _connect(){const t=new WebTransport(this._url);let e;t.closed.then(()=>{b.log("webtransport closed")}).catch(n=>{e=n.message,b.log("webtransport closed due to",n)}).finally(()=>{this._connectClosed=!0,this._core.emit(O.OnConnectClosed,e),this._core.emit(O.OnError,x(C.WTP_CONNECT_FAIL,e))}),await t.ready,this._transport=t;const s=await t.createBidirectionalStream();this._writer=s.writable.getWriter(),this._write(),b.log("transport opend")}async _write(){var e;if(!this._writer)return;this._inWriting=!0;const t=this._queue.shift();if(!t){this._inWriting=!1;return}await((e=this._writer)==null?void 0:e.write(t)),this._firstFramePushed||(this._firstFramePushed=!0,this._core.emit(O.OnFirstFramePushed),b.log("first frame pushed")),this._upSpeed.addSample(t.length);try{await this._write()}catch(s){b.log("writer error:",s)}}getFile(){return D(this._queue)}destroy(){var t,e;clearTimeout(this._increaseTimer),this._connectClosed||(t=this._writer)==null||t.close(),this._writer=null,(e=this._transport)==null||e.close(),this._transport=null}}const ue=new E("LiveRTMP");class _e extends j{constructor(){super(),this._ts=0,this._setting={codec:A.codec,hardwareAcceleration:"prefer-hardware",width:-1,height:-1,frameRate:-1,sampleRate:A.sampleRate,channel:A.channel,gopSize:A.gopSize,videoBitrate:A.VideoBitrateDefault,audioBitrate:A.AudioBitrateDefault,hasAudio:!1,hasVideo:!1,vDeviceId:"",aDeviceId:""},this._encode=new ee(this),this._packet=new de(this),this._transport=new ce(this)}ready(){return this._encode.init()}getSetting(){return this._setting}updateSetting(t){this._setting=Object.assign({},this._setting,t)}videoFrameCaptured(t,e){this.emit(l.OnVideoCaptured,t,e)}audioFrameCaptured(t,e){this.emit(l.OnAudioCaptured,t,e)}startMockVideoEncode(){this.emit(l.OnVideoCaptureNoOutput)}adjustBitrate(t,e){t===S.Video&&this.updateSetting({videoBitrate:e}),t===S.Audio&&this.updateSetting({audioBitrate:e}),this.emit(l.OnBitrateChanged,t,e)}avExist(t,e){this._setting.hasVideo=t,this._setting.hasAudio=e}publish(t){return this._transport.start(t)}setEncodeCapacity(t){this._setting=Object.assign({},this._setting,t)}getStats(){return{video:{...this._encode.getStats().video,sendSpeed:this._transport.sendSpeed,codec:this._setting.codec,frameWidth:this._setting.width,frameHeight:this._setting.height,gopSize:this._setting.gopSize},audio:{...this._encode.getStats().audio,codec:"aac",channels:this._setting.channel,sampleRate:this._setting.sampleRate}}}destroy(){ue.log("destroy"),this._encode.destroy(),this._packet.destroy(),this._transport.destroy()}down(){return this._transport.getFile()}}self.constructor.name!=="Window"&&le();function le(){let i={};self.addEventListener("message",async t=>{switch(t.data.type){case v.Init:{const{options:e}=t.data;e.logEnable&&(E.enable=!0),e.logEnableLong&&(E.enableLong=!0),i=new _e,i.on(O.OnError,s=>{self.postMessage({type:y.Error,data:s.toJson()})}),i.on(O.OnConnectClosed,()=>{self.postMessage({type:y.Close})}),i.on(O.OnFirstFramePushed,()=>{self.postMessage({type:y.FirstFramePushed})});try{await i.ready(),self.postMessage({type:y.Ready})}catch(s){self.postMessage({type:y.Error,data:s.toJson()})}}break;case v.AvExist:{const{hasAudio:e,hasVideo:s}=t.data;i.avExist(s,e)}break;case v.VideoFrame:{const{frame:e,setting:s}=t.data;i.videoFrameCaptured(e,s)}break;case v.MockVideoEncode:i.startMockVideoEncode();break;case v.AudioFrame:{const{frame:e,setting:s}=t.data;i.audioFrameCaptured(e,s)}break;case v.AdjustBitrate:{const{kind:e,bitrate:s}=t.data;i.adjustBitrate(e,s)}break;case v.Publish:{const{url:e}=t.data;try{await i.publish(e)}catch(s){self.postMessage({type:y.Error,data:s.toJson()})}}break;case v.GetStats:self.postMessage({type:y.STATS,data:i.getStats()});break;case v.EncodeConfig:{i.setEncodeCapacity(t.data.cfg);break}case v.Download:{const e=i.down();self.postMessage({type:y.Flvfile,buffer:e},[e.buffer])}break;case v.UnPublish:{i.destroy();break}}})}})();\n', li = typeof self < "u" && self.Blob && new Blob([_s], { type: "text/javascript;charset=utf-8" });
|
|
5204
|
-
function
|
|
5220
|
+
const _s = '(function(){"use strict";var l=(i=>(i.OnVideoCaptured="onvideocaptured",i.OnAudioCaptured="onaudiocaptured",i.OnVideoCaptureNoOutput="onvideocapturenooutput",i.OnVideoEncoded="onvideoencoded",i.OnAudioEncoded="onaudioencoded",i.OnEncodedFrame="onencodedframe",i.OnPacketed="onpacketed",i.OnUpstreamFeedback="onupstreamfeedback",i.OnBitrateChanged="onbitratechanged",i))(l||{}),O=(i=>(i.OnError="onerror",i.OnConnectClosed="onconnectclosed",i.OnFirstFramePushed="onfirstframepushed",i))(O||{}),I=(i=>(i.Video="video",i.Audio="audio",i))(I||{}),v=(i=>(i.Init="init",i.AvExist="avexist",i.VideoFrame="videoframe",i.MockVideoEncode="mockvideoencode",i.AudioFrame="audioframe",i.AdjustBitrate="adjustbitrate",i.Publish="publish",i.UnPublish="unpublish",i.Download="download",i.GetStats="getstats",i.EncodeConfig="encodeconfig",i))(v||{}),w=(i=>(i.Ready="ready",i.Error="error",i.FirstFramePushed="firstframepushed",i.Flvfile="flvfile",i.STATS="stats",i.Close="close",i))(w||{});function $(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var k={exports:{}},U;function q(){return U||(U=1,function(i){var t=Object.prototype.hasOwnProperty,e="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(e=!1));function r(u,a,n){this.fn=u,this.context=a,this.once=n||!1}function o(u,a,n,h,m){if(typeof n!="function")throw new TypeError("The listener must be a function");var g=new r(n,h||u,m),f=e?e+a:a;return u._events[f]?u._events[f].fn?u._events[f]=[u._events[f],g]:u._events[f].push(g):(u._events[f]=g,u._eventsCount++),u}function _(u,a){--u._eventsCount===0?u._events=new s:delete u._events[a]}function c(){this._events=new s,this._eventsCount=0}c.prototype.eventNames=function(){var a=[],n,h;if(this._eventsCount===0)return a;for(h in n=this._events)t.call(n,h)&&a.push(e?h.slice(1):h);return Object.getOwnPropertySymbols?a.concat(Object.getOwnPropertySymbols(n)):a},c.prototype.listeners=function(a){var n=e?e+a:a,h=this._events[n];if(!h)return[];if(h.fn)return[h.fn];for(var m=0,g=h.length,f=new Array(g);m<g;m++)f[m]=h[m].fn;return f},c.prototype.listenerCount=function(a){var n=e?e+a:a,h=this._events[n];return h?h.fn?1:h.length:0},c.prototype.emit=function(a,n,h,m,g,f){var F=e?e+a:a;if(!this._events[F])return!1;var d=this._events[F],C=arguments.length,N,p;if(d.fn){switch(d.once&&this.removeListener(a,d.fn,void 0,!0),C){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,n),!0;case 3:return d.fn.call(d.context,n,h),!0;case 4:return d.fn.call(d.context,n,h,m),!0;case 5:return d.fn.call(d.context,n,h,m,g),!0;case 6:return d.fn.call(d.context,n,h,m,g,f),!0}for(p=1,N=new Array(C-1);p<C;p++)N[p-1]=arguments[p];d.fn.apply(d.context,N)}else{var fe=d.length,R;for(p=0;p<fe;p++)switch(d[p].once&&this.removeListener(a,d[p].fn,void 0,!0),C){case 1:d[p].fn.call(d[p].context);break;case 2:d[p].fn.call(d[p].context,n);break;case 3:d[p].fn.call(d[p].context,n,h);break;case 4:d[p].fn.call(d[p].context,n,h,m);break;default:if(!N)for(R=1,N=new Array(C-1);R<C;R++)N[R-1]=arguments[R];d[p].fn.apply(d[p].context,N)}}return!0},c.prototype.on=function(a,n,h){return o(this,a,n,h,!1)},c.prototype.once=function(a,n,h){return o(this,a,n,h,!0)},c.prototype.removeListener=function(a,n,h,m){var g=e?e+a:a;if(!this._events[g])return this;if(!n)return _(this,g),this;var f=this._events[g];if(f.fn)f.fn===n&&(!m||f.once)&&(!h||f.context===h)&&_(this,g);else{for(var F=0,d=[],C=f.length;F<C;F++)(f[F].fn!==n||m&&!f[F].once||h&&f[F].context!==h)&&d.push(f[F]);d.length?this._events[g]=d.length===1?d[0]:d:_(this,g)}return this},c.prototype.removeAllListeners=function(a){var n;return a?(n=e?e+a:a,this._events[n]&&_(this,n)):(this._events=new s,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=e,c.EventEmitter=c,i.exports=c}(k)),k.exports}var z=q(),H=$(z);const x=class x{constructor(t){this.group=(...e)=>{this._enabled&&console.group(`[${this._prefix}]: `,...e)},this.groupCollapsed=(...e)=>{this._enabled&&console.groupCollapsed(`[${this._prefix}]: `,...e)},this.groupEnd=()=>{this._enabled&&console.groupEnd()},this.log=(...e)=>{this._enabled&&console.log(`[${this._prefix}]: `,...e)},this.warn=(...e)=>{this._enabled&&console.warn(`[${this._prefix}]: `,...e)},this.error=(...e)=>{this._enabled&&console.error(`[${this._prefix}]: `,...e)},this.table=(...e)=>{this._enabled&&console.table(...e)},this._prefix=t}get _enabled(){return x.enable}get _enableLong(){return x.enableLong}get long(){return this._enableLong}};x.enable=!1,x.enableLong=!1;let E=x;function S(i){i=i.filter(Boolean);const t=new Uint8Array(i.reduce((s,r)=>s+r.byteLength,0));let e=0;return i.forEach(s=>{t.set(s,e),e+=s.byteLength}),t}const A={codec:"avc1.4DE033",MaxCachedFrameSize:100,RealSpeedPercent:.8,UplinkBitrateCheckInterval:60*1e3,VideoBitrateDefault:1e6,AudioBitrateDefault:68e3,gopSize:90,sampleRate:48e3,channel:2,audioEncoderPath:"https://lf-unpkg.volccdn.com/obj/vcloudfe/sdk/Web_push/1.0.1/1735619140327/pcm2aac.js",audioEncoderWasmPath:"https://lf-unpkg.volccdn.com/obj/vcloudfe/sdk/Web_push/1.0.2/1735619208418/pcm2aac.wasm",ignoreRelPublish:!1},T=new E("RTMP_AudioEncoder");class j{constructor(t){this._encodedFrameCount=0,this._ready=!1,this._lastFrame=null,this._aacOutput=(e,s)=>{const r=this._module.HEAPU8.subarray(e,e+s);if(!this._lastFrame)return;this._encodedFrameCount++;const{props:o}=this._lastFrame,_={buffer:new Uint8Array(r),props:{timestamp:parseInt(o.timestamp/1e3),originTs:parseInt(o.timestamp/1e3)}};this._core.emit(l.OnAudioEncoded,_)},this._core=t}async init(){const t=await fetch(A.audioEncoderPath).then(_=>_.text());new Function(`self.exports={};${t}`)();const e=self.exports.m;let s,r;const o=new Promise((_,c)=>{r=_,s=c});return e({instantiateWasm:function(_,c){fetch(A.audioEncoderWasmPath).then(u=>u.arrayBuffer()).then(u=>WebAssembly.instantiate(u,_)).then(function(u){return c(u.instance)}).then(()=>{r(),T.log("aac module inited")}).catch(u=>{s(u)})}}).then(_=>{const c=_.addFunction(this._aacOutput,"vii");_._init_callback(c),this._module=_}).catch(s),o}rnnoise(t){var s;const e=t.length;for(let r=0;r<e;r++)t[r]=t[r]*32768;(s=this._rnnoiseModule)==null||s.processFrame(t);for(let r=0;r<e;r++)t[r]=t[r]/32768}updateConfigure(){this._module._flush(),this._module._free_encoder(),this._ready=!1}encode(t){if(!this._ready){const o=this._start_encoder();if(o<0)throw new Error(`init aac encoder error, code:${o}`)}this._lastFrame=t;const e=t.buffer.buffer,s=this._module._malloc(e.byteLength);this._module.HEAPU8.subarray(s,s+e.byteLength).set(new Uint8Array(e));const r=this._module._encode_one_frame(s);if(r<0)throw new Error(`encode aac frame error, code:${r}`)}_start_encoder(){const t=this._core.getSetting(),e=this._module._init_encoder(t.sampleRate,t.channel,t.audioBitrate);if(e<0)return e;this._ready=!0,T.log(`init encoder: sampleRate=${t.sampleRate}, channel:${t.channel}, bitrate:${t.audioBitrate}`)}destroy(){var t;(t=this._module)==null||t._free_encoder()}}const P=1024;class M{constructor(){this._queue=[],this._sampleCount=0}compose(t){if(this._queue.push(t),this._sampleCount+=t.data.audioData.numberOfFrames,this._sampleCount>=P)return this._doCompose()}_doCompose(){const t=new Float32Array(P);let e=0,s=P;const r=this._queue[0];for(;;){const o=this._queue[0];if(!o)break;const _=Math.min(s,o.data.audioData.numberOfFrames-o.offset,480),c=o.data.buffer.slice(o.offset,o.offset+_);if(o.offset+=_,o.offset>=o.data.audioData.numberOfFrames&&this._queue.shift(),s-=_,this._sampleCount-=_,t.set(c,e),e+=_,s<=0)break}return{buffer:t,props:{timestamp:r.data.audioData.timestamp,sampleRate:r.data.audioData.sampleRate,numberOfChannels:r.data.audioData.numberOfChannels}}}}var y=(i=>(i[i.RTMP_INIT_FAIL=3e3]="RTMP_INIT_FAIL",i[i.AUDIO_ENCODER_INIT_FAIL=3001]="AUDIO_ENCODER_INIT_FAIL",i[i.AUDIO_RRNOISE_INIT_FAIL=3002]="AUDIO_RRNOISE_INIT_FAIL",i[i.AUDIO_ENCODE_FAIL=3003]="AUDIO_ENCODE_FAIL",i[i.VIDEO_ENCODE_CONFIGURE_FAIL=3004]="VIDEO_ENCODE_CONFIGURE_FAIL",i[i.VIDEO_ENCODE_FAIL=3005]="VIDEO_ENCODE_FAIL",i[i.WTP_OPEN_FAIL=3006]="WTP_OPEN_FAIL",i[i.WTP_CONNECT_FAIL=3007]="WTP_CONNECT_FAIL",i[i.WORKER_ERROR=3008]="WORKER_ERROR",i))(y||{});class W extends Error{constructor(t,e,s){super(),this.code=t,this.message=e,s&&(this.ext=s),this.toJson=()=>({code:this.code,message:this.message,ext:this.ext})}}function b(i,t,e){return new W(i,t,e)}class G{constructor(t){this._audioFrameQueue=new M,this.encode=e=>{const s=new Float32Array(e.numberOfFrames);e.copyTo(s,{planeIndex:0,frameOffset:0,frameCount:e.numberOfFrames});const r=this._audioFrameQueue.compose({offset:0,data:{audioData:e,buffer:s}});if(r)try{this._encoder.encode(r)}catch(o){this._core.emit(O.OnError,b(y.AUDIO_ENCODE_FAIL,o.message))}},this._core=t,this._encoder=new j(t)}async init(){try{await this._encoder.init()}catch(t){throw b(y.AUDIO_ENCODER_INIT_FAIL,t.message)}}setConfiguration(t){const e=Object.assign({},this._core.getSetting(),{audioBitrate:t});this._core.updateSetting(e),this._encoder.updateConfigure()}destroy(){this._encoder.destroy()}}const L=new E("RTMP_VEncoder");class J{constructor(t){this._encoder=null,this._queue=[],this._encodeTimer=0,this._loopEncodeTimer=0,this._frameIndex=0,this._gopSize=0,this._encodedFrameCount=0,this._lastFrame=null,this._startTimer=()=>{this._clearEncodeTimer(),this._encodeTimer=setInterval(()=>{const e=this._queue.shift();if(!(!e||!this._encoder||this._encoder.state==="closed"))try{this._encoder.encode(e,{keyFrame:this._frameIndex%this._gopSize===0}),this._frameIndex++,this._lastFrame&&this._lastFrame.close(),this._lastFrame=e}catch(s){L.log("encode frame error",s)}},5)},this._core=t}configurate(t){return this._gopSize=t.gopSize,this._encoder?this.flush().then(()=>this._configure(t)):this._configure(t)}_configure(t){return this._clearEncodeTimer(),L.log("start config encoder",t),VideoEncoder.isConfigSupported(t).then(e=>{if(!e.supported)throw new Error(`VideoEncoder not support config, ${JSON.stringify(t)}`);this._encoder=new VideoEncoder({output:(s,r)=>{const o=new Uint8Array(s.byteLength);s.copyTo(o),this._emitFrame(o,s,r)},error:s=>{this._clearEncodeTimer(),this._core.emit(O.OnError,b(y.VIDEO_ENCODE_FAIL,s.message))}}),this._encoder.configure(t),L.log("encoder configured")}).then(this._startTimer).catch(e=>{throw b(y.VIDEO_ENCODE_CONFIGURE_FAIL,e.message)})}_emitFrame(t,e,s){this._encodedFrameCount++,this._core.emit(l.OnVideoEncoded,{buffer:t,props:{byteLength:e.byteLength,duration:e.duration,timestamp:parseInt(e.timestamp/1e3),originTs:parseInt(e.timestamp/1e3),type:e.type},cfg:s.decoderConfig})}_clearEncodeTimer(){clearInterval(this._encodeTimer)}_clearLoopEncodeTimer(){this._loopEncodeTimer&&clearInterval(this._loopEncodeTimer)}flush(){return this._encoder?this._encoder.flush().then(()=>{var t;this._clearEncodeTimer(),(t=this._encoder)==null||t.close(),this._frameIndex=0,this._encoder=null,L.log("encoder flush & closed")}).catch(t=>{console.log("encoder flush & close error:",t)}):Promise.resolve()}encode(t){this._clearLoopEncodeTimer(),this._queue.push(t)}startLoop(t){if(!this._lastFrame)return;const e=Math.floor(1e3/t*1e3);L.log("start encode last frame looped, ",t,"increment:",e),this._loopEncodeTimer=setInterval(()=>{if(!this._lastFrame)return;const s=new VideoFrame(this._lastFrame,{duration:e,timestamp:(this._lastFrame.timestamp||0)+e});this._queue.push(s)},Math.floor(1e3/t))}destroy(){this._queue.forEach(t=>t.close()),this._lastFrame&&this._lastFrame.close(),this._clearEncodeTimer(),this._clearLoopEncodeTimer(),this.flush()}}const Q=new E("RTMP_VideoEncode");class K{constructor(t){this._core=t,this._encoder=new J(t)}async setConfiguration(t={}){const e=Object.assign({},this._core.getSetting(),t),s={width:e.width,height:e.height,displayWidth:e.width,displayHeight:e.height,bitrate:e.videoBitrate,framerate:Math.floor(e.frameRate),codec:e.codec,gopSize:e.gopSize,hardwareAcceleration:e.hardwareAcceleration};this._core.updateSetting(e),Q.log("set Configuration:",s,t);try{await this._encoder.configurate(s)}catch(r){this._core.emit(O.OnError,r)}}encode(t){this._encoder.encode(t)}startLoopEncodeLastFrame(){this._encoder.startLoop(this._core.getSetting().frameRate)}flushEncoder(){this._encoder.flush()}destroy(){this._encoder.destroy()}}const V=new E("RTMP_AVSync");class Z{constructor(t){this._videoFrameGot=!1,this._videoBaseDts=0,this._audioBaseDts=0,this._videoNextDts=0,this._videoLastDts=0,this._audioNextDts=0,this._lastVideoReceived=0,this._core=t}get avExist(){return this._core.getSetting().hasVideo&&this._core.getSetting().hasAudio}get videoRefDuration(){return parseInt(1e3/this._core.getSetting().frameRate)}get audioRefDuration(){return parseInt(1024/this._core.getSetting().sampleRate*1e3)}addVideoFrame(t){this._videoFrameGot||(this._videoFrameGot=!0);const e=t.props;if(Math.abs(this._videoNextDts-e.timestamp-this._videoBaseDts)>1e3){const r=Date.now()-this._lastVideoReceived;this._videoNextDts=this._videoNextDts===this._audioNextDts?this._videoNextDts+this.videoRefDuration:this._audioNextDts||this._videoNextDts+r,this._videoBaseDts=this._videoNextDts-e.timestamp,V.warn(`video stream timestamp breaked! dts:${this._videoNextDts} -> ${e.timestamp}, videoBaseDts=${this._videoBaseDts}, deltaToLastFrame=${r}`)}e.timestamp=e.timestamp+this._videoBaseDts;const s=e.timestamp-this._videoLastDts;return s>100&&V.warn("video frame large gap",s),this._videoLastDts=this._videoNextDts=e.timestamp,V.long&&V.log(`V frame, dts: ${e.timestamp}, originDts:${e.originTs}, videoBaseDts=${this._videoBaseDts}, type=${e.type}, duration=${s}`),this._lastVideoReceived=Date.now(),this._core.emit(l.OnEncodedFrame,I.Video,t),{size:t.buffer.length,duration:s,key:t.props.type==="key"}}addAudioFrame(t){if(this.avExist&&!this._videoFrameGot)return;const e=t.props;return this._audioBaseDts||(this._audioBaseDts=e.timestamp-this._videoNextDts),Math.abs(e.timestamp-this._audioBaseDts-this._audioNextDts)>1e3&&(this._audioBaseDts=this._audioNextDts+this.audioRefDuration-e.timestamp,V.warn(`audio stream timestamp breaked! dts:${this._audioNextDts} -> ${e.timestamp}, audioBaseDts=${this._audioBaseDts}`)),this._audioNextDts=e.timestamp=e.timestamp-this._audioBaseDts,V.long&&V.log(`A frame, dts: ${e.timestamp}, originDts:${e.originTs}`),this._core.emit(l.OnEncodedFrame,I.Audio,t),{size:t.buffer.length,duration:this.audioRefDuration}}}class X{constructor(){this._videoSize=0,this._videoDuration=0,this._videoBitrate=0,this._frameCount=0,this._fps=0,this._videoEncodedCount=0,this._keyCount=0,this._audioSize=0,this._audioDuration=0,this._audioBitrate=0,this._audioEncodedCount=0}get videoStats(){return{sendBitrate:this._videoBitrate,framesPerSecond:this._fps,framesEncoded:this._videoEncodedCount,keyFramesEncoded:this._keyCount}}get audioStats(){return{sendBitrate:this._audioBitrate,framesEncoded:this._audioEncodedCount}}addVideoSample({size:t,duration:e,key:s}){this._videoEncodedCount++,this._videoSize+=t,this._videoDuration+=e,this._frameCount++,s&&this._keyCount++,this._videoDuration>=1e3&&(this._videoBitrate=Math.floor(this._videoSize/this._videoDuration*8e3),this._fps=this._frameCount,this._frameCount=0,this._videoSize=0,this._videoDuration=0)}addAudioSample({size:t,duration:e}){this._audioEncodedCount++,this._audioSize+=t,this._audioDuration+=e,this._audioDuration>=1e3&&(this._audioBitrate=Math.floor(this._audioSize/this._audioDuration*1e3),this._audioSize=0,this._audioDuration=0)}}const Y=new E("RTMP_EncodeController");class ee{constructor(t){this._analyse=new X,this._gotFrame=!1,this._OnVideoCaptured=(e,s)=>{this._gotFrame=!0,this._videoSettingChanged(s)&&(Y.log("video track setting changed!",s),this._core.updateSetting({width:s.width,height:s.height,frameRate:s.frameRate,vDeviceId:s.deviceId}),this._videoEncode.setConfiguration()),this._videoEncode.encode(e)},this._OnVideoCaptureNoOutput=()=>{this._videoEncode.startLoopEncodeLastFrame()},this._OnAudioCaptured=e=>{this._gotFrame=!0,this._audioEncode.encode(e)},this._OnVideoEncoded=e=>{const s=this._avSync.addVideoFrame(e);this._analyse.addVideoSample(s)},this._OnAudioEncoded=e=>{if(!e.buffer.length)return;const s=this._avSync.addAudioFrame(e);s&&this._analyse.addAudioSample(s)},this._OnUpstreamFeedback=e=>{this._videoEncode.setConfiguration(e)},this._OnBitrateChanged=(e,s)=>{this._gotFrame&&(e===I.Video&&this._videoEncode.setConfiguration({videoBitrate:s}),e===I.Audio&&this._audioEncode.setConfiguration(s))},this._core=t,this._audioEncode=new G(t),this._videoEncode=new K(t),this._avSync=new Z(t),this._bindEvents()}getStats(){return{video:this._analyse.videoStats,audio:this._analyse.audioStats}}init(){return this._audioEncode.init()}_bindEvents(){this._core.on(l.OnVideoCaptured,this._OnVideoCaptured),this._core.on(l.OnAudioCaptured,this._OnAudioCaptured),this._core.on(l.OnVideoCaptureNoOutput,this._OnVideoCaptureNoOutput),this._core.on(l.OnVideoEncoded,this._OnVideoEncoded),this._core.on(l.OnAudioEncoded,this._OnAudioEncoded),this._core.on(l.OnUpstreamFeedback,this._OnUpstreamFeedback),this._core.on(l.OnBitrateChanged,this._OnBitrateChanged)}_videoSettingChanged(t){const e=this._core.getSetting();return t.width!==e.width||t.height!==e.height||Math.floor(t.frameRate)!==Math.floor(e.frameRate)||t.deviceId!==e.vDeviceId}destroy(){this._videoEncode.destroy(),this._audioEncode.destroy()}}var B=(i=>(i[i.AUDIO=8]="AUDIO",i[i.VIDEO=9]="VIDEO",i[i.SCRIPT_DATA=18]="SCRIPT_DATA",i))(B||{});const te=10,ie=1,se=7,oe={96e3:0,48e3:3,44100:4,22050:7,16e3:8,8e3:11};function re(i){const t=(i[4]&3)+1;let e;const s=[],r=[];let o=6;const _=i[5]&31;let c;for(let n=0;n<_;n++){if(c=i[o]<<8|i[o+1],o+=2,!c)continue;const h=i.subarray(o,o+c);o+=c,s.push(h)}const u=i[o];o++;let a;for(let n=0;n<u;n++)a=i[o]<<8|i[o+1],o+=2,a&&(r.push(i.subarray(o,o+a)),o+=a);return{sps:e,spsArr:s,ppsArr:r,nalUnitSize:t}}class ne{constructor(){this._cfg={hasVideo:!1,hasAudio:!1,sampleRate:48e3,channelCount:1},this._hasAudioSeqHeader=!1,this._hasVideoSeqHeader=!1}setConfig(t){this._cfg=Object.assign(this._cfg,t)}genHeader(){const t=[70,76,86,1,(this._cfg.hasAudio?1:0)<<2|(this._cfg.hasVideo?1:0),0,0,0,9,0,0,0,0];return new Uint8Array(t)}genSeqTag(t,e){let s;t===8?(s=this._genAudioTagPaylod(0,e),this._hasAudioSeqHeader=!0):(s=this._genVideoTagPayload(0,e),this._hasVideoSeqHeader=!0);const r=this._genTagHeader(t,s.length,e.props.timestamp),o=r.length+s.length;return S([r,s,new Uint8Array([o>>>24,o>>>16,o>>>8,o])])}genFrameTag(t,e){let s;t===8?s=this._genAudioTagPaylod(1,e):s=this._genVideoTagPayload(1,e);const r=this._genTagHeader(t,s.length,e.props.timestamp),o=r.length+s.length;return S([r,s,new Uint8Array([o>>>24,o>>>16,o>>>8,o])])}_genTagHeader(t,e,s){return new Uint8Array([t,e>>>16,e>>>8,e,s>>>16,s>>>8,s,s>>>24,0,0,0])}_genAudioTagPaylod(t,e){return S(t===0?[this._genAudioTagHeader(),this._genAudioSequenceHeader()]:[this._genAudioTagHeader(),this._genAudioData(e)])}_genAudioTagHeader(){return new Uint8Array([te<<4|12|ie<<1|this._cfg.channelCount-1])}_genAudioSequenceHeader(){const t=4096|oe[this._cfg.sampleRate]<<7|this._cfg.channelCount<<3;return new Uint8Array([0,t>>8,t])}_genAudioData(t){const e=new Uint8Array(1+t.buffer.length);return e.set([1],0),e.set(t.buffer,1),e}_genVideoTagPayload(t,e){return S(t===0?[this._genVideoTagHeader(e),this._genVideoSequenceHeader(e)]:[this._genVideoTagHeader(e),this._genVideoData(e)])}_genVideoTagHeader(t){return new Uint8Array([(t.props.type==="key"?1:2)<<4|se,this._hasVideoSeqHeader?1:0,0,0,0])}_genVideoSequenceHeader(t){return new Uint8Array(t.cfg.description)}_genVideoData(t){if(t.props.type==="delta")return t.buffer;const e=re(new Uint8Array(t.cfg.description)),s=e.spsArr[0].length,r=e.ppsArr[0].length;return S([new Uint8Array([0,0,s>>8,s%256]),e.spsArr[0],new Uint8Array([0,0,r>>8,r%256]),e.ppsArr[0],t.buffer])}}const ae=new E("RTMP_Packet");class de{constructor(t){this._firstFrame=!0,this._flv=new ne,this._OnEncodedFrame=(e,s)=>{if(this._firstFrame){const o=this._core.getSetting();this._flv.setConfig({hasVideo:o.hasVideo,hasAudio:o.hasAudio,sampleRate:o.sampleRate,channelCount:o.channel});const _=this._flv.genHeader();if(this._core.emit(l.OnPacketed,_),o.hasVideo){const c=this._flv.genSeqTag(B.VIDEO,s);this._core.emit(l.OnPacketed,c)}if(o.hasAudio){const c=this._flv.genSeqTag(B.AUDIO,s);this._core.emit(l.OnPacketed,c)}this._firstFrame=!1,ae.log("first frame encoded & packed")}const r=this._flv.genFrameTag(e==="video"?B.VIDEO:B.AUDIO,s);this._core.emit(l.OnPacketed,r,s.props.type==="key")},this._core=t,this._bindEvents()}_bindEvents(){this._core.on(l.OnEncodedFrame,this._OnEncodedFrame)}destroy(){}}class he{constructor(){this._lastDot=0,this._totalSize=0,this._speed=[]}addSample(t){this._lastDot||(this._lastDot=Date.now()),this._totalSize+=t;const e=Date.now()-this._lastDot;e>=500&&(this._addSpeedSample(this._totalSize/e*8e3),this._totalSize=0,this._lastDot=Date.now())}_addSpeedSample(t){this._speed.push(t),this._speed=this._speed.slice(-6)}reset(){this._speed=[]}getUpSpeed(){return this._speed.length?parseInt(this._speed.reduce((t,e)=>t+=e,0)/this._speed.length):0}}const D=new E("RTMP_Wtp");class ce{constructor(t){this._queue=[],this._url="",this._connectClosed=!1,this._upSpeed=new he,this._transport=null,this._writer=null,this._inWriting=!1,this._inAdjustEncode=!1,this._increaseTimer=0,this._firstFramePushed=!1,this._core=t,this._bindEvents()}get sendSpeed(){return this._upSpeed.getUpSpeed()}getStats(){var t;return(t=this._transport)==null?void 0:t.getStats()}_bindEvents(){this._core.on(l.OnPacketed,(t,e=!1)=>{this._checkDecreaseBitrate(),this._checkDeleteCache(e),this._queue.push(t),this._inWriting||this._write()})}_checkDecreaseBitrate(){if(this._inAdjustEncode)return;const t=this._upSpeed.getUpSpeed();if(!t||this._queue.length<A.MaxCachedFrameSize)return;D.log(`up speed: ${t} low, ajust encode setting`);const e=this._core.getSetting();this._core.emit(l.OnUpstreamFeedback,{videoBitrate:t*A.RealSpeedPercent,width:e.width,height:e.height,frameRate:e.frameRate}),this._inAdjustEncode=!0,this._checkIncreaseBitrate()}_checkIncreaseBitrate(){D.log("add timer to check uplink speed increased"),clearInterval(this._increaseTimer),this._increaseTimer=setTimeout(()=>{const t=this._core.getSetting();D.log(`set encode bitrate to specified ${t.videoBitrate}`),this._core.emit(l.OnUpstreamFeedback,{videoBitrate:t.videoBitrate,width:t.width,height:t.height,frameRate:t.frameRate}),this._inAdjustEncode=!0},A.UplinkBitrateCheckInterval)}_checkDeleteCache(t){this._inAdjustEncode&&t&&(D.log(`ajust encode setting finish, delete cached ${this._queue.length} frame`),this._queue=[],this._upSpeed.reset(),this._inAdjustEncode=!1)}async start(t){this._url=t;try{await this._connect()}catch(e){throw b(y.WTP_OPEN_FAIL,e.message)}}async _connect(){const t=new WebTransport(this._url);let e;t.closed.then(()=>{D.log("webtransport closed")}).catch(r=>{e=r.message,D.log("webtransport closed due to",r)}).finally(()=>{this._connectClosed=!0,this._core.emit(O.OnConnectClosed,e),this._core.emit(O.OnError,b(y.WTP_CONNECT_FAIL,e))}),await t.ready,this._transport=t;const s=await t.createBidirectionalStream();this._writer=s.writable.getWriter(),this._write(),D.log("transport opend")}async _write(){var e;if(!this._writer)return;this._inWriting=!0;const t=this._queue.shift();if(!t){this._inWriting=!1;return}await((e=this._writer)==null?void 0:e.write(t)),this._firstFramePushed||(this._firstFramePushed=!0,this._core.emit(O.OnFirstFramePushed),D.log("first frame pushed")),this._upSpeed.addSample(t.length);try{await this._write()}catch(s){D.log("writer error:",s)}}getFile(){return S(this._queue)}destroy(){var t,e;clearTimeout(this._increaseTimer),this._connectClosed||(t=this._writer)==null||t.close(),this._writer=null,(e=this._transport)==null||e.close(),this._transport=null}}const ue=new E("LiveRTMP");class _e extends H{constructor(){super(),this._ts=0,this._setting={codec:A.codec,hardwareAcceleration:"prefer-hardware",width:-1,height:-1,frameRate:-1,sampleRate:A.sampleRate,channel:A.channel,gopSize:A.gopSize,videoBitrate:A.VideoBitrateDefault,audioBitrate:A.AudioBitrateDefault,hasAudio:!1,hasVideo:!1,vDeviceId:"",aDeviceId:""},this._encode=new ee(this),this._packet=new de(this),this._transport=new ce(this)}async checkVideoHardwareAcceleration(){const t=["prefer-hardware","prefer-software","no-preference"],e=this.getSetting(),s={codec:e.codec,width:1280,height:720,framerate:15,bitrate:e.videoBitrate};for(const r of t)try{if((await VideoEncoder.isConfigSupported({...s,hardwareAcceleration:r})).supported)return this.updateSetting({hardwareAcceleration:r}),Promise.resolve()}catch{throw b(y.VIDEO_ENCODE_CONFIGURE_FAIL,`VideoEncoder not support hardwareAcceleration, ${JSON.stringify({...s,hardwareAcceleration:r})}`)}throw b(y.VIDEO_ENCODE_CONFIGURE_FAIL,"VideoEncoder not support hardwareAcceleration")}async ready(){await Promise.all([this.checkVideoHardwareAcceleration(),this._encode.init()])}getSetting(){return this._setting}updateSetting(t){this._setting=Object.assign({},this._setting,t)}videoFrameCaptured(t,e){this.emit(l.OnVideoCaptured,t,e)}audioFrameCaptured(t,e){this.emit(l.OnAudioCaptured,t,e)}startMockVideoEncode(){this.emit(l.OnVideoCaptureNoOutput)}adjustBitrate(t,e){t===I.Video&&this.updateSetting({videoBitrate:e}),t===I.Audio&&this.updateSetting({audioBitrate:e}),this.emit(l.OnBitrateChanged,t,e)}avExist(t,e){this._setting.hasVideo=t,this._setting.hasAudio=e}publish(t){return this._transport.start(t)}setEncodeCapacity(t){this._setting=Object.assign({},this._setting,t)}getStats(){return{video:{...this._encode.getStats().video,sendSpeed:this._transport.sendSpeed,codec:this._setting.codec,frameWidth:this._setting.width,frameHeight:this._setting.height,gopSize:this._setting.gopSize},audio:{...this._encode.getStats().audio,codec:"aac",channels:this._setting.channel,sampleRate:this._setting.sampleRate}}}destroy(){ue.log("destroy"),this._encode.destroy(),this._packet.destroy(),this._transport.destroy()}down(){return this._transport.getFile()}}self.constructor.name!=="Window"&&le();function le(){let i={};self.addEventListener("message",async t=>{switch(t.data.type){case v.Init:{const{options:e}=t.data;e.logEnable&&(E.enable=!0),e.logEnableLong&&(E.enableLong=!0),i=new _e,i.on(O.OnError,s=>{self.postMessage({type:w.Error,data:s.toJson()})}),i.on(O.OnConnectClosed,()=>{self.postMessage({type:w.Close})}),i.on(O.OnFirstFramePushed,()=>{self.postMessage({type:w.FirstFramePushed})});try{await i.ready(),self.postMessage({type:w.Ready})}catch(s){self.postMessage({type:w.Error,data:s.toJson()})}}break;case v.AvExist:{const{hasAudio:e,hasVideo:s}=t.data;i.avExist(s,e)}break;case v.VideoFrame:{const{frame:e,setting:s}=t.data;i.videoFrameCaptured(e,s)}break;case v.MockVideoEncode:i.startMockVideoEncode();break;case v.AudioFrame:{const{frame:e,setting:s}=t.data;i.audioFrameCaptured(e,s)}break;case v.AdjustBitrate:{const{kind:e,bitrate:s}=t.data;i.adjustBitrate(e,s)}break;case v.Publish:{const{url:e}=t.data;try{await i.publish(e)}catch(s){self.postMessage({type:w.Error,data:s.toJson()})}}break;case v.GetStats:self.postMessage({type:w.STATS,data:i.getStats()});break;case v.EncodeConfig:{i.setEncodeCapacity(t.data.cfg);break}case v.Download:{const e=i.down();self.postMessage({type:w.Flvfile,buffer:e},[e.buffer])}break;case v.UnPublish:{i.destroy();break}}})}})();\n', li = typeof self < "u" && self.Blob && new Blob([_s], { type: "text/javascript;charset=utf-8" });
|
|
5221
|
+
function Ku(r) {
|
|
5205
5222
|
let e;
|
|
5206
5223
|
try {
|
|
5207
5224
|
if (e = li && (self.URL || self.webkitURL).createObjectURL(li), !e) throw "";
|
|
@@ -5227,10 +5244,10 @@ try {
|
|
|
5227
5244
|
} catch {
|
|
5228
5245
|
}
|
|
5229
5246
|
const Le = new ee("Bridge");
|
|
5230
|
-
class gs extends
|
|
5247
|
+
class gs extends qu {
|
|
5231
5248
|
// static version = __VERSION__
|
|
5232
5249
|
constructor() {
|
|
5233
|
-
super(), this._worker = null, this._audioMsTrack = null, this._videoMsTrack = null, this._capture = new
|
|
5250
|
+
super(), this._worker = null, this._audioMsTrack = null, this._videoMsTrack = null, this._capture = new Xu(this);
|
|
5234
5251
|
}
|
|
5235
5252
|
static isSupported() {
|
|
5236
5253
|
return typeof WebTransport < "u" && typeof MediaStreamTrackProcessor < "u" && typeof MediaStreamTrackGenerator < "u" && typeof VideoEncoder < "u";
|
|
@@ -5257,7 +5274,7 @@ class gs extends Hu {
|
|
|
5257
5274
|
}
|
|
5258
5275
|
};
|
|
5259
5276
|
try {
|
|
5260
|
-
this._worker = new
|
|
5277
|
+
this._worker = new Ku();
|
|
5261
5278
|
} catch (o) {
|
|
5262
5279
|
t(pi(wt.RTMP_INIT_FAIL, o.message));
|
|
5263
5280
|
}
|
|
@@ -5282,7 +5299,7 @@ class gs extends Hu {
|
|
|
5282
5299
|
Le.table(i.data.data), this.emit(se.OnError, i.data.data);
|
|
5283
5300
|
break;
|
|
5284
5301
|
case re.Flvfile:
|
|
5285
|
-
|
|
5302
|
+
Ju(i.data.buffer);
|
|
5286
5303
|
break;
|
|
5287
5304
|
case re.FirstFramePushed:
|
|
5288
5305
|
this.emit(se.OnFirstFramePushed);
|
|
@@ -5400,12 +5417,12 @@ class gs extends Hu {
|
|
|
5400
5417
|
});
|
|
5401
5418
|
}
|
|
5402
5419
|
}
|
|
5403
|
-
function
|
|
5420
|
+
function Ju(r) {
|
|
5404
5421
|
const e = document.createElement("a");
|
|
5405
5422
|
e.href = URL.createObjectURL(new Blob([r])), e.download = Date.now() + ".flv", e.click();
|
|
5406
5423
|
}
|
|
5407
5424
|
const mi = new ce("RTMPConnect");
|
|
5408
|
-
class
|
|
5425
|
+
class Yu {
|
|
5409
5426
|
constructor(e, t, i, s) {
|
|
5410
5427
|
this._opts = void 0, this._isPushing = !1, this._url = e, this._opts = t, this._onError = i, this._OnSuccess = s, this._rtmp = new gs(), this._bindEvents();
|
|
5411
5428
|
}
|
|
@@ -5444,8 +5461,8 @@ class Ju {
|
|
|
5444
5461
|
mi.warn("unpublish"), this._rtmp.unpublish(), this._isPushing = !1;
|
|
5445
5462
|
}
|
|
5446
5463
|
}
|
|
5447
|
-
const
|
|
5448
|
-
class
|
|
5464
|
+
const Zu = new ce("PushController");
|
|
5465
|
+
class Qu extends ls {
|
|
5449
5466
|
constructor(e, {
|
|
5450
5467
|
config: t,
|
|
5451
5468
|
streamConsumeController: i
|
|
@@ -5454,7 +5471,7 @@ class Zu extends ls {
|
|
|
5454
5471
|
timeout: 5e3,
|
|
5455
5472
|
retryCount: 1,
|
|
5456
5473
|
retryDelay: 1e3
|
|
5457
|
-
}, this._audioBitrate = fe(
|
|
5474
|
+
}, this._audioBitrate = fe(Di, "audio").bitrate, this._videoBitrate = fe(Ii, "video").bitrate, this.handleAudioStreamChange = (s) => {
|
|
5458
5475
|
this.updatePush({
|
|
5459
5476
|
audioTrack: s.audioTrack
|
|
5460
5477
|
});
|
|
@@ -5529,7 +5546,7 @@ class Zu extends ls {
|
|
|
5529
5546
|
if (!i && !s)
|
|
5530
5547
|
return;
|
|
5531
5548
|
let n;
|
|
5532
|
-
this._pushMode === "rtm" ? n = new
|
|
5549
|
+
this._pushMode === "rtm" ? n = new zu(e, this._pushConfig, this._OnRtcStateChange) : n = new Yu(
|
|
5533
5550
|
e,
|
|
5534
5551
|
this._pushConfig,
|
|
5535
5552
|
this._OnRTMPError,
|
|
@@ -5542,7 +5559,7 @@ class Zu extends ls {
|
|
|
5542
5559
|
t
|
|
5543
5560
|
);
|
|
5544
5561
|
} catch (a) {
|
|
5545
|
-
|
|
5562
|
+
Zu.groupEnd(), n.unpublish();
|
|
5546
5563
|
const o = new Te(
|
|
5547
5564
|
V.PUBLISH_FAILED,
|
|
5548
5565
|
a.message,
|
|
@@ -5603,14 +5620,14 @@ class Zu extends ls {
|
|
|
5603
5620
|
return this._pushMode;
|
|
5604
5621
|
}
|
|
5605
5622
|
}
|
|
5606
|
-
class
|
|
5623
|
+
class eh extends te {
|
|
5607
5624
|
constructor(e) {
|
|
5608
|
-
super(), this._previewConsumer = new
|
|
5625
|
+
super(), this._previewConsumer = new Du(
|
|
5609
5626
|
e.getComposedStream(),
|
|
5610
5627
|
{
|
|
5611
5628
|
streamConsumeController: this
|
|
5612
5629
|
}
|
|
5613
|
-
), this._pushConsumer = new
|
|
5630
|
+
), this._pushConsumer = new Qu(
|
|
5614
5631
|
e.getComposedStream(),
|
|
5615
5632
|
{
|
|
5616
5633
|
streamConsumeController: this
|
|
@@ -5657,7 +5674,7 @@ class Qu extends te {
|
|
|
5657
5674
|
await this._pushConsumer.destroy(), this._previewConsumer.destroy();
|
|
5658
5675
|
}
|
|
5659
5676
|
}
|
|
5660
|
-
const
|
|
5677
|
+
const th = () => typeof window > "u", z = {}, ze = async (r) => {
|
|
5661
5678
|
const e = new RTCPeerConnection({ sdpSemantics: "unified-plan" });
|
|
5662
5679
|
e.addTransceiver("video", { direction: r });
|
|
5663
5680
|
const t = await e.createOffer();
|
|
@@ -5696,30 +5713,30 @@ function vs(r) {
|
|
|
5696
5713
|
}
|
|
5697
5714
|
return !1;
|
|
5698
5715
|
}
|
|
5699
|
-
const
|
|
5716
|
+
const rh = async () => {
|
|
5700
5717
|
let r = await ze("sendonly");
|
|
5701
5718
|
return navigator.userAgent.includes("VivoBrowser") && (r = await ze("sendonly")), z.h264encode = vs(r), z.vp8encode = r.indexOf("vp8") > -1, z;
|
|
5702
|
-
},
|
|
5719
|
+
}, ih = async () => {
|
|
5703
5720
|
let r = await ze("recvonly");
|
|
5704
5721
|
return navigator.userAgent.includes("VivoBrowser") && (r = await ze("recvonly")), z.h264decode = vs(r), z.vp8decode = r.indexOf("vp8") > -1, z;
|
|
5705
|
-
},
|
|
5722
|
+
}, sh = async () => {
|
|
5706
5723
|
if (typeof z.h264encode > "u")
|
|
5707
5724
|
try {
|
|
5708
|
-
await
|
|
5725
|
+
await rh();
|
|
5709
5726
|
} catch {
|
|
5710
5727
|
return !1;
|
|
5711
5728
|
}
|
|
5712
5729
|
return z.h264encode || !1;
|
|
5713
|
-
},
|
|
5730
|
+
}, nh = async () => {
|
|
5714
5731
|
if (typeof z.h264decode > "u")
|
|
5715
5732
|
try {
|
|
5716
|
-
await
|
|
5733
|
+
await ih();
|
|
5717
5734
|
} catch {
|
|
5718
5735
|
return !1;
|
|
5719
5736
|
}
|
|
5720
5737
|
return z.h264decode || !1;
|
|
5721
5738
|
};
|
|
5722
|
-
class
|
|
5739
|
+
class oh {
|
|
5723
5740
|
/** {zh}
|
|
5724
5741
|
* @brief 构造函数
|
|
5725
5742
|
* @hidden
|
|
@@ -5743,7 +5760,7 @@ class nh {
|
|
|
5743
5760
|
};
|
|
5744
5761
|
}
|
|
5745
5762
|
}
|
|
5746
|
-
const
|
|
5763
|
+
const ah = new oh();
|
|
5747
5764
|
let Cs = !0, ys = !0;
|
|
5748
5765
|
function Fe(r, e, t) {
|
|
5749
5766
|
const i = r.match(e);
|
|
@@ -5793,10 +5810,10 @@ function de(r, e, t) {
|
|
|
5793
5810
|
configurable: !0
|
|
5794
5811
|
});
|
|
5795
5812
|
}
|
|
5796
|
-
function
|
|
5813
|
+
function ch(r) {
|
|
5797
5814
|
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (Cs = r, r ? "adapter.js logging disabled" : "adapter.js logging enabled");
|
|
5798
5815
|
}
|
|
5799
|
-
function
|
|
5816
|
+
function dh(r) {
|
|
5800
5817
|
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (ys = !r, "adapter.js deprecation warnings " + (r ? "disabled" : "enabled"));
|
|
5801
5818
|
}
|
|
5802
5819
|
function Ss() {
|
|
@@ -5809,7 +5826,7 @@ function Ss() {
|
|
|
5809
5826
|
function Zt(r, e) {
|
|
5810
5827
|
ys && console.warn(r + " is deprecated, please use " + e + " instead.");
|
|
5811
5828
|
}
|
|
5812
|
-
function
|
|
5829
|
+
function uh(r) {
|
|
5813
5830
|
const e = { browser: null, version: null };
|
|
5814
5831
|
if (typeof r > "u" || !r.navigator || !r.navigator.userAgent)
|
|
5815
5832
|
return e.browser = "Not a browser.", e;
|
|
@@ -6335,7 +6352,7 @@ function Os(r, e) {
|
|
|
6335
6352
|
}
|
|
6336
6353
|
}
|
|
6337
6354
|
}
|
|
6338
|
-
function
|
|
6355
|
+
function hh(r, e) {
|
|
6339
6356
|
r.navigator.mediaDevices && "getDisplayMedia" in r.navigator.mediaDevices || r.navigator.mediaDevices && (r.navigator.mediaDevices.getDisplayMedia = function(i) {
|
|
6340
6357
|
if (!(i && i.video)) {
|
|
6341
6358
|
const s = new DOMException("getDisplayMedia without video constraints is undefined");
|
|
@@ -6351,7 +6368,7 @@ function Is(r) {
|
|
|
6351
6368
|
}
|
|
6352
6369
|
});
|
|
6353
6370
|
}
|
|
6354
|
-
function
|
|
6371
|
+
function Dt(r, e) {
|
|
6355
6372
|
if (typeof r != "object" || !(r.RTCPeerConnection || r.mozRTCPeerConnection))
|
|
6356
6373
|
return;
|
|
6357
6374
|
!r.RTCPeerConnection && r.mozRTCPeerConnection && (r.RTCPeerConnection = r.mozRTCPeerConnection), e.version < 53 && ["setLocalDescription", "setRemoteDescription", "addIceCandidate"].forEach(function(s) {
|
|
@@ -6388,7 +6405,7 @@ function Mt(r, e) {
|
|
|
6388
6405
|
}).then(a, o);
|
|
6389
6406
|
};
|
|
6390
6407
|
}
|
|
6391
|
-
function
|
|
6408
|
+
function Ds(r) {
|
|
6392
6409
|
if (!(typeof r == "object" && r.RTCPeerConnection && r.RTCRtpSender) || r.RTCRtpSender && "getStats" in r.RTCRtpSender.prototype)
|
|
6393
6410
|
return;
|
|
6394
6411
|
const e = r.RTCPeerConnection.prototype.getSenders;
|
|
@@ -6404,7 +6421,7 @@ function Ms(r) {
|
|
|
6404
6421
|
return this.track ? this._pc.getStats(this.track) : Promise.resolve(/* @__PURE__ */ new Map());
|
|
6405
6422
|
};
|
|
6406
6423
|
}
|
|
6407
|
-
function
|
|
6424
|
+
function Ms(r) {
|
|
6408
6425
|
if (!(typeof r == "object" && r.RTCPeerConnection && r.RTCRtpSender) || r.RTCRtpSender && "getStats" in r.RTCRtpReceiver.prototype)
|
|
6409
6426
|
return;
|
|
6410
6427
|
const e = r.RTCPeerConnection.prototype.getReceivers;
|
|
@@ -6491,15 +6508,15 @@ const Ci = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
6491
6508
|
shimAddTransceiver: Ns,
|
|
6492
6509
|
shimCreateAnswer: $s,
|
|
6493
6510
|
shimCreateOffer: Us,
|
|
6494
|
-
shimGetDisplayMedia:
|
|
6511
|
+
shimGetDisplayMedia: hh,
|
|
6495
6512
|
shimGetParameters: Vs,
|
|
6496
6513
|
shimGetUserMedia: Os,
|
|
6497
6514
|
shimOnTrack: Is,
|
|
6498
|
-
shimPeerConnection:
|
|
6515
|
+
shimPeerConnection: Dt,
|
|
6499
6516
|
shimRTCDataChannel: Fs,
|
|
6500
|
-
shimReceiverGetStats:
|
|
6517
|
+
shimReceiverGetStats: Ms,
|
|
6501
6518
|
shimRemoveStream: Ls,
|
|
6502
|
-
shimSenderGetStats:
|
|
6519
|
+
shimSenderGetStats: Ds
|
|
6503
6520
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
6504
6521
|
function Bs(r) {
|
|
6505
6522
|
if (!(typeof r != "object" || !r.RTCPeerConnection)) {
|
|
@@ -6667,7 +6684,7 @@ const yi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
6667
6684
|
shimTrackEventTransceiver: Ws
|
|
6668
6685
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
6669
6686
|
var _t = { exports: {} }, Si;
|
|
6670
|
-
function
|
|
6687
|
+
function ph() {
|
|
6671
6688
|
return Si || (Si = 1, function(r) {
|
|
6672
6689
|
const e = {};
|
|
6673
6690
|
e.generateIdentifier = function() {
|
|
@@ -7056,8 +7073,8 @@ t=0 0\r
|
|
|
7056
7073
|
}, r.exports = e;
|
|
7057
7074
|
}(_t)), _t.exports;
|
|
7058
7075
|
}
|
|
7059
|
-
var Js =
|
|
7060
|
-
const le = /* @__PURE__ */ Ge(Js),
|
|
7076
|
+
var Js = ph();
|
|
7077
|
+
const le = /* @__PURE__ */ Ge(Js), lh = /* @__PURE__ */ tn({
|
|
7061
7078
|
__proto__: null,
|
|
7062
7079
|
default: le
|
|
7063
7080
|
}, [Js]);
|
|
@@ -7089,7 +7106,7 @@ function Ne(r) {
|
|
|
7089
7106
|
writable: "false"
|
|
7090
7107
|
}), t));
|
|
7091
7108
|
}
|
|
7092
|
-
function
|
|
7109
|
+
function Mt(r) {
|
|
7093
7110
|
!r.RTCIceCandidate || r.RTCIceCandidate && "relayProtocol" in r.RTCIceCandidate.prototype || de(r, "icecandidate", (e) => {
|
|
7094
7111
|
if (e.candidate) {
|
|
7095
7112
|
const t = le.parseCandidate(e.candidate.candidate);
|
|
@@ -7273,7 +7290,7 @@ function Be(r, e) {
|
|
|
7273
7290
|
return s.sdp || s.type !== "offer" && s.type !== "answer" ? t.apply(this, [s]) : (s.type === "offer" ? this.createOffer : this.createAnswer).apply(this).then((a) => t.apply(this, [a]));
|
|
7274
7291
|
});
|
|
7275
7292
|
}
|
|
7276
|
-
const
|
|
7293
|
+
const mh = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
7277
7294
|
__proto__: null,
|
|
7278
7295
|
removeExtmapAllowMixed: Ft,
|
|
7279
7296
|
shimAddIceCandidateNullOrEmpty: $e,
|
|
@@ -7281,22 +7298,22 @@ const lh = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
7281
7298
|
shimMaxMessageSize: Ve,
|
|
7282
7299
|
shimParameterlessSetLocalDescription: Be,
|
|
7283
7300
|
shimRTCIceCandidate: Ne,
|
|
7284
|
-
shimRTCIceCandidateRelayProtocol:
|
|
7301
|
+
shimRTCIceCandidateRelayProtocol: Mt,
|
|
7285
7302
|
shimSendThrowTypeError: Ue
|
|
7286
7303
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
7287
|
-
function
|
|
7304
|
+
function fh({ window: r } = {}, e = {
|
|
7288
7305
|
shimChrome: !0,
|
|
7289
7306
|
shimFirefox: !0,
|
|
7290
7307
|
shimSafari: !0
|
|
7291
7308
|
}) {
|
|
7292
|
-
const t = Ss, i =
|
|
7309
|
+
const t = Ss, i = uh(r), s = {
|
|
7293
7310
|
browserDetails: i,
|
|
7294
|
-
commonShim:
|
|
7311
|
+
commonShim: mh,
|
|
7295
7312
|
extractVersion: Fe,
|
|
7296
|
-
disableLog:
|
|
7297
|
-
disableWarnings:
|
|
7313
|
+
disableLog: ch,
|
|
7314
|
+
disableWarnings: dh,
|
|
7298
7315
|
// Expose sdp as a convenience. For production apps include directly.
|
|
7299
|
-
sdp:
|
|
7316
|
+
sdp: lh
|
|
7300
7317
|
};
|
|
7301
7318
|
switch (i.browser) {
|
|
7302
7319
|
case "chrome":
|
|
@@ -7304,17 +7321,17 @@ function mh({ window: r } = {}, e = {
|
|
|
7304
7321
|
return t("Chrome shim is not included in this adapter release."), s;
|
|
7305
7322
|
if (i.version === null)
|
|
7306
7323
|
return t("Chrome shim can not determine version, not shimming."), s;
|
|
7307
|
-
t("adapter.js shimming chrome."), s.browserShim = vi, $e(r, i), Be(r), Es(r, i), bs(r), It(r, i), ks(r), As(r, i), Ps(r), xs(r), ws(r, i), Ne(r),
|
|
7324
|
+
t("adapter.js shimming chrome."), s.browserShim = vi, $e(r, i), Be(r), Es(r, i), bs(r), It(r, i), ks(r), As(r, i), Ps(r), xs(r), ws(r, i), Ne(r), Mt(r), Lt(r), Ve(r, i), Ue(r), Ft(r, i);
|
|
7308
7325
|
break;
|
|
7309
7326
|
case "firefox":
|
|
7310
|
-
if (!Ci || !
|
|
7327
|
+
if (!Ci || !Dt || !e.shimFirefox)
|
|
7311
7328
|
return t("Firefox shim is not included in this adapter release."), s;
|
|
7312
|
-
t("adapter.js shimming firefox."), s.browserShim = Ci, $e(r, i), Be(r), Os(r, i),
|
|
7329
|
+
t("adapter.js shimming firefox."), s.browserShim = Ci, $e(r, i), Be(r), Os(r, i), Dt(r, i), Is(r), Ls(r), Ds(r), Ms(r), Fs(r), Ns(r), Vs(r), Us(r), $s(r), Ne(r), Lt(r), Ve(r, i), Ue(r);
|
|
7313
7330
|
break;
|
|
7314
7331
|
case "safari":
|
|
7315
7332
|
if (!yi || !e.shimSafari)
|
|
7316
7333
|
return t("Safari shim is not included in this adapter release."), s;
|
|
7317
|
-
t("adapter.js shimming safari."), s.browserShim = yi, $e(r, i), Be(r), qs(r), Xs(r), zs(r), Bs(r), js(r), Ws(r), Gs(r), Ks(r), Ne(r),
|
|
7334
|
+
t("adapter.js shimming safari."), s.browserShim = yi, $e(r, i), Be(r), qs(r), Xs(r), zs(r), Bs(r), js(r), Ws(r), Gs(r), Ks(r), Ne(r), Mt(r), Ve(r, i), Ue(r), Ft(r, i);
|
|
7318
7335
|
break;
|
|
7319
7336
|
default:
|
|
7320
7337
|
t("Unsupported browser!");
|
|
@@ -7322,8 +7339,8 @@ function mh({ window: r } = {}, e = {
|
|
|
7322
7339
|
}
|
|
7323
7340
|
return s;
|
|
7324
7341
|
}
|
|
7325
|
-
|
|
7326
|
-
class
|
|
7342
|
+
fh({ window: typeof window > "u" ? void 0 : window });
|
|
7343
|
+
class Ch extends te {
|
|
7327
7344
|
/** {zh}
|
|
7328
7345
|
* @brief 查询是否支持 RTM 或 WebTransport 推流。
|
|
7329
7346
|
* @param mode 推流模式。
|
|
@@ -7341,7 +7358,7 @@ class vh extends te {
|
|
|
7341
7358
|
if (e === "webTransport")
|
|
7342
7359
|
return Promise.resolve(gs.isSupported());
|
|
7343
7360
|
try {
|
|
7344
|
-
return
|
|
7361
|
+
return th() || !window.RTCPeerConnection || !window.RTCPeerConnection.prototype.addTransceiver || !window.RTCPeerConnection.prototype.createDataChannel ? !1 : await nh() && await sh();
|
|
7345
7362
|
} catch {
|
|
7346
7363
|
return !1;
|
|
7347
7364
|
}
|
|
@@ -7359,9 +7376,9 @@ class vh extends te {
|
|
|
7359
7376
|
constructor(e) {
|
|
7360
7377
|
super(), this._streamManagerController = new Tu(), this._streamComposeController = new Iu(
|
|
7361
7378
|
this._streamManagerController
|
|
7362
|
-
), this._streamConsumeController = new
|
|
7379
|
+
), this._streamConsumeController = new eh(
|
|
7363
7380
|
this._streamComposeController
|
|
7364
|
-
), this._streamConsumeController.setPushConfig(e), this._observer =
|
|
7381
|
+
), this._streamConsumeController.setPushConfig(e), this._observer = ah, this._bindEvent();
|
|
7365
7382
|
}
|
|
7366
7383
|
/** {zh}
|
|
7367
7384
|
* @brief 获取设备列表,包括音频输入设备和视频输入设备。
|
|
@@ -7887,7 +7904,7 @@ class vh extends te {
|
|
|
7887
7904
|
* @param config The video stream layout parameters can be a single object or an array of multiple objects.
|
|
7888
7905
|
*/
|
|
7889
7906
|
addVideoStream(e) {
|
|
7890
|
-
|
|
7907
|
+
M(e) ? e.forEach((t) => {
|
|
7891
7908
|
this._streamComposeController.addVideoStream(t);
|
|
7892
7909
|
}) : this._streamComposeController.addVideoStream(e);
|
|
7893
7910
|
}
|
|
@@ -7913,7 +7930,7 @@ class vh extends te {
|
|
|
7913
7930
|
* @param config Update the video stream parameters. When an array is passed, multiple video streams are updated.
|
|
7914
7931
|
*/
|
|
7915
7932
|
updateVideoStream(e) {
|
|
7916
|
-
|
|
7933
|
+
M(e) ? this._streamComposeController.updateVideoStream(e) : this._streamComposeController.updateVideoStream([e]);
|
|
7917
7934
|
}
|
|
7918
7935
|
/** {zh}
|
|
7919
7936
|
* @brief 隐藏合流画布中的视频流。当需要暂时隐藏某个视频画面,但不想从合流画布中移除该视频流时使用。
|
|
@@ -7951,7 +7968,7 @@ class vh extends te {
|
|
|
7951
7968
|
* @param config Audio stream parameters can be a single object or an array of multiple objects.
|
|
7952
7969
|
*/
|
|
7953
7970
|
addAudioStream(e) {
|
|
7954
|
-
|
|
7971
|
+
M(e) ? e.map(
|
|
7955
7972
|
(t) => this._streamComposeController.addAudioStream(t)
|
|
7956
7973
|
) : this._streamComposeController.addAudioStream(e);
|
|
7957
7974
|
}
|
|
@@ -7985,7 +8002,7 @@ class vh extends te {
|
|
|
7985
8002
|
* - Call `updateAudioStream()` to update the parameters of the audio stream.
|
|
7986
8003
|
*/
|
|
7987
8004
|
updateAudioStream(e) {
|
|
7988
|
-
|
|
8005
|
+
M(e) ? this._streamComposeController.updateAudioStream(e) : this._streamComposeController.updateAudioStream([e]);
|
|
7989
8006
|
}
|
|
7990
8007
|
/** {zh}
|
|
7991
8008
|
* @brief 静音指定的音频流或包含音频轨道的视频流。在某个音频流内容不需要被输出时使用。
|
|
@@ -8304,5 +8321,5 @@ class vh extends te {
|
|
|
8304
8321
|
}
|
|
8305
8322
|
}
|
|
8306
8323
|
export {
|
|
8307
|
-
|
|
8324
|
+
Ch as default
|
|
8308
8325
|
};
|