* @copyright 2014-2019
* @license MIT-style
*
* @param {YUVFrame} buffer - input frame buffer
* @param {Uint8ClampedArray} output - array to draw RGBA into
* Assumes that the output array already has alpha channel set to opaque.
*/function t(n, r) { var l = n.format.width | 0, a = n.format.height | 0, e = h(n.format.width / n.format.chromaWidth) | 0, g = h(n.format.height / n.format.chromaHeight) | 0, _ = n.y.bytes, y = n.u.bytes, x = n.v.bytes, E = n.y.stride | 0, C = n.u.stride | 0, L = n.v.stride | 0, A = l << 2, I = 0, D = 0, w = 0, S = 0, O = 0, F = 0, j = 0, P = 0, $ = 0, V = 0, q = 0, ee = 0, re = 0, ye = 0, ce = 0, Q = 0, se = 0, fe = 0; if (e == 1 && g == 1) for (j = 0, P = A, fe = 0, Q = 0; Q < a; Q += 2) { for (D = Q * E | 0, w = D + E | 0, S = fe * C | 0, O = fe * L | 0, ce = 0; ce < l; ce += 2)$ = y[S++] | 0, V = x[O++] | 0, ee = (409 * V | 0) - 57088 | 0, re = (100 * $ | 0) + (208 * V | 0) - 34816 | 0, ye = (516 * $ | 0) - 70912 | 0, q = 298 * _[D++] | 0, r[j] = q + ee >> 8, r[j + 1] = q - re >> 8, r[j + 2] = q + ye >> 8, j += 4, q = 298 * _[D++] | 0, r[j] = q + ee >> 8, r[j + 1] = q - re >> 8, r[j + 2] = q + ye >> 8, j += 4, q = 298 * _[w++] | 0, r[P] = q + ee >> 8, r[P + 1] = q - re >> 8, r[P + 2] = q + ye >> 8, P += 4, q = 298 * _[w++] | 0, r[P] = q + ee >> 8, r[P + 1] = q - re >> 8, r[P + 2] = q + ye >> 8, P += 4; j += A, P += A, fe++ } else for (F = 0, Q = 0; Q < a; Q++)for (se = 0, fe = Q >> g, I = Q * E | 0, S = fe * C | 0, O = fe * L | 0, ce = 0; ce < l; ce++)se = ce >> e, $ = y[S + se] | 0, V = x[O + se] | 0, ee = (409 * V | 0) - 57088 | 0, re = (100 * $ | 0) + (208 * V | 0) - 34816 | 0, ye = (516 * $ | 0) - 70912 | 0, q = 298 * _[I++] | 0, r[F] = q + ee >> 8, r[F + 1] = q - re >> 8, r[F + 2] = q + ye >> 8, F += 4 } YCbCr.exports = { convertYCbCr: t }
})(); var YCbCrExports = YCbCr.exports; (function () { var h = FrameSinkExports, t = YCbCrExports; function n(r) { var l = this, a = r.getContext("2d"), e = null, g = null, _ = null; function y(E, C) { e = a.createImageData(E, C); for (var L = e.data, A = E * C * 4, I = 0; I < A; I += 4)L[I + 3] = 255 } function x(E, C) { g = document.createElement("canvas"), g.width = E, g.height = C, _ = g.getContext("2d") } return l.drawFrame = function (C) { var L = C.format; (r.width !== L.displayWidth || r.height !== L.displayHeight) && (r.width = L.displayWidth, r.height = L.displayHeight), (e === null || e.width != L.width || e.height != L.height) && y(L.width, L.height), t.convertYCbCr(C, e.data); var A = L.cropWidth != L.displayWidth || L.cropHeight != L.displayHeight, I; A ? (g || x(L.cropWidth, L.cropHeight), I = _) : I = a, I.putImageData(e, -L.cropLeft, -L.cropTop, L.cropLeft, L.cropTop, L.cropWidth, L.cropHeight), A && a.drawImage(g, 0, 0, L.displayWidth, L.displayHeight) }, l.clear = function () { a.clearRect(0, 0, r.width, r.height) }, l } n.prototype = Object.create(h.prototype) })(); var shaders = {
vertex: `precision mediump float;
attribute vec2 aPosition;
attribute vec2 aLumaPosition;
attribute vec2 aChromaPosition;
varying vec2 vLumaPosition;
varying vec2 vChromaPosition;
void main() {
gl_Position = vec4(aPosition, 0, 1);
vLumaPosition = aLumaPosition;
vChromaPosition = aChromaPosition;
}
`, fragment: `// inspired by https://github.com/mbebenita/Broadway/blob/master/Player/canvas.js
precision mediump float;
uniform sampler2D uTextureY;
uniform sampler2D uTextureCb;
uniform sampler2D uTextureCr;
varying vec2 vLumaPosition;
varying vec2 vChromaPosition;
void main() {
// Y, Cb, and Cr planes are uploaded as ALPHA textures.
float fY = texture2D(uTextureY, vLumaPosition).w;
float fCb = texture2D(uTextureCb, vChromaPosition).w;
float fCr = texture2D(uTextureCr, vChromaPosition).w;
// Premultipy the Y...
float fYmul = fY * 1.1643828125;
// And convert that to RGB!
gl_FragColor = vec4(
fYmul + 1.59602734375 * fCr - 0.87078515625,
fYmul - 0.39176171875 * fCb - 0.81296875 * fCr + 0.52959375,
fYmul + 2.017234375 * fCb - 1.081390625,
1
);
}
`, vertexStripe: `precision mediump float;
attribute vec2 aPosition;
attribute vec2 aTexturePosition;
varying vec2 vTexturePosition;
void main() {
gl_Position = vec4(aPosition, 0, 1);
vTexturePosition = aTexturePosition;
}
`, fragmentStripe: `// extra 'stripe' texture fiddling to work around IE 11's poor performance on gl.LUMINANCE and gl.ALPHA textures
precision mediump float;
uniform sampler2D uStripe;
uniform sampler2D uTexture;
varying vec2 vTexturePosition;
void main() {
// Y, Cb, and Cr planes are mapped into a pseudo-RGBA texture
// so we can upload them without expanding the bytes on IE 11
// which doesn't allow LUMINANCE or ALPHA textures
// The stripe textures mark which channel to keep for each pixel.
// Each texture extraction will contain the relevant value in one
// channel only.
float fLuminance = dot(
texture2D(uStripe, vTexturePosition),
texture2D(uTexture, vTexturePosition)
);
gl_FragColor = vec4(0, 0, 0, fLuminance);
}
`}; (function () { var h = FrameSinkExports, t = shaders; function n(r) { var l = this, a = n.contextForCanvas(r); if (a === null) throw new Error("WebGL unavailable"); function e(Q, se) { var fe = a.createShader(Q); if (a.shaderSource(fe, se), a.compileShader(fe), !a.getShaderParameter(fe, a.COMPILE_STATUS)) { var G = a.getShaderInfoLog(fe); throw a.deleteShader(fe), new Error("GL shader compilation for " + Q + " failed: " + G) } return fe } var g, _, y = new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]), x = {}, E = {}, C = {}, L, A, I, D, w, S, O, F, j, P; function $(Q, se) { return (!x[Q] || se) && (x[Q] = a.createTexture()), x[Q] } function V(Q, se, fe, G, K) { var de = !x[Q] || se, ve = $(Q, se); if (a.activeTexture(a.TEXTURE0), n.stripe) { var ae = !x[Q + "_temp"] || se, J = $(Q + "_temp", se); a.bindTexture(a.TEXTURE_2D, J), ae ? (a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.NEAREST), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.NEAREST), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, fe / 4, G, 0, a.RGBA, a.UNSIGNED_BYTE, K)) : a.texSubImage2D(a.TEXTURE_2D, 0, 0, 0, fe / 4, G, a.RGBA, a.UNSIGNED_BYTE, K); var U = x[Q + "_stripe"], X = !U || se; X && (U = $(Q + "_stripe", se)), a.bindTexture(a.TEXTURE_2D, U), X && (a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.NEAREST), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.NEAREST), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, fe, 1, 0, a.RGBA, a.UNSIGNED_BYTE, re(fe))) } else a.bindTexture(a.TEXTURE_2D, ve), de ? (a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texImage2D(a.TEXTURE_2D, 0, a.ALPHA, fe, G, 0, a.ALPHA, a.UNSIGNED_BYTE, K)) : a.texSubImage2D(a.TEXTURE_2D, 0, 0, 0, fe, G, a.ALPHA, a.UNSIGNED_BYTE, K) } function q(Q, se, fe, G) { var K = x[Q]; a.useProgram(_); var de = E[Q]; (!de || se) && (a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, K), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, fe, G, 0, a.RGBA, a.UNSIGNED_BYTE, null), de = E[Q] = a.createFramebuffer()), a.bindFramebuffer(a.FRAMEBUFFER, de), a.framebufferTexture2D(a.FRAMEBUFFER, a.COLOR_ATTACHMENT0, a.TEXTURE_2D, K, 0); var ve = x[Q + "_temp"]; a.activeTexture(a.TEXTURE1), a.bindTexture(a.TEXTURE_2D, ve), a.uniform1i(S, 1); var ae = x[Q + "_stripe"]; a.activeTexture(a.TEXTURE2), a.bindTexture(a.TEXTURE_2D, ae), a.uniform1i(w, 2), a.bindBuffer(a.ARRAY_BUFFER, L), a.enableVertexAttribArray(A), a.vertexAttribPointer(A, 2, a.FLOAT, !1, 0, 0), a.bindBuffer(a.ARRAY_BUFFER, I), a.enableVertexAttribArray(D), a.vertexAttribPointer(D, 2, a.FLOAT, !1, 0, 0), a.viewport(0, 0, fe, G), a.drawArrays(a.TRIANGLES, 0, y.length / 2), a.bindFramebuffer(a.FRAMEBUFFER, null) } function ee(Q, se, fe) { a.activeTexture(se), a.bindTexture(a.TEXTURE_2D, x[Q]), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.uniform1i(a.getUniformLocation(g, Q), fe) } function re(Q) { if (C[Q]) return C[Q]; for (var se = Q, fe = new Uint32Array(se), G = 0; G < se; G += 4)fe[G] = 255, fe[G + 1] = 65280, fe[G + 2] = 16711680, fe[G + 3] = 4278190080; return C[Q] = new Uint8Array(fe.buffer) } function ye(Q, se) { var fe = e(a.VERTEX_SHADER, Q), G = e(a.FRAGMENT_SHADER, se), K = a.createProgram(); if (a.attachShader(K, fe), a.attachShader(K, G), a.linkProgram(K), !a.getProgramParameter(K, a.LINK_STATUS)) { var de = a.getProgramInfoLog(K); throw a.deleteProgram(K), new Error("GL program linking failed: " + de) } return K } function ce() { if (n.stripe) { _ = ye(t.vertexStripe, t.fragmentStripe), a.getAttribLocation(_, "aPosition"), I = a.createBuffer(); var Q = new Float32Array([0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]); a.bindBuffer(a.ARRAY_BUFFER, I), a.bufferData(a.ARRAY_BUFFER, Q, a.STATIC_DRAW), D = a.getAttribLocation(_, "aTexturePosition"), w = a.getUniformLocation(_, "uStripe"), S = a.getUniformLocation(_, "uTexture") } g = ye(t.vertex, t.fragment), L = a.createBuffer(), a.bindBuffer(a.ARRAY_BUFFER, L), a.bufferData(a.ARRAY_BUFFER, y, a.STATIC_DRAW), A = a.getAttribLocation(g, "aPosition"), O = a.createBuffer(), F = a.getAttribLocation(g, "aLumaPosition"), j = a.createBuffer(), P = a.getAttribLocation(g, "aChromaPosition") } return l.drawFrame = function (Q) { var se = Q.format, fe = !g || r.width !== se.displayWidth || r.height !== se.displayHeight; if (fe && (r.width = se.displayWidth, r.height = se.displayHeight, l.clear()), g || ce(), fe) { var G = function (K, de, ve) { var ae = se.cropLeft / ve, J = (se.cropLeft + se.cropWidth) / ve, U = (se.cropTop + se.cropHeight) / se.height, X = se.cropTop / se.height, ne = new Float32Array([ae, U, J, U, ae, X, ae, X, J, U, J, X]); a.bindBuffer(a.ARRAY_BUFFER, K), a.bufferData(a.ARRAY_BUFFER, ne, a.STATIC_DRAW) }; G(O, F, Q.y.stride), G(j, P, Q.u.stride * se.width / se.chromaWidth) } V("uTextureY", fe, Q.y.stride, se.height, Q.y.bytes), V("uTextureCb", fe, Q.u.stride, se.chromaHeight, Q.u.bytes), V("uTextureCr", fe, Q.v.stride, se.chromaHeight, Q.v.bytes), n.stripe && (q("uTextureY", fe, Q.y.stride, se.height), q("uTextureCb", fe, Q.u.stride, se.chromaHeight), q("uTextureCr", fe, Q.v.stride, se.chromaHeight)), a.useProgram(g), a.viewport(0, 0, r.width, r.height), ee("uTextureY", a.TEXTURE0, 0), ee("uTextureCb", a.TEXTURE1, 1), ee("uTextureCr", a.TEXTURE2, 2), a.bindBuffer(a.ARRAY_BUFFER, L), a.enableVertexAttribArray(A), a.vertexAttribPointer(A, 2, a.FLOAT, !1, 0, 0), a.bindBuffer(a.ARRAY_BUFFER, O), a.enableVertexAttribArray(F), a.vertexAttribPointer(F, 2, a.FLOAT, !1, 0, 0), a.bindBuffer(a.ARRAY_BUFFER, j), a.enableVertexAttribArray(P), a.vertexAttribPointer(P, 2, a.FLOAT, !1, 0, 0), a.drawArrays(a.TRIANGLES, 0, y.length / 2) }, l.clear = function () { a.viewport(0, 0, r.width, r.height), a.clearColor(0, 0, 0, 0), a.clear(a.COLOR_BUFFER_BIT) }, l.clear(), l } n.stripe = !1, n.contextForCanvas = function (r) { var l = { preferLowPowerToHighPerformance: !0, powerPreference: "low-power", failIfMajorPerformanceCaveat: !0, preserveDrawingBuffer: !0 }; return r.getContext("webgl", l) || r.getContext("experimental-webgl", l) }, n.isAvailable = function () { var r = document.createElement("canvas"), l; r.width = 1, r.height = 1; try { l = n.contextForCanvas(r) } catch { return !1 } if (l) { var a = l.TEXTURE0, e = 4, g = 4, _ = l.createTexture(), y = new Uint8Array(e * g), x = n.stripe ? e / 4 : e, E = n.stripe ? l.RGBA : l.ALPHA, C = n.stripe ? l.NEAREST : l.LINEAR; l.activeTexture(a), l.bindTexture(l.TEXTURE_2D, _), l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_S, l.CLAMP_TO_EDGE), l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_T, l.CLAMP_TO_EDGE), l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MIN_FILTER, C), l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MAG_FILTER, C), l.texImage2D(l.TEXTURE_2D, 0, E, x, g, 0, E, l.UNSIGNED_BYTE, y); var L = l.getError(); return !L } else return !1 }, n.prototype = Object.create(h.prototype) })(); function Texture(h) { this.gl = h, this.texture = h.createTexture(), h.bindTexture(h.TEXTURE_2D, this.texture), h.texParameteri(h.TEXTURE_2D, h.TEXTURE_MAG_FILTER, h.LINEAR), h.texParameteri(h.TEXTURE_2D, h.TEXTURE_MIN_FILTER, h.LINEAR), h.texParameteri(h.TEXTURE_2D, h.TEXTURE_WRAP_S, h.CLAMP_TO_EDGE), h.texParameteri(h.TEXTURE_2D, h.TEXTURE_WRAP_T, h.CLAMP_TO_EDGE) } Texture.prototype.bind = function (h, t, n) { let r = this.gl; r.activeTexture([r.TEXTURE0, r.TEXTURE1, r.TEXTURE2][h]), r.bindTexture(r.TEXTURE_2D, this.texture), r.uniform1i(r.getUniformLocation(t, n), h) }, Texture.prototype.fill = function (h, t, n) { let r = this.gl; r.bindTexture(r.TEXTURE_2D, this.texture), r.texImage2D(r.TEXTURE_2D, 0, r.LUMINANCE, h, t, 0, r.LUMINANCE, r.UNSIGNED_BYTE, n) }; class Renderer {
constructor(t) { this.flv = t; const { container: n } = t.options; this.canvas = n, this.gl = n.getContext("webgl2") || n.getContext("webgl") || n.getContext("experimental-webgl"), this.initGL({ preserveDrawingBuffer: !1 }) } initGL(t) {
if (!this.gl) { console.log("[ER] WebGL not supported."); return } let n = this.gl; n.pixelStorei(n.UNPACK_ALIGNMENT, 1); let r = n.createProgram(), l = `
attribute highp vec4 aVertexPosition;
attribute vec2 aTextureCoord;
varying highp vec2 vTextureCoord;
void main(void) {
gl_Position = aVertexPosition;
vTextureCoord = aTextureCoord;
}`, a = n.createShader(n.VERTEX_SHADER); n.shaderSource(a, l), n.compileShader(a); let e = `
precision mediump float;
uniform sampler2D tex;
uniform sampler2D YTexture;
uniform sampler2D UTexture;
uniform sampler2D VTexture;
uniform float texWidth;
uniform float texHeight;
const vec3 keyColor = vec3(0.47, 1.0, 0.47);
uniform float similarity;
uniform float smoothness;
uniform float spill;
vec2 RGBtoUV(vec3 rgb) {
return vec2(
rgb.r * -0.169 + rgb.g * -0.331 + rgb.b * 0.5 + 0.5,
rgb.r * 0.5 + rgb.g * -0.419 + rgb.b * -0.081 + 0.5
);
}
const mat4 YUV2RGB = mat4
(
1.1643828125, 0, 1.59602734375, -.87078515625,
1.1643828125, -.39176171875, -.81296875, .52959375,
1.1643828125, 2.017234375, 0, -1.081390625,
0, 0, 0, 1
);
vec4 GetRgba(float detaX, float detaY) {
vec2 texCoord = vec2((gl_FragCoord.x + detaX)/texWidth, 1.0 - (gl_FragCoord.y + detaY)/texHeight);
vec4 rgba = vec4( texture2D(YTexture, texCoord).x, texture2D(UTexture, texCoord).x, texture2D(VTexture, texCoord).x, 1) * YUV2RGB;
float green = rgba.g - max(rgba.r, rgba.b);
float greenKey = keyColor.g - max(keyColor.r, keyColor.b);
float mask = smoothstep(greenKey-0.1, 0.0, green);
rgba.a = mask;
return rgba;
}
vec4 ProcessChromaKey() {
vec4 rgba = GetRgba(0.0, 0.0);
if (rgba.a > 0.0 && rgba.a < 1.0) {
vec4 rgbas[9];
float maxMask = 0.0;
vec4 minRgba = rgba;
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
vec4 tmp;
if (i == 0 && j == 0) {
tmp = rgba;
} else {
tmp = GetRgba(float(i), float(j));
}
rgbas[(i+1)*3 + (j+1)] = tmp;
if (tmp.a > maxMask) {
maxMask = tmp.a;
minRgba = tmp;
}
}
}
rgbas[4] = minRgba;
rgbas[4].a = rgba.a;
vec4 dest = vec4(0.0, 0.0, 0.0, 0.0);
float gs[9];
gs[0] = gs[2] = gs[6] = gs[8] = 0.05;
gs[1] = gs[3] = gs[5] = gs[7] = 0.05;
gs[4] = 0.6;
for(int i = 0; i < 9; i++) {
dest.rgb = dest.rgb + rgbas[i].rgb * gs[i];
}
gs[0] = gs[2] = gs[6] = gs[8] = 0.05;
gs[1] = gs[3] = gs[5] = gs[7] = 0.15;
gs[4] = 0.2;
for(int i = 0; i < 9; i++) {
dest.a = dest.a + rgbas[i].a* gs[i];
}
rgba.rgb = dest.rgb;
rgba.a = dest.a;
if (rgba.g > rgba.r && rgba.g > rgba.b) {
rgba.g = max(rgba.r, rgba.b);
}
rgba.rgb = rgba.rgb * rgba.a;
} else {
rgba.rgb = rgba.rgb * rgba.a;
}
return rgba;
}
void main(void) {
gl_FragColor = ProcessChromaKey();
}
`, g = n.createShader(n.FRAGMENT_SHADER); n.shaderSource(g, e), n.compileShader(g), n.attachShader(r, a), n.attachShader(r, g), n.linkProgram(r), n.useProgram(r), n.getProgramParameter(r, n.LINK_STATUS) || console.log("[ER] Shader link failed."); let _ = n.getAttribLocation(r, "aVertexPosition"); n.enableVertexAttribArray(_); let y = n.getAttribLocation(r, "aTextureCoord"); n.enableVertexAttribArray(y); let x = n.createBuffer(); n.bindBuffer(n.ARRAY_BUFFER, x), n.bufferData(n.ARRAY_BUFFER, new Float32Array([1, 1, 0, -1, 1, 0, 1, -1, 0, -1, -1, 0]), n.STATIC_DRAW), n.vertexAttribPointer(_, 3, n.FLOAT, !1, 0, 0); let E = n.createBuffer(); n.bindBuffer(n.ARRAY_BUFFER, E), n.bufferData(n.ARRAY_BUFFER, new Float32Array([1, 0, 0, 0, 1, 1, 0, 1]), n.STATIC_DRAW), n.vertexAttribPointer(y, 2, n.FLOAT, !1, 0, 0), n.y = new Texture(n), n.u = new Texture(n), n.v = new Texture(n), n.y.bind(0, r, "YTexture"), n.u.bind(1, r, "UTexture"), n.v.bind(2, r, "VTexture"); let C = n.getUniformLocation(r, "texWidth"), L = n.getUniformLocation(r, "texHeight"); n.uniform1f(C, this.canvas.width), n.uniform1f(L, this.canvas.height)
} drawFrame(t) { if (!this.gl) { console.log("[ER] Render frame failed due to WebGL not supported."); return } const { data: n, width: r, height: l, yLength: a, uvLength: e } = t, g = new Uint8Array(n), _ = this.gl; _.viewport(0, 0, _.canvas.width, _.canvas.height), _.clearColor(0, 0, 0, 0), _.clear(_.COLOR_BUFFER_BIT), _.y.fill(r, l, g.subarray(0, a)), _.u.fill(r >> 1, l >> 1, g.subarray(a, a + e)), _.v.fill(r >> 1, l >> 1, g.subarray(a + e, g.length)), _.drawArrays(_.TRIANGLE_STRIP, 0, 4) } fullscreen() { let t = this.canvas; t.RequestFullScreen ? t.RequestFullScreen() : t.webkitRequestFullScreen ? t.webkitRequestFullScreen() : t.mozRequestFullScreen ? t.mozRequestFullScreen() : t.msRequestFullscreen ? t.msRequestFullscreen() : alert("This browser doesn't supporter fullscreen") } exitfullscreen() { document.exitFullscreen ? document.exitFullscreen() : document.webkitExitFullscreen ? document.webkitExitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.msExitFullscreen ? document.msExitFullscreen() : alert("Exit fullscreen doesn't work") } destroy() { this.flv = null, this.canvas = null, this.gl = null }
} let Decoder$1 = class { constructor(t) { return window.VideoDecoder ? new Render(t, this) : new Renderer(t, this) } }; class VideoBasic { constructor(t) { const { flv: n } = t; this.flv = n, this.playing = !1, this.inputVideoIndex = 0, this.outVideoIndex = 0, this.videoFrames = [], this.lastTime = 0; const r = this; n.on("destroy", () => { r.playing = !1, r.videoFrames = null }), n.on("timeupdate", l => { var a; ((a = r.videoFrames[0]) == null ? void 0 : a.pts) <= l + 20 && (parseInt(performance.now()), this.lastTime = parseInt(performance.now()), r.draw(0)) }) } get decoding() { return this.outVideoIndex !== this.inputVideoIndex } framePlay() { return !!((this.lastTime > 0 && this.videoFrames.length > 0 || this.videoFrames.length > 10) && this.playing) } reset() { this.playing = !1, this.workerReset(), window.VideoDecoder && this.videoFrames.forEach(t => { var n; (n = t.data) == null || n.close() }), this.videoFrames = [], this.inputVideoIndex = 0, this.outVideoIndex = 0, this.lastTime = 0 } clearList() { console.log("---clearList---"), window.VideoDecoder && this.videoFrames.forEach(t => { var n; (n = t.data) == null || n.close() }), this.videoFrames = [], this.inputVideoIndex = 0, this.outVideoIndex = 0, this.lastTime = 0 } draw(t) { const n = this.videoFrames[t]; if (!n) return !1; if (this.videoFrames.shift(), window.VideoDecoder) { n.type != "videoEnd" ? this.flv.render.drawFrame(n.data) : (this.flv.playAudioLastFrame(), this.flv.options.wxServerEnd()); return } n.type != "videoEnd" ? this.flv.render.drawFrame(n) : (this.flv.playAudioLastFrame(), this.flv.options.wxServerEnd()) } play() { this.videoFrames.length > 0 ? this.playing = !0 : this.playing = !1 } stop() { this.playing = !1 } } class Wasm extends VideoBasic { constructor(t) { super(t); const { flv: n } = t; this.flv = n, this.firstTarget = !1, this.animationFrameTimer = null, this.list = [], this.loop = !1, this.workerInit(), this.animationFrame(), n.on("videoData", (r, l) => { this.list.push({ buffer: r, timestamp: l }) }), n.on("destroy", () => { this.animationFrameTimer && cancelAnimationFrame(this.animationFrameTimer), this.animationFrameTimer = null, this.decoderWorker.postMessage({ type: "stop" }), this.decoderWorker.terminate(), this.decoderWorker = null }) } workerInit() { const t = this; this.decoderWorker = new Worker("ffmpegWorker.js"), this.decoderWorker.onmessage = n => { const r = n.data; switch (r.type) { case "video": this.outVideoIndex++, this.videoFrames.push(r); break; case "videoEnd": this.outVideoIndex++, this.videoFrames.push(r); break; case "loaded": this.firstTarget ? (console.log("重启wasm"), setTimeout(() => { t.loop = !0 }, 100)) : (this.firstTarget = !0, this.flv.emit("workOn"), setTimeout(() => { t.loop = !0 }, 100)); break } } } workerReset() { this.loop = !1, this.list = [], console.log("wasm restart"), this.decoderWorker.postMessage({ type: "stop" }), this.decoderWorker.terminate(), this.workerInit() } animationFrame() { const t = this; this.animationFrameTimer = requestAnimationFrame(() => { if (t.list[0] && t.loop) { const r = t.list.shift(); t.inputVideoIndex++, t.decoderWorker.postMessage({ data: r.buffer, pts: r.timestamp }, [r.buffer.buffer]) } this.animationFrame() }) } } const webCodecsText = `let renderer = null;
let pendingFrame = null;
let startTime = null;
let frameCount = 0;
let width = 1080;
let height = 1920;
let videoDecoder = null;
let h264Arr = [];
let decoding = false;
let playing = false;
let animationFrameTimer = null;
let fpsTime = 0;
let fpsCount = 0;
let missCount = 0;
function animationFrame() {
animationFrameTimer = requestAnimationFrame(() => {
const h264Len = h264Arr.length;
if (h264Len > 0 && decoding == false && playing) {
let nowTime = getNowTime();
if (fpsTime == 0 || fpsTime < nowTime - 1000) {
if (fpsTime == 0) {
console.info(nowTime, "start decode");
missCount = 10;
} else {
if (fpsCount < 25) {
missCount += 25 - fpsCount;
} else {
missCount = missCount - (fpsCount - 25);
}
console.info(fpsTime, "decode fps", fpsCount, ", miss", missCount);
}
fpsTime = nowTime;
fpsCount = 0;
}
if (fpsCount < 25 + missCount) {
try {
const buffer = h264Arr.shift();
// console.log(h264Arr.length, buffer, h264Arr[0])
if (h264Len <= 2 && h264Arr[0]?.byteLength == 1) {
self.postMessage({
type: "videoEnd",
pts: buffer.timestamp,
});
h264Arr = [];
} else if (buffer.byteLength != 1) {
// console.log("解码")
decoding = true;
videoDecoder.decode(buffer);
fpsCount = fpsCount + 1;
}
} catch (e) {
console.info(e);
decoding = false;
}
}
}
animationFrame();
});
}
// Startup.
function webCodes() {
videoDecoder = new VideoDecoder({
output: (videoFrame) => {
if (!playing) return;
self.postMessage(
{
type: "video",
data: videoFrame,
pts: videoFrame.timestamp,
},
[videoFrame]
);
decoding = false;
},
error: (error) => {
console.error(error);
},
});
videoDecoder.configure({
codec: "avc1.64001E",
codecWidth: width, //解码数据宽度
codecHeight: height, //解码数据高度
hardwareAcceleration: "prefer-hardware",
});
animationFrame();
playing = true;
decoding = false;
fpsTime = 0;
}
function start() {
webCodes();
console.log("webcodes success");
self.postMessage({
type: "loaded",
});
}
function reStart() {
webCodes();
console.log("reStart webcodes");
}
function getNowTime() {
if (performance && typeof performance.now === "function") {
return parseInt(performance.now());
}
return Date.now();
}
self.addEventListener(
"message",
function (e) {
var data = e.data;
switch (data.type) {
case "start":
width = data.width;
height = data.height;
start();
break;
case "reStart":
playing = false;
cancelAnimationFrame(animationFrameTimer);
videoDecoder.flush();
h264Arr = [];
missCount = 10;
reStart();
break;
case "destroy":
playing = false;
videoDecoder.flush();
cancelAnimationFrame(animationFrameTimer);
self.close(); // Terminates the worker.
break;
default:
if (playing) {
const chunk = new EncodedVideoChunk({
timestamp: data.timestamp, //视频帧的时间戳
type: true ? "key" : "delta", //是否是关键帧
data: data.buffer, //视频数据
});
h264Arr.push(chunk);
}
}
},
false
);
`; class WebCode extends VideoBasic { constructor(t) { super(t); const { flv: n } = t, { container: r } = n.options; this.canvas = r, this.worker = createWorker(webCodecsText), this.worker.onmessage = a => { const e = a.data; switch (e.type) { case "video": this.outVideoIndex++, this.videoFrames.push(e); break; case "videoEnd": this.outVideoIndex++, this.videoFrames.push(e); break; case "loaded": n.emit("workOn"); break } }, this.worker.postMessage({ type: "start" }); const l = this; n.on("destroy", () => { l.worker.postMessage({ type: "destroy" }), l.worker.terminate(), l.worker = null }), n.on("videoData", (a, e) => { this.inputVideoIndex++, l.worker.postMessage({ buffer: a, timestamp: e }, [a.buffer]) }) } workerReset() { console.log("webcodes restart"), this.worker.postMessage({ type: "reStart" }) } } class Decoder { constructor(t) { return window.VideoDecoder ? (console.info("Webcodec decode"), new WebCode(t)) : (console.info("wasm decode"), new Wasm(t)) } } var dist = { exports: {} }; (function (h, t) { (function (n, r) { h.exports = r() })(commonjsGlobal, function () { class n { constructor(l) { this.init(l) } init(l) { const a = { inputCodec: "Int16", channels: 1, sampleRate: 8e3, flushTime: 1e3 }; this.option = Object.assign({}, a, l), this.samples = new Float32Array, this.interval = setInterval(this.flush.bind(this), this.option.flushTime), this.convertValue = this.getConvertValue(), this.typedArray = this.getTypedArray(), this.initAudioContext(), this.bindAudioContextEvent() } getConvertValue() { const l = { Int8: 128, Int16: 32768, Int32: 2147483648, Float32: 1 }; if (!l[this.option.inputCodec]) throw new Error("wrong codec.please input one of these codecs:Int8,Int16,Int32,Float32"); return l[this.option.inputCodec] } getTypedArray() { const l = { Int8: Int8Array, Int16: Int16Array, Int32: Int32Array, Float32: Float32Array }; if (!l[this.option.inputCodec]) throw new Error("wrong codec.please input one of these codecs:Int8,Int16,Int32,Float32"); return l[this.option.inputCodec] } initAudioContext() { this.audioCtx = new (window.AudioContext || window.webkitAudioContext), this.gainNode = this.audioCtx.createGain(), this.gainNode.gain.value = .1, this.gainNode.connect(this.audioCtx.destination), this.startTime = this.audioCtx.currentTime } static isTypedArray(l) { return l.byteLength && l.buffer && l.buffer.constructor == ArrayBuffer || l.constructor == ArrayBuffer } isSupported(l) { if (!n.isTypedArray(l)) throw new Error("请传入ArrayBuffer或者任意TypedArray"); return !0 } feed(l) { this.isSupported(l), l = this.getFormattedValue(l); const a = new Float32Array(this.samples.length + l.length); a.set(this.samples, 0), a.set(l, this.samples.length), this.samples = a } getFormattedValue(l) { l.constructor == ArrayBuffer ? l = new this.typedArray(l) : l = new this.typedArray(l.buffer); let a = new Float32Array(l.length); for (let e = 0; e < l.length; e++)a[e] = l[e] / this.convertValue; return a } volume(l) { this.gainNode.gain.value = l } destroy() { this.interval && clearInterval(this.interval), this.samples = null, this.audioCtx.close(), this.audioCtx = null } flush() { if (!this.samples.length) return; const l = this; var a = this.audioCtx.createBufferSource(); typeof this.option.onended == "function" && (a.onended = function (_) { l.option.onended(this, _) }); const e = this.samples.length / this.option.channels, g = this.audioCtx.createBuffer(this.option.channels, e, this.option.sampleRate); for (let _ = 0; _ < this.option.channels; _++) { const y = g.getChannelData(_); let x = _, E = 50; for (let C = 0; C < e; C++)y[C] = this.samples[x], C < 50 && (y[C] = y[C] * C / 50), C >= e - 51 && (y[C] = y[C] * E-- / 50), x += this.option.channels } this.startTime < this.audioCtx.currentTime && (this.startTime = this.audioCtx.currentTime), a.buffer = g, a.connect(this.gainNode), a.start(this.startTime), this.startTime += g.duration, this.samples = new Float32Array } async pause() { await this.audioCtx.suspend() } async continue() { await this.audioCtx.resume() } bindAudioContextEvent() { const l = this; typeof l.option.onstatechange == "function" && (this.audioCtx.onstatechange = function (a) { l.audioCtx && l.option.onstatechange(this, a, l.audioCtx.state) }) } } return n }) })(dist); var distExports = dist.exports; const PCMPlayer$1 = getDefaultExportFromCjs(distExports); let AudioPlayer$1 = class { constructor(t) { const { flv: n } = t; this.playing = !1, this.paused = !1, this.audioPts = [], this.outAudioIndex = 0, this.inputAudioIndex = 0, this.volume = 1, this.audioCtrl = new PCMPlayer$1({ inputCodec: "Int16", channels: 1, sampleRate: 16e3, flushTime: 240, endCallback: () => { this.playing = !1 } }), this.audioCtrl.volume(this.volume), n.on("audioData", (r, l) => { this.audioPts.push({ pts: l, buffer: r }) }), n.on("destroy", () => { this.audioPts = null, this.audioCtrl.destroy(), this.audioCtrl = null }), n.on("timeupdate", r => { this.resume(); let l = 10; for (let a = 0; a < l; a++)this.feed(0) }) } get decoding() { return this.outAudioIndex !== this.inputAudioIndex } get framePlay() { return this.audioPts.length > 0 && this.playing } get getTimestamp() { var t; return (t = this.audioCtrl) == null ? void 0 : t.getTimestamp() } feed(t) { const n = this.audioPts[t]; if (!n) return !1; this.audioCtrl.feed(n.buffer), this.audioPts.shift() } play() { this.audioPts.length > 0 ? this.playing = !0 : this.playing = !1 } reset() { this.playing = !1, this.audioCtrl.destroy(), this.audioCtrl = new PCMPlayer$1({ inputCodec: "Int16", channels: 1, sampleRate: 16e3, flushTime: 240, endCallback: () => { this.playing = !1 } }), this.audioCtrl.volume(this.volume), this.audioPts = [], this.outAudioIndex = 0, this.inputAudioIndex = 0 } clearList() { this.audioPts = [], this.outAudioIndex = 0, this.inputAudioIndex = 0 } stop() { this.playing = !1, this.audioCtrl.pause() } pause() { this.paused == !1 && (console.log("audio pause......."), this.paused = !0, this.audioCtrl.pause()) } resume() { this.paused == !0 && (console.log("audio resume......."), this.paused = !1, this.audioCtrl.continue()) } playLastFrame() { console.log("playLastFrame", this.audioPts.length), this.audioPts.length > 0 && (this.audioPts.some(t => { this.audioCtrl.feed(t.buffer) }), this.audioPts = []) } }, Play$1 = class { constructor(t) { this.flv = t, this.streaming = !1, this.ended = !0, this.animationFrameTimer = null, this.decoder = new Decoder(this), this.audioDecoder = new AudioPlayer$1(this), this.sign = 0, this.resultSign = 0, this.playerStatus = "", this.currentTime = 0, this.lastUpdateTime = 0, t.on("destroy", () => { this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.animationFrameTimer && cancelAnimationFrame(this.animationFrameTimer), this.animationFrameTimer = null, this.ended = !0 }), t.on("streaming", () => { this.streaming = !0 }), t.on("streamEnd", () => { this.streaming = !1, this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null }) } init() { this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.currentTime = 0, this.lastUpdateTime = 0, this.animationFrame(), this.ended = !1 } animationFrame() { this.animationFrameTimer = requestAnimationFrame(() => { if (this.decoder.framePlay()) { const t = parseInt(getNowTime$1()); this.flv.stearmPtsH || (this.flv.stearmPtsH = !0, this.currentTime = 0, this.lastUpdateTime = t), this.currentTime += t - this.lastUpdateTime, this.lastUpdateTime = t, this.flv.emit("timeupdate", this.currentTime), this.playerStatus != "canplay" && (this.playerStatus = "canplay", this.flv.options.canPlay()) } else if (this.streaming || this.decoder.decoding || this.audioDecoder.decoding) { this.audioDecoder.pause(), this.waitingTimer = setTimeout(() => { !this.decoder.framePlay() && !this.audioDecoder.framePlay && this.playerStatus != "waiting" && (this.playerStatus = "waiting", this.flv.options.waiting()), this.lastUpdateTime = getNowTime$1(), this.play() }, 300); return } this.animationFrame() }) } play() { this.decoder.play(), this.audioDecoder.play(), this.animationFrame() } restart() { this.decoder.reset(), this.audioDecoder.reset(), this.currentTime = 0, this.lastUpdateTime = 0, this.playerStatus = "" } clearList() { this.decoder.clearList(), this.audioDecoder.clearList() } continue() { this.animationFrameTimer || (this.playerStatus = "canplay", this.lastUpdateTime = getNowTime$1(), this.animationFrame(), this.audioDecoder.resume(), this.flv.options.canPlay()) } stop() { this.playerStatus = "waiting", this.flv.options.waiting(), this.audioDecoder.pause(), this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.animationFrameTimer && cancelAnimationFrame(this.animationFrameTimer), this.animationFrameTimer = null } }, flvStearmLoad$1 = class extends Emitter$1 { constructor(t) { super(), this.options = Object.assign({ url: "", ...t }), this.timestamp = 0, this.audioTimestamp = 0, this.init(), this.stearmPtsH = !1 } init() { this.options.webcodeDisabled && (window.VideoDecoder = !1), this.render = new Decoder$1(this), this.player = new Play$1(this), this.on("workOn", () => { this.stearmInit(), this.player.init() }), this.timestamp = 0, this.audioTimestamp = 0 } stearmInit() { const t = this; this.socket = new WebSocket(this.options.url), this.socket.binaryType = "arraybuffer", this.socket.onopen = () => { t.options.cbOpen(t.socket), t.emit("streamStart") }, this.socket.onmessage = n => { t.options.cbMessage(t.socket, n, function (r, l) { if (l) { t.clearList(); return } t.emit("streaming"), r[0] === 80 && r[1] === 67 && r[2] === 77 ? (t.audioTimestamp += 40, t.emit("audioData", r.slice(3), t.audioTimestamp)) : (t.timestamp += 40, t.emit("videoData", r, t.timestamp)) }) }, this.socket.onerror = n => { throw t.options.cbError(t.socket, n), t.emit("streamError", n), n }, this.socket.onclose = () => { this.stearmPtsH = !1, t.options.cbClose(t.socket), t.emit("streamEnd") }, console.log(this.options.url) } destroy() { this.emit("destroy"), this.socket && (this.socket.close(), this.socket = null), this.render.destroy(), this.render = null } restart() { console.error("restart stream"), this.timestamp = 80, this.audioTimestamp = 0, this.stearmPtsH = !1, this.player.restart() } clearList() { this.player.clearList() } changeVolume(t) { console.log(this.player.audioDecoder), t ? (this.player.audioDecoder.volume = 0, this.player.audioDecoder.audioCtrl.volume(0)) : (this.player.audioDecoder.volume = 1, this.player.audioDecoder.audioCtrl.volume(1)) } playAudioLastFrame() { this.player.audioDecoder.playLastFrame() } }; const isPlat$2 = judgeEnvironment().includes("Chrome"); let ffmPlayer = null, pacemaker$2 = !1, websocket$2 = null, videoPlayerInit$1 = !1, interval$2 = 5, ffmcanvas = null, c2 = null, silentVideo$1 = null, videoWidth$2 = "", videoHeight$2 = "", reqRes$2 = null, playStatus = !1, serverEnded = !1, videoFlow = "", emitter$2 = new Emitter$2; const checkVideoStatus = debounce(() => { console.log("checkVideoStatus"), playStatus && videoFlow == "waiting" && serverEnded && (serverEnded = !1, emitter$2.emit("videoEnd"), websocket$2 == null || websocket$2.send(SendMsg.startAsr())) }, 280), checkCondition$2 = h => { "WebSocket" in window ? h(!0, "success") : h(!1, "当前浏览器不支持websocketio连接") }, webReconnect$1 = (h = !1) => { slientShowTarget(!0), ffmPlayer.restart(), videoPlayerInit$1 = !0 }, loopConnect$2 = () => { uninstallEvent$2(!1), startPlayer$2() }, pageAcitveStatusGet$2 = () => { (() => { setTimeout(() => { interval$2 += 5, interval$2 > 30 && (interval$2 = 30), loopConnect$2() }, interval$2 * 1e3) })() }, uninstallEvent$2 = (h = !0) => { pacemaker$2 = h, videoPlayerInit$1 = !1, heartPing.end(), ffmPlayer && (ffmPlayer.destroy(), ffmPlayer = null) }; let asrWsApp$2 = null; const startPlayer$2 = () => { let { _sign: h, _projectId: t, _drivertype: n, _volume: r, _asr: l, decodeType: a } = commonObj; ffmPlayer = new flvStearmLoad$1({ url: websocketInit$1({ _projectId: t, _sign: h, isPlat: isPlat$2, type: 0, _drivertype: n, requestVideo: requestVideo$2 }), width: videoWidth$2, height: videoHeight$2, container: ffmcanvas, webcodeDisabled: a == 2, cbOpen: function (e) { console.log("建立websocket", e), websocket$2 = e, l && asrWsApp$2 && asrWsApp$2(e), heartPing.start(() => { (websocket$2 == null ? void 0 : websocket$2.readyState) == 1 && (websocket$2 == null || websocket$2.send(JSON.stringify({ signal: "ping" }))) }) }, cbMessage: isPlat$2 ? function (e, g, _) { if (typeof g.data == "object") { const y = new Uint8Array(g.data); if (!(y[0] !== 72 || y[1] !== 80 || y[2] !== 67 || y[3] !== 77)) { videoPlayerInit$1 = !1, console.log("——————————loop new——————————————"), _(null, !0); return } videoPlayerInit$1 || _(y, videoPlayerInit$1) } else if (g.data != "ppg-end") { if (g.data.includes("requests overload")) pacemaker$2 = !0, emitter$2.emit("wsMessage", { type: "requests overload" }); else if (g.data.includes("{")) { const y = JSON.parse(g.data); y.type == "asr-part" || y.type == "asr" || y.type == "answer" ? emitter$2.emit("wsMessage", y) : y.type == "startAsr" || y.type == "startSleep" || y.type == "wakeup" || (y.type == "server_ready" ? emitter$2.emit("wsMessage", y) : y.type == "server_ended" || (y.type == "error" ? (emitter$2.emit("wsMessage", y), console.error(y.content)) : y.type == "node")) } } } : function (e, g, _) { const y = new Uint8Array(g.data); if (y[0] === 116 && y[1] === 101 && y[2] === 120 && y[3] === 116) { const x = get_text$1(y); if (x != "ppg-end") { if (x != "pong") { if (x.includes("requests overload")) pacemaker$2 = !0, emitter$2.emit("wsMessage", { type: "requests overload" }); else if (x.includes("{")) { const E = JSON.parse(x); E.type == "asr-part" || E.type == "asr" || E.type == "answer" ? emitter$2.emit("wsMessage", E) : E.type == "startAsr" || E.type == "startSleep" || E.type == "wakeup" || (E.type == "server_ready" ? emitter$2.emit("wsMessage", E) : E.type == "server_ended" || (E.type == "error" ? (emitter$2.emit("wsMessage", E), console.error(E.content)) : E.type == "node")) } } } } else { if (!(y[0] !== 72 || y[1] !== 80 || y[2] !== 67 || y[3] !== 77)) { videoPlayerInit$1 = !1, console.log("——————————loop new——————————————"), _(null, !0); return } videoPlayerInit$1 || _(y, videoPlayerInit$1) } }, cbError: function (e, g) { console.error("websocket错误:", g), emitter$2.emit("wsMessage", { type: "websocket Error", value: g }) }, cbClose: function (e) { console.error("websocket关闭!"), pacemaker$2 ? emitter$2.emit("wsMessage", { type: "websocket close" }) : (pageAcitveStatusGet$2(), emitter$2.emit("wsMessage", { type: "websocket reLoop" })) }, cbDestroy: function (e) { console.error("websocket销毁!") }, wxServerEnd: function () { console.log("-----wxServerEnd"), playStatus = !0, serverEnded = !0, checkVideoStatus() }, canPlay: function () { console.log("-----canPlay"), slientShowTarget(!1), webglCut.videoPlay(), videoFlow = "canplay", emitter$2.emit("videoStart") }, waiting: function () { console.log("-----waiting"), slientShowTarget(!0), webglCut.slicePlay(), videoFlow = "waiting", checkVideoStatus() } }) }; function displayEle$1(h, t) { h.style.display = t } const slientShowTarget = debounce(h => { h ? (displayEle$1(ffmcanvas, "none"), displayEle$1(c2, "inline")) : (displayEle$1(ffmcanvas, "inline"), displayEle$1(c2, "none")) }, 120); let requestVideo$2 = ""; function player$2(h, t, n, r, l = 1) {
videoWidth$2 = viewMap[t][r].width, videoHeight$2 = viewMap[t][r].height, requestVideo$2 = `requestWidth=${videoWidth$2}&requestHeight=${videoHeight$2}`, document.querySelector(h).innerHTML = `
`, ffmcanvas = querySelectorEl("#ffmcanvas"), c2 = querySelectorEl("#digitalPlayer"), silentVideo$1 = querySelectorEl("#silentVideo"), displayEle$1(ffmcanvas, "none"), displayEle$1(c2, "none")
} let xxPlayer$2 = class extends Emitter$2 { constructor({ environment: t, containerLable: n, token: r, projectId: l, quality: a, zoom: e, clientId: g, volume: _, asr: y }, x) { if (super(), y) { const { asrDestroy: E, asrWsAppoint: C, asrStart: L } = asrWs(A => { console.log(A, "mic") }); asrWsApp$2 = C, L() } emitter$2 = new Emitter$2, this.containerLable = n, commonObj._sign = r, commonObj._projectId = l, this.quality = a || 1, this.zoom = e || 1, commonObj._env = t || "prd", commonObj._volume = _ || 1, commonObj._asr = y || !1, commonObj.decodeType = x.data.decodeType, reqRes$2 = x, this.streamImg = !1 } init() { checkCondition$2(t => { if (t) { let { avatarSilenceUrl: n, avatarDirection: r } = reqRes$2.data; player$2(this.containerLable, r, n, this.quality, this.zoom), emitter$2.on("videoEnd", () => { this.emit("message", { type: "videoEnd", data: {} }) }), emitter$2.on("videoStart", () => { this.emit("message", { type: "videoStart", data: {} }) }), emitter$2.on("wsMessage", l => { this.emit("message", { type: "wsMessage", data: l }) }), emitter$2.on("initIos", () => { this.emit("intialSucccess", { type: "2" }) }), this.emit("intialSucccess", { type: "1" }) } else this.emit("intialError", msg) }) } playSilentvideo() { silentVideo$1 && silentVideo$1.play().then(t => { console.log("ffm交互静音视频播放") }).catch(t => { console.log("ffm交互静音视频播放失败-", t) }) } startPlay() { ffmcanvas && (console.log("xiaohui"), displayEle$1(ffmcanvas, "none")), webglCut.load(null, silentVideo$1, c2, t => { videoPlayerInit$1 = !0, webglCut.slicePlay(), displayEle$1(c2, "inline"), startPlayer$2(this.direction, this.quality), emitter$2.emit("initIos") }) } setClientId(t) { t ? commonObj._clientId = t : console.log("clientId不能为空") } stopPlay() { uninstallEvent$2(), emitter$2 = null, ffmcanvas = null, c2 = null, silentVideo$1 = null, videoWidth$2 = "", videoHeight$2 = "", reqRes$2 = null, this.streamImg = !1 } playQA(t, n) { websocket$2 == null || websocket$2.send(SendMsg.qa(t, n)), this.streamImg = !0 } interrupt() { websocket$2 == null || websocket$2.send(SendMsg.interrupt()), webglCut.slicePlay(), webReconnect$1(!0), this.streamImg = !1 } playText(t) { websocket$2 == null || websocket$2.send(SendMsg.text(t)) } playStreamText(t) { websocket$2 == null || websocket$2.send(SendMsg.streamText(t)) } playStreamTextStart(t, n) { websocket$2 == null || websocket$2.send(SendMsg.streamTextStart(t, n)), this.streamImg = !0 } playStreamTextEnd() { websocket$2 == null || websocket$2.send(SendMsg.streamTextEnd()) } playAudio(t) { websocket$2 == null || websocket$2.send(SendMsg.streamAudio(t)), this.streamImg = !0 } playAudioEnd() { websocket$2 == null || websocket$2.send(SendMsg.streamAudioEnd()) } playCurVideo() { this.streamImg && (websocket$2 == null || websocket$2.send(SendMsg.resumePlay()), ffmPlayer.player.continue()) } stopCurVideo() { this.streamImg && (websocket$2 == null || websocket$2.send(SendMsg.pausePlay()), ffmPlayer.player.stop()) } }; function webRtcPlayer(h) { h = typeof h < "u" ? h : {}; var t = this; this.cfg = typeof h.peerConnectionOptions < "u" ? h.peerConnectionOptions : {}, this.cfg.sdpSemantics = "unified-plan", this.cfg.offerExtmapAllowMixed = !1, this.pcClient = null, this.dcClient = null, this.tnClient = null, this._audio = null, this._volume = 1, this.sdpConstraints = { offerToReceiveAudio: 1, offerToReceiveVideo: 1, voiceActivityDetection: !1 }, this.dataChannelOptions = { ordered: !0 }, this.startVideoMuted = typeof h.startVideoMuted < "u" ? h.startVideoMuted : !1, this.autoPlayAudio = typeof h.autoPlayAudio < "u" ? h.autoPlayAudio : !0; const n = new URLSearchParams(window.location.search); this.useMic = n.has("useMic"), this.useMic; let r = location.hostname === "localhost" || location.hostname === "127.0.0.1", l = location.protocol === "https:"; this.useMic && !r && !l && (this.useMic = !1), this.latencyTestTimings = { TestStartTimeMs: null, UEReceiptTimeMs: null, UEPreCaptureTimeMs: null, UEPostCaptureTimeMs: null, UEPreEncodeTimeMs: null, UEPostEncodeTimeMs: null, UETransmissionTimeMs: null, BrowserReceiptTimeMs: null, FrameDisplayDeltaTimeMs: null, Reset: function () { this.TestStartTimeMs = null, this.UEReceiptTimeMs = null, this.UEPreCaptureTimeMs = null, this.UEPostCaptureTimeMs = null, this.UEPreEncodeTimeMs = null, this.UEPostEncodeTimeMs = null, this.UETransmissionTimeMs = null, this.BrowserReceiptTimeMs = null, this.FrameDisplayDeltaTimeMs = null }, SetUETimings: function (w) { this.UEReceiptTimeMs = w.ReceiptTimeMs, this.UEPreCaptureTimeMs = w.PreCaptureTimeMs, this.UEPostCaptureTimeMs = w.PostCaptureTimeMs, this.UEPreEncodeTimeMs = w.PreEncodeTimeMs, this.UEPostEncodeTimeMs = w.PostEncodeTimeMs, this.UETransmissionTimeMs = w.TransmissionTimeMs, this.BrowserReceiptTimeMs = Date.now(), this.OnAllLatencyTimingsReady(this) }, SetFrameDisplayDeltaTime: function (w) { this.FrameDisplayDeltaTimeMs == null && (this.FrameDisplayDeltaTimeMs = Math.round(w), this.OnAllLatencyTimingsReady(this)) }, OnAllLatencyTimingsReady: function (w) { } }, this.createWebRtcVideo = function () { var w = document.createElement("video"); if (w.id = "digital3DPlayer", w.playsInline = !0, w.disablepictureinpicture = !0, w.muted = t.startVideoMuted, w.autoplay = "autoplay", w.hidden = !0, w.addEventListener("loadedmetadata", function (S) { t.onVideoInitialised && t.onVideoInitialised() }, !0), "requestVideoFrameCallback" in HTMLVideoElement.prototype) { const S = (O, F) => { if (F.receiveTime && F.expectedDisplayTime) { const j = F.presentationTime - F.receiveTime; t.aggregatedStats.receiveToCompositeMs = j } w.requestVideoFrameCallback(S) }; w.requestVideoFrameCallback(S) } return w }, this.video = this.createWebRtcVideo(); const a = function (w) { }, e = function (w) { }, g = function (w) { }, _ = function (w) { if (w.track, w.track.kind == "audio") { y(w.streams[0]); return } else w.track.kind == "video" && (t.video.srcObject, w.streams[0]); { t.video.srcObject = w.streams[0]; return } }, y = function (w) { if (t.video.srcObject != w && t.video.srcObject && t.video.srcObject !== w) { let S = document.createElement("Audio"); if (t._audio = S, S.volume = t._volume, S.srcObject = w, t.autoPlayAudio) S.play(); else { let O = function () { S.play(), t.video.removeEventListener("click", O) }; t.video.addEventListener("click", O) } } }, x = function (w, S, O) { try { let F = w.createDataChannel(S, O); return F.binaryType = "arraybuffer", F.onopen = function (j) { t.onDataChannelConnected && t.onDataChannelConnected() }, F.onclose = function (j) { }, F.onmessage = function (j) { t.onDataChannelMessage && t.onDataChannelMessage(j.data) }, F } catch { return null } }, E = function (w) { w.candidate && w.candidate.candidate && t.onWebRtcCandidate(w.candidate) }, C = function (w) { w.createOffer(t.sdpConstraints).then(function (S) { L(S), w.setLocalDescription(S), t.onWebRtcOffer && t.onWebRtcOffer(S) }, function () { console.warn("Couldn't create offer") }) }, L = function (w) { w.sdp = w.sdp.replace("useinbandfec=1", "useinbandfec=1;stereo=1;sprop-maxcapturerate=48000") }, A = function (w) { w.SetBitrate && (w.onsignalingstatechange = a), w.oniceconnectionstatechange = e, w.onicegatheringstatechange = g, w.ontrack = _, w.onicecandidate = E }, I = function () { return t.aggregatedStats || (t.aggregatedStats = {}), function (w) { let S = {}; w.forEach(O => { O.type == "inbound-rtp" && !O.isRemote && (O.mediaType == "video" || O.id.toLowerCase().includes("video")) && (S.timestamp = O.timestamp, S.bytesReceived = O.bytesReceived, S.framesDecoded = O.framesDecoded, S.packetsLost = O.packetsLost, S.bytesReceivedStart = t.aggregatedStats && t.aggregatedStats.bytesReceivedStart ? t.aggregatedStats.bytesReceivedStart : O.bytesReceived, S.framesDecodedStart = t.aggregatedStats && t.aggregatedStats.framesDecodedStart ? t.aggregatedStats.framesDecodedStart : O.framesDecoded, S.timestampStart = t.aggregatedStats && t.aggregatedStats.timestampStart ? t.aggregatedStats.timestampStart : O.timestamp, t.aggregatedStats && t.aggregatedStats.timestamp && (t.aggregatedStats.bytesReceived && (S.bitrate = 8 * (S.bytesReceived - t.aggregatedStats.bytesReceived) / (S.timestamp - t.aggregatedStats.timestamp), S.bitrate = Math.floor(S.bitrate), S.lowBitrate = t.aggregatedStats.lowBitrate && t.aggregatedStats.lowBitrate < S.bitrate ? t.aggregatedStats.lowBitrate : S.bitrate, S.highBitrate = t.aggregatedStats.highBitrate && t.aggregatedStats.highBitrate > S.bitrate ? t.aggregatedStats.highBitrate : S.bitrate), t.aggregatedStats.bytesReceivedStart && (S.avgBitrate = 8 * (S.bytesReceived - t.aggregatedStats.bytesReceivedStart) / (S.timestamp - t.aggregatedStats.timestampStart), S.avgBitrate = Math.floor(S.avgBitrate)), t.aggregatedStats.framesDecoded && (S.framerate = (S.framesDecoded - t.aggregatedStats.framesDecoded) / ((S.timestamp - t.aggregatedStats.timestamp) / 1e3), S.framerate = Math.floor(S.framerate), S.lowFramerate = t.aggregatedStats.lowFramerate && t.aggregatedStats.lowFramerate < S.framerate ? t.aggregatedStats.lowFramerate : S.framerate, S.highFramerate = t.aggregatedStats.highFramerate && t.aggregatedStats.highFramerate > S.framerate ? t.aggregatedStats.highFramerate : S.framerate), t.aggregatedStats.framesDecodedStart && (S.avgframerate = (S.framesDecoded - t.aggregatedStats.framesDecodedStart) / ((S.timestamp - t.aggregatedStats.timestampStart) / 1e3), S.avgframerate = Math.floor(S.avgframerate)))), O.type == "track" && (O.trackIdentifier == "video_label" || O.kind == "video") && (S.framesDropped = O.framesDropped, S.framesReceived = O.framesReceived, S.framesDroppedPercentage = O.framesDropped / O.framesReceived * 100, S.frameHeight = O.frameHeight, S.frameWidth = O.frameWidth, S.frameHeightStart = t.aggregatedStats && t.aggregatedStats.frameHeightStart ? t.aggregatedStats.frameHeightStart : O.frameHeight, S.frameWidthStart = t.aggregatedStats && t.aggregatedStats.frameWidthStart ? t.aggregatedStats.frameWidthStart : O.frameWidth), O.type == "candidate-pair" && O.hasOwnProperty("currentRoundTripTime") && O.currentRoundTripTime != 0 && (S.currentRoundTripTime = O.currentRoundTripTime) }), t.aggregatedStats.receiveToCompositeMs && (S.receiveToCompositeMs = t.aggregatedStats.receiveToCompositeMs, t.latencyTestTimings.SetFrameDisplayDeltaTime(t.aggregatedStats.receiveToCompositeMs)), t.aggregatedStats = S, t.onAggregatedStats && t.onAggregatedStats(S) } }, D = async function (w) { if (w.addTransceiver("video", { direction: "recvonly" }), !t.useMic) w.addTransceiver("audio", { direction: "recvonly" }); else { let S = t.useMic ? { autoGainControl: !1, channelCount: 1, echoCancellation: !1, latency: 0, noiseSuppression: !1, sampleRate: 16e3, volume: 1 } : !1; const O = await navigator.mediaDevices.getUserMedia({ video: !1, audio: S }); if (O) for (const F of O.getTracks()) F.kind && F.kind == "audio" && w.addTransceiver(F, { direction: "sendrecv" }); else w.addTransceiver("audio", { direction: "recvonly" }) } }; this.setVideoEnabled = function (w) { t.video.srcObject.getTracks().forEach(S => S.enabled = w) }, this.startLatencyTest = function (w) { t.video && (t.latencyTestTimings.Reset(), t.latencyTestTimings.TestStartTimeMs = Date.now(), w(t.latencyTestTimings.TestStartTimeMs)) }, this.handleCandidateFromServer = function (w) { let S = new RTCIceCandidate(w); t.pcClient.addIceCandidate(S).then(O => { }) }, this.createOffer = function () { t.pcClient && (t.pcClient.close(), t.pcClient = null), t.pcClient = new RTCPeerConnection(t.cfg), D(t.pcClient).finally(function () { A(t.pcClient), t.dcClient = x(t.pcClient, "cirrus", t.dataChannelOptions), C(t.pcClient) }) }, this.receiveAnswer = function (w) { var S = new RTCSessionDescription(w); t.pcClient.setRemoteDescription(S); let O = t.pcClient.getReceivers(); for (let F of O) F.playoutDelayHint = 0 }, this.close = function () { t.pcClient && (t.pcClient.close(), t.pcClient = null), t.aggregateStatsIntervalId && clearInterval(t.aggregateStatsIntervalId) }, this.send = function (w) { t.dcClient && t.dcClient.readyState == "open" && t.dcClient.send(w) }, this.getStats = function (w) { t.pcClient && w && t.pcClient.getStats(null).then(S => { w(S) }) }, this.aggregateStats = function (w) { let S = I(), O = () => { t.getStats(S) }; t.aggregateStatsIntervalId = setInterval(O, w) }, this.changeVol = function (w) { this._volume = w, this._audio && (this._audio.volume = w) } } let webSocketUrl = null, successCallback = () => { }, failCallback = () => { }, interactiveTimeExpiredCallback = () => { }, kbEvent = document.createEvent("KeyboardEvent"); typeof kbEvent.initKeyboardEvent < "u"; let webRtcPlayerObj = null, ws; const WS_OPEN_STATE = 1; let lastTimeResized = new Date().getTime(), resizeTimeout, responseEventListeners = new Map, freezeFrameOverlay = null, shouldShowPlayOverlay = !0, freezeFrame = { receiving: !1, size: 0, jpeg: void 0, height: 0, width: 0, valid: !1 }, afk = { enabled: !0, warnTimeout: 9999999, closeTimeout: 10, active: !1, overlay: void 0, warnTimer: void 0, countdown: 0, countdownTimer: void 0 }, editTextButton, hiddenInput; function setOverlay(h, t, n) { let r = document.getElementById("videoPlayOverlay"); if (!r) { let a = document.getElementById("player"); r = document.createElement("div"), r.id = "videoPlayOverlay", a && a.appendChild(r) } for (; r.lastChild;)r.removeChild(r.lastChild); t && r.appendChild(t), n && r.addEventListener("click", function a(e) { n(e), r.removeEventListener("click", a) }); let l = r.classList; for (let a = l.length - 1; a >= 0; a--)l.remove(l[a]); r.classList.add(h) } function showConnectOverlay() { connect(), startAfkWarningTimer() } function showTextOverlay(h) { let t = document.createElement("div"); t.id = "messageOverlay", t.innerHTML = h || "", setOverlay("textDisplayState", t) } function showAfkOverlay() { stopAfkWarningTimer(), afk.overlay = document.createElement("div"), afk.overlay.id = "afkOverlay", setOverlay("clickableState", afk.overlay, h => { hideOverlay(), clearInterval(afk.countdownTimer), startAfkWarningTimer() }), afk.countdown = afk.closeTimeout, document.exitPointerLock(), afk.countdownTimer = setInterval(function () { afk.countdown--, afk.countdown == 0 && (hideOverlay(), ws.close(), clearInterval(afk.countdownTimer)) }, 1e3) } function hideOverlay() { setOverlay("hiddenState") } function startAfkWarningTimer() { afk.active = afk.enabled, resetAfkWarningTimer() } function stopAfkWarningTimer() { afk.active = !1 } let num = afk.warnTimeout, fiveMinuteTimer = null; function resetAfkWarningTimer() { afk.active && (num = afk.warnTimeout, clearTimeout(afk.warnTimer), clearInterval(afk.countdownTimer), clearInterval(fiveMinuteTimer), fiveMinuteTimer = setInterval(() => { num--, num === 0 && interactiveTimeExpiredCallback && interactiveTimeExpiredCallback(!0) }, 1e3), afk.warnTimer = setTimeout(function () { showAfkOverlay() }, afk.warnTimeout * 1e3)) } function createWebRtcOffer() { webRtcPlayerObj ? (console.log("Creating offer"), webRtcPlayerObj.createOffer()) : (console.log("WebRTC player not setup, cannot create offer"), showTextOverlay("Unable to setup video")) } function sendInputData(h) { webRtcPlayerObj && (interactiveTimeExpiredCallback && interactiveTimeExpiredCallback(!1), afk.active = afk.enabled, resetAfkWarningTimer(), webRtcPlayerObj.send(h)) } const ToClientMessageType = { QualityControlOwnership: 0, Response: 1, Command: 2, FreezeFrame: 3, UnfreezeFrame: 4, VideoEncoderAvgQP: 5, LatencyTest: 6, InitialSettings: 7 }; let VideoEncoderQP = "N/A"; function setupWebRtcPlayer(h, t) { webRtcPlayerObj = new webRtcPlayer(t), h.appendChild(webRtcPlayerObj.video), webRtcPlayerObj.onWebRtcOffer = function (l) { if (ws && ws.readyState === WS_OPEN_STATE) { let a = JSON.stringify(l); ws.send(a) } }, webRtcPlayerObj.onWebRtcCandidate = function (l) { ws && ws.readyState === WS_OPEN_STATE && ws.send(JSON.stringify({ type: "iceCandidate", candidate: l })) }, webRtcPlayerObj.onVideoInitialised = function () { ws && ws.readyState === WS_OPEN_STATE && shouldShowPlayOverlay && resizePlayerStyle() }, webRtcPlayerObj.onDataChannelConnected = function () { ws && ws.readyState === WS_OPEN_STATE && webRtcPlayerObj.video && webRtcPlayerObj.video.srcObject && webRtcPlayerObj.onVideoInitialised && (webRtcPlayerObj.onVideoInitialised(), successCallback && successCallback(ws)) }; function n() { let l = btoa(freezeFrame.jpeg.reduce((e, g) => e + String.fromCharCode(g), "")), a = document.getElementById("freezeFrameOverlay").childNodes[0]; a.src = "data:image/jpeg;base64," + l, a.onload = function () { freezeFrame.height = a.naturalHeight, freezeFrame.width = a.naturalWidth, resizeFreezeFrameOverlay(), shouldShowPlayOverlay ? resizePlayerStyle() : showFreezeFrameOverlay(), webRtcPlayerObj.setVideoEnabled(!1) } } function r(l) { freezeFrame.receiving || (freezeFrame.receiving = !0, freezeFrame.valid = !1, freezeFrame.size = 0, freezeFrame.jpeg = void 0), freezeFrame.size = new DataView(l.slice(1, 5).buffer).getInt32(0, !0); let a = l.slice(1 + 4); if (freezeFrame.jpeg) { let e = new Uint8Array(freezeFrame.jpeg.length + a.length); e.set(freezeFrame.jpeg, 0), e.set(a, freezeFrame.jpeg.length), freezeFrame.jpeg = e } else freezeFrame.jpeg = a, freezeFrame.receiving = !0, console.log(`received first chunk of freeze frame: ${freezeFrame.jpeg.length}/${freezeFrame.size}`); freezeFrame.jpeg.length === freezeFrame.size ? (freezeFrame.receiving = !1, freezeFrame.valid = !0, console.log(`received complete freeze frame ${freezeFrame.size}`), n()) : freezeFrame.jpeg.length > freezeFrame.size && (console.error(`received bigger freeze frame than advertised: ${freezeFrame.jpeg.length}/${freezeFrame.size}`), freezeFrame.jpeg = void 0, freezeFrame.receiving = !1) } return webRtcPlayerObj.onDataChannelMessage = function (l) { let a = new Uint8Array(l); if (a[0] === ToClientMessageType.QualityControlOwnership) { let e = a[1] !== 0; console.log("Received quality controller message, will control quality: " + e) } else if (a[0] === ToClientMessageType.Response) { let e = new TextDecoder("utf-16").decode(l.slice(1)); for (let g of responseEventListeners.values()) g(e) } else if (a[0] === ToClientMessageType.Command) { let e = new TextDecoder("utf-16").decode(l.slice(1)); console.log(e); let g = JSON.parse(e); g.command === "onScreenKeyboard" && showOnScreenKeyboard(g) } else if (a[0] === ToClientMessageType.FreezeFrame) r(a); else if (a[0] === ToClientMessageType.UnfreezeFrame) invalidateFreezeFrameOverlay(); else if (a[0] === ToClientMessageType.VideoEncoderAvgQP) VideoEncoderQP = new TextDecoder("utf-16").decode(l.slice(1)); else if (a[0] == ToClientMessageType.LatencyTest) { let e = new TextDecoder("utf-16").decode(l.slice(1)); console.log("Got latency timings from UE."), console.log(e); let g = JSON.parse(e); webRtcPlayerObj && webRtcPlayerObj.latencyTestTimings.SetUETimings(g) } else if (a[0] == ToClientMessageType.InitialSettings) { let e = new TextDecoder("utf-16").decode(l.slice(1)); JSON.parse(e) } else console.error(`unrecognized data received, packet ID ${a[0]}`) }, createWebRtcOffer(), webRtcPlayerObj.video } function onWebRtcAnswer(h) { webRtcPlayerObj.receiveAnswer(h), webRtcPlayerObj.onAggregatedStats = t => { let n = new Intl.NumberFormat(window.navigator.language, { maximumFractionDigits: 0 }), r = new Intl.NumberFormat(window.navigator.language, { maximumFractionDigits: 0, minimumIntegerDigits: 2 }), l = (t.timestamp - t.timestampStart) / 1e3, a = [], e = [60, 60]; for (let w = 0; w < e.length; w++)a.push(l % e[w]), l = l / e[w]; a.push(l); let g = a[0], _ = Math.floor(a[1]), y = Math.floor([a[2]]), x = "B", E = t.hasOwnProperty("bytesReceived") ? t.bytesReceived : 0, C = ["kB", "MB", "GB"]; for (let w = 0; w < C.length && !(E < 100 * 1e3); w++)E = E / 1e3, x = C[w]; document.getElementById("qualityStatus"); const L = 26, A = 35; let I = "", D = "lime"; VideoEncoderQP > A ? (D = "red", I += `Bad network connection
`) : VideoEncoderQP > L && (D = "orange", I += `Spotty network connection
`), I += `Duration: ${r.format(y)}:${r.format(_)}:${r.format(g)}
`, I += `Video Resolution: ${t.hasOwnProperty("frameWidth") && t.frameWidth && t.hasOwnProperty("frameHeight") && t.frameHeight ? t.frameWidth + "x" + t.frameHeight : "Chrome only"}
`, I += `Received (${x}): ${n.format(E)}
`, I += `Frames Decoded: ${t.hasOwnProperty("framesDecoded") ? n.format(t.framesDecoded) : "Chrome only"}
`, I += `Packets Lost: ${t.hasOwnProperty("packetsLost") ? n.format(t.packetsLost) : "Chrome only"}
`, I += `Bitrate (kbps): ${t.hasOwnProperty("bitrate") ? n.format(t.bitrate) : "Chrome only"}
`, I += `Framerate: ${t.hasOwnProperty("framerate") ? n.format(t.framerate) : "Chrome only"}
`, I += `Frames dropped: ${t.hasOwnProperty("framesDropped") ? n.format(t.framesDropped) : "Chrome only"}
`, I += `Net RTT (ms): ${t.hasOwnProperty("currentRoundTripTime") ? n.format(t.currentRoundTripTime * 1e3) : "Can't calculate"}
`, I += `Browser receive to composite (ms): ${t.hasOwnProperty("receiveToCompositeMs") ? n.format(t.receiveToCompositeMs) : "Chrome only"}
`, I += `Video Quantization Parameter: ${VideoEncoderQP}
` }, webRtcPlayerObj.aggregateStats(1 * 1e3), webRtcPlayerObj.latencyTestTimings.OnAllLatencyTimingsReady = function (t) { if (!t.BrowserReceiptTimeMs) return; let n = t.BrowserReceiptTimeMs - t.TestStartTimeMs, r = t.UEPreEncodeTimeMs == 0 || t.UEPreCaptureTimeMs == 0 ? "???" : t.UEPostEncodeTimeMs - t.UEPreCaptureTimeMs, l = t.UEPostCaptureTimeMs - t.UEPreCaptureTimeMs, a = t.UEPostEncodeTimeMs - t.UEPreEncodeTimeMs, e = t.UETransmissionTimeMs - t.UEReceiptTimeMs, g = n - e, _ = n - g - e, y = null, x = null; t.FrameDisplayDeltaTimeMs && t.BrowserReceiptTimeMs && (y = t.FrameDisplayDeltaTimeMs + n, x = y - g - e); let E = ""; E += `Net latency RTT (ms): ${g}
`, E += `UE Capture+Encode (ms): ${r}
`, E += `UE Capture (ms): ${l}
`, E += `UE Encode (ms): ${a}
`, E += `Total UE latency (ms): ${e}
`, E += `Browser send latency (ms): ${_}
`, E += t.FrameDisplayDeltaTimeMs && t.BrowserReceiptTimeMs ? `Browser receive latency (ms): ${t.FrameDisplayDeltaTimeMs}
` : "", E += x ? `Total browser latency (ms): ${x}
` : "", E += `Total latency (excluding browser) (ms): ${n}
`, E += y ? `Total latency (ms): ${y}
` : "", document.getElementById("LatencyStats").innerHTML = E } } function onWebRtcIce(h) { webRtcPlayerObj && webRtcPlayerObj.handleCandidateFromServer(h) } let styleWidth, styleHeight, styleTop, styleLeft, styleCursor = "default", styleAdditional; function resizePlayerStyleToFillWindow(h) { let t = h.getElementsByTagName("VIDEO"), n = window.innerHeight / window.innerWidth, r = h.clientHeight / h.clientWidth, l = t.videoHeight / t.videoWidth; isNaN(l) ? (styleWidth = window.innerWidth, styleHeight = window.innerHeight, styleTop = 0, styleLeft = 0, h.style = "top: " + styleTop + "px; left: " + styleLeft + "px; width: " + styleWidth + "px; height: " + styleHeight + "px; cursor: " + styleCursor + "; " + styleAdditional) : n < r ? (styleWidth = Math.floor(window.innerHeight / l), styleHeight = window.innerHeight, styleTop = 0, styleLeft = Math.floor((window.innerWidth - styleWidth) * .5), h.style = "top: " + styleTop + "px; left: " + styleLeft + "px; width: " + styleWidth + "px; height: " + styleHeight + "px; cursor: " + styleCursor + "; " + styleAdditional) : (styleWidth = window.innerWidth, styleHeight = Math.floor(window.innerWidth * l), styleTop = Math.floor((window.innerHeight - styleHeight) * .5), styleLeft = 0, h.style = "top: " + styleTop + "px; left: " + styleLeft + "px; width: " + styleWidth + "px; height: " + styleHeight + "px; cursor: " + styleCursor + "; " + styleAdditional) } function resizePlayerStyleToActualSize(h) { let t = h.getElementsByTagName("VIDEO"); if (t.length > 0) { styleWidth = t[0].videoWidth, styleHeight = t[0].videoHeight; let n = Math.floor((window.innerHeight - styleHeight) * .5), r = Math.floor((window.innerWidth - styleWidth) * .5); styleTop = n > 0 ? n : 0, styleLeft = r > 0 ? r : 0, h.style = "top: " + styleTop + "px; left: " + styleLeft + "px; width: " + styleWidth + "px; height: " + styleHeight + "px; cursor: " + styleCursor + "; " + styleAdditional } } function resizePlayerStyleToArbitrarySize(h) { h.getElementsByTagName("VIDEO"), h.style = "top: 0px; left: 0px; width: " + styleWidth + "px; height: " + styleHeight + "px; cursor: " + styleCursor + "; " + styleAdditional } function showFreezeFrameOverlay() { freezeFrame.valid && (freezeFrameOverlay.classList.add("freezeframeBackground"), freezeFrameOverlay.style.display = "block") } function invalidateFreezeFrameOverlay() { freezeFrameOverlay.style.display = "none", freezeFrame.valid = !1, freezeFrameOverlay.classList.remove("freezeframeBackground"), webRtcPlayerObj && webRtcPlayerObj.setVideoEnabled(!0) } function resizeFreezeFrameOverlay() { if (freezeFrame.width !== 0 && freezeFrame.height !== 0) { let h = 0, t = 0, n = 0, r = 0, l = document.getElementById("enlarge-display-to-fill-window-tgl"), a = document.getElementById("player"); if (l !== null && l.checked) { let g = window.innerWidth / window.innerHeight, _ = freezeFrame.width / freezeFrame.height; g < _ ? (h = window.innerWidth, t = Math.floor(window.innerWidth / _), n = Math.floor((window.innerHeight - t) * .5), r = 0) : (h = Math.floor(window.innerHeight * _), t = window.innerHeight, n = 0, r = Math.floor((window.innerWidth - h) * .5)) } else { let g = a.offsetWidth / a.offsetHeight, _ = freezeFrame.width / freezeFrame.height; g < _ ? (h = a.offsetWidth, t = Math.floor(a.offsetWidth / _), n = Math.floor((a.offsetHeight - t) * .5), r = 0) : (h = Math.floor(a.offsetHeight * _), t = a.offsetHeight, n = 0, r = Math.floor((a.offsetWidth - h) * .5)) } let e = document.getElementById("freezeFrameOverlay").childNodes[0]; freezeFrameOverlay.style.width = a.offsetWidth + "px", freezeFrameOverlay.style.height = a.offsetHeight + "px", freezeFrameOverlay.style.left = "0px", freezeFrameOverlay.style.top = "0px", e.style.width = h + "px", e.style.height = t + "px", e.style.left = r + "px", e.style.top = n + "px" } } function resizePlayerStyle(h) { let t = document.getElementById("player"); if (!t) return; if (updateVideoStreamSize(), t.classList.contains("fixed-size")) { setupMouseAndFreezeFrame(t); return } let n = document.getElementById("enlarge-display-to-fill-window-tgl"), r = window.innerWidth < t.videoWidth || window.innerHeight < t.videoHeight; n !== null ? n.checked || r ? resizePlayerStyleToFillWindow(t) : resizePlayerStyleToActualSize(t) : resizePlayerStyleToArbitrarySize(t), setupMouseAndFreezeFrame(t) } function setupMouseAndFreezeFrame(h) { h.getBoundingClientRect(), setupNormalizeAndQuantize(), resizeFreezeFrameOverlay() } function updateVideoStreamSize() { if (new Date().getTime() - lastTimeResized > 1e3) { if (!document.getElementById("player")) return; lastTimeResized = new Date().getTime() } else console.log("Resizing too often - skipping"), clearTimeout(resizeTimeout), resizeTimeout = setTimeout(updateVideoStreamSize, 1e3) } const MessageType = { IFrameRequest: 0, RequestQualityControl: 1, MaxFpsRequest: 2, AverageBitrateRequest: 3, StartStreaming: 4, StopStreaming: 5, LatencyTest: 6, RequestInitialSettings: 7, UIInteraction: 50, Command: 51, KeyDown: 60, KeyUp: 61, KeyPress: 62, MouseEnter: 70, MouseLeave: 71, MouseDown: 72, MouseUp: 73, MouseMove: 74, MouseWheel: 75, TouchStart: 80, TouchEnd: 81, TouchMove: 82, GamepadButtonPressed: 90, GamepadButtonReleased: 91, GamepadAnalog: 92 }; function emitDescriptor(h, t) { let n = JSON.stringify(t), r = new DataView(new ArrayBuffer(1 + 2 + 2 * n.length)), l = 0; r.setUint8(l, h), l++, r.setUint16(l, n.length, !0), l += 2; for (let a = 0; a < n.length; a++)r.setUint16(l, n.charCodeAt(a), !0), l += 2; sendInputData(r.buffer) } function emitUIInteraction(h) { emitDescriptor(MessageType.UIInteraction, h) } function setupNormalizeAndQuantize() { let h = document.getElementById("player"), t = h.getElementsByTagName("video"); h && t.length > 0 && (h.clientHeight / h.clientWidth, t[0].videoHeight / t[0].videoWidth) } function showOnScreenKeyboard(h) { if (h.showOnScreenKeyboard) { editTextButton.classList.remove("hiddenState"); let t = unquantizeAndDenormalizeUnsigned(h.x, h.y); editTextButton.style.top = t.y.toString() + "px", editTextButton.style.left = (t.x - 40).toString() + "px" } else editTextButton.classList.add("hiddenState"), hiddenInput.blur() } function start() { let h = document.getElementById("qualityStatus"); h && (h.className = "grey-status"); let t = document.getElementById("stats"); t && (t.innerHTML = "Not connected"), showConnectOverlay(), shouldShowPlayOverlay = !0, resizePlayerStyle(), updateKickButton(0) } function updateKickButton(h) { let t = document.getElementById("kick-other-players-button"); t && (t.value = `Kick (${h})`) } function get_text(h) { return String.fromCharCode.apply(null, new Uint8Array(h.slice(0, 5))) == "text:" ? new TextDecoder("utf-8").decode(new Uint8Array(h.slice(5))) : "" } function connect() { if (window.WebSocket = window.WebSocket || window.MozWebSocket, !window.WebSocket) { alert("Your browser doesn't support WebSocket"); return } console.log("webSocketUrl:", webSocketUrl), ws = new WebSocket(webSocketUrl), ws.binaryType = "arraybuffer", ws.onmessage = function (t) { let n = t.data; const r = new Uint8Array(t.data); r[0] === 116 && r[1] === 101 && r[2] === 120 && r[3] === 116 && (n = get_text(r)); let l = JSON.parse(n); l.type === "config" ? onConfig(l) : l.type === "playerCount" ? updateKickButton(l.count - 1) : l.type === "answer" ? onWebRtcAnswer(l) : l.type === "iceCandidate" && onWebRtcIce(l.candidate) }, ws.onerror = function (t) { console.log(`WS error: ${JSON.stringify(t)}`) }; let h = null; ws.onclose = function (t) { clearInterval(fiveMinuteTimer), clearTimeout(afk.warnTimer), clearInterval(afk.countdownTimer), ws = void 0; let n = document.getElementById("player"); webRtcPlayerObj && (n && n.removeChild(webRtcPlayerObj.video), webRtcPlayerObj.close(), webRtcPlayerObj = void 0), failCallback && failCallback(), h = setTimeout(start, 4e3), clearTimeout(h) } } function onConfig(h) { let t = document.getElementById("player"); setupWebRtcPlayer(t, h), resizePlayerStyle() } function close$1() { ws && ws.close() } function load(h) { h.successCallback && (successCallback = h.successCallback), h.failCallback && (failCallback = h.failCallback), h.totalTimeExpiredCallback && h.totalTimeExpiredCallback, h.interactiveTimeExpiredCallback && (interactiveTimeExpiredCallback = h.interactiveTimeExpiredCallback), h.webSocketUrl && (webSocketUrl = h.webSocketUrl), start() } function changeVol(h) { webRtcPlayerObj.video.volume = h, webRtcPlayerObj.changeVol(h) } let webrtc = { load, resizePlayerStyle, emitUIInteraction, close: close$1, changeVol }; const isPlat$1 = judgeEnvironment().includes("Chrome"); let pacemaker$1 = !1, websocket$1 = null, rtccanvas = null, digital3D = null, interval$1 = 5, videoWidth$1 = "", videoHeight$1 = "", reqRes$1 = null, emitter$1 = new Emitter$2; const lvCutInitStart = () => { const h = commonObj.scene == "1" || commonObj.scene == null || commonObj.sceneId >= 1e3 ? "" : "fragment-shader-nocut"; digital3D = querySelectorEl("#digital3DPlayer"), console.log("---digital3D", digital3D), digital3D.width = videoWidth$1, digital3D.height = videoHeight$1, webglCut.load(digital3D, null, rtccanvas, () => { webglCut.videoPlay() }, h), emitter$1.emit("init3d") }, checkCondition$1 = h => { "WebSocket" in window ? h(!0, "success") : h(!1, "当前浏览器不支持websocketio连接") }, loopConnect$1 = () => { uninstallEvent$1(!1), startPlayer$1() }, pageAcitveStatusGet$1 = () => { (() => { setTimeout(() => { interval$1 += 5, interval$1 > 30 && (interval$1 = 30), loopConnect$1() }, interval$1 * 1e3) })() }, uninstallEvent$1 = (h = !0) => { pacemaker$1 = h, heartPing.end(), close(), websocket$1 && (websocket$1.close(), websocket$1 = null) }, initWebSocket = h => { const t = h.ws(); websocket$1 = t, t.binaryType = "arraybuffer", t.onopen = h.cbOpen, t.onclose = h.cbClose, t.onmessage = h.cbMessage, t.onerror = h.cbError }; let asrWsApp$1 = null; const startPlayer$1 = () => { let { _sign: h, _projectId: t, _drivertype: n, _volume: r, _asr: l } = commonObj; initWebSocket({ cbOpen: function (a) { console.log("建立websocket", a), l && asrWsApp$1 && asrWsApp$1(websocket$1), heartPing.start(() => { (websocket$1 == null ? void 0 : websocket$1.readyState) == 1 && (websocket$1 == null || websocket$1.send(JSON.stringify({ signal: "ping" }))) }), pacemaker$1 = !1 }, cbMessage: isPlat$1 ? function (a) { if (typeof a.data == "object") new Uint8Array(a.data); else if (a.data != "ppg-end") { if (a.data.includes("requests overload")) pacemaker$1 = !0, emitter$1.emit("wsMessage", { type: "requests overload" }); else if (a.data.includes("{")) { const e = JSON.parse(a.data); e.type == "asr-part" ? emitter$1.emit("wsMessage", e) : e.type == "asr" ? e != null && e.resultType ? emitter$1.emit("wsMessage", e) : emitter$1.emit("videoStart") : e.type == "answer" ? emitter$1.emit("wsMessage", e) : e.type == "startAsr" ? (emitter$1.emit("videoEnd"), websocket$1 == null || websocket$1.send(SendMsg.startAsr())) : e.type == "startSleep" || e.type == "wakeup" || (e.type == "server_ready" ? (console.error("可以发送语音文件"), emitter$1.emit("wsMessage", e)) : e.type == "server_ended" || (e.type == "error" ? (emitter$1.emit("wsMessage", e), console.error(e.content)) : e.type == "node" || e.type == "server_url" && (console.log("2----------3d---到这里"), treeDOpen(`wss://${e.content}`)))) } } } : function (a) { const e = new Uint8Array(a.data); if (e[0] === 116 && e[1] === 101 && e[2] === 120 && e[3] === 116) { const g = get_text$1(e); if (g != "ppg-end") { if (g != "pong") { if (g.includes("requests overload")) pacemaker$1 = !0, emitter$1.emit("wsMessage", { type: "requests overload" }); else if (g.includes("{")) { const _ = JSON.parse(g); _.type == "asr-part" ? emitter$1.emit("wsMessage", _) : _.type == "asr" ? _ != null && _.resultType ? emitter$1.emit("wsMessage", _) : emitter$1.emit("videoStart") : _.type == "answer" ? emitter$1.emit("wsMessage", _) : _.type == "startAsr" ? emitter$1.emit("videoEnd") : _.type == "startSleep" || _.type == "wakeup" || (_.type == "server_ready" ? (console.error("可以发送语音文件"), emitter$1.emit("wsMessage", _)) : _.type == "server_ended" || (_.type == "error" ? (emitter$1.emit("wsMessage", _), console.error(_.content)) : _.type == "node" || _.type == "server_url" && (console.log("1----------3d---到这里"), treeDOpen(`wss://${_.content}`)))) } } } } }, cbError: function (a) { console.error("websocket错误:", a), emitter$1.emit("wsMessage", { type: "websocket Error", value: a }) }, cbClose: function (a) { console.error("websocket关闭:", a), pacemaker$1 ? emitter$1.emit("wsMessage", { type: "websocket close" }) : (pageAcitveStatusGet$1(), emitter$1.emit("wsMessage", { type: "websocket reLoop" })) }, ws: websocketInit$1({ _projectId: t, _sign: h, isPlat: isPlat$1, type: 1, _drivertype: n, requestVideo: requestVideo$1 }) }) }, treeDOpen = h => { setTimeout(() => { webrtc.load({ webSocketUrl: h, successCallback: t => { console.log("回调成功"), lvCutInitStart(); let n = setInterval(() => { (t == null ? void 0 : t.readyState) == 3 ? clearInterval(n) : t == null || t.send(JSON.stringify({ signal: "ping" })) }, 1e4) }, totalTimeExpiredCallback: t => { console.log("totalTimeExpiredCallback") }, interactiveTimeExpiredCallback: t => { console.log("interactiveTimeExpiredCallback") }, failCallback: t => { console.log("failCallback") } }) }) }, close = () => { webrtc.close() }; let requestVideo$1 = ""; function player$1(h, t, n, r, l = 1) {
videoWidth$1 = viewMap[t][r].width, videoHeight$1 = viewMap[t][r].height, requestVideo$1 = `requestWidth=${videoWidth$1}&requestHeight=${videoHeight$1}`, document.querySelector(h).innerHTML = `
`, rtccanvas = querySelectorEl("#rtccanvas")
} let xxPlayer$1 = class extends Emitter$2 { constructor({ environment: t, containerLable: n, token: r, projectId: l, quality: a, zoom: e, volume: g, asr: _ }, y) { if (super(), _) { const { asrDestroy: x, asrWsAppoint: E, asrStart: C } = asrWs(L => { console.log(L, "mic") }); asrWsApp$1 = E, C() } emitter$1 = new Emitter$2, this.containerLable = n, commonObj._sign = r, commonObj._projectId = l, this.quality = a || 1, this.zoom = e || 1, commonObj._env = t || "prd", commonObj._volume = g || 1, commonObj._asr = _ || !1, reqRes$1 = y } init() { checkCondition$1(t => { if (t) { let { avatarSilenceUrl: n, avatarDirection: r, scene: l } = reqRes$1.data, a = l; if (l.trim().startsWith("{")) { let e = JSON.parse(l); e.id && (a = e.id) } commonObj.scene = a == 1 || a >= 1e3 ? "1" : "2", player$1(this.containerLable, r, n, this.quality, this.zoom), emitter$1.on("videoEnd", () => { this.emit("message", { type: "videoEnd", data: {} }) }), emitter$1.on("videoStart", () => { this.emit("message", { type: "videoStart", data: {} }) }), emitter$1.on("wsMessage", e => { this.emit("message", { type: "wsMessage", data: e }) }), emitter$1.on("init3d", e => { this.emit("intialSucccess", { type: "2" }) }), this.emit("intialSucccess", { type: "1" }) } else this.emit("intialError", msg) }) } playSilentvideo() { const t = document.querySelector("#digital3DPlayer"); return t == null ? void 0 : t.play() } startPlay() { startPlayer$1() } setClientId(t) { t ? commonObj._clientId = t : console.log("clientId不能为空") } stopPlay() { uninstallEvent$1(), emitter$1 = null, rtccanvas = null, digital3D = null, reqRes$1 = null } playQA(t, n) { websocket$1 == null || websocket$1.send(SendMsg.qa(t, n)) } interrupt() { websocket$1 == null || websocket$1.send(SendMsg.interrupt()) } playText(t) { websocket$1 == null || websocket$1.send(SendMsg.text(t)) } playStreamText(t) { websocket$1 == null || websocket$1.send(SendMsg.streamText(t)) } playStreamTextStart(t, n) { websocket$1 == null || websocket$1.send(SendMsg.streamTextStart(t, n)) } playStreamTextEnd() { websocket$1 == null || websocket$1.send(SendMsg.streamTextEnd()) } playAudio(t) { websocket$1 == null || websocket$1.send(SendMsg.streamAudio(t)) } playAudioEnd() { websocket$1 == null || websocket$1.send(SendMsg.streamAudioEnd()) } playCurVideo() { websocket$1 == null || websocket$1.send(SendMsg.resumePlay()) } stopCurVideo() { websocket$1 == null || websocket$1.send(SendMsg.pausePlay()) } }; const websocketInit = (h, t, n, r) => { h && !h.includes("ws") && (h = `${h.includes("https") ? "wss:" : "ws:"}//${h.split("//")[1]}`); let l = `${h || "wss://wenyan-avatar.mobvoi.com"}/websocket/wenyan/asr/${n}?projectId=${t}&holdTalk=1`, a = new WebSocket(l); return a.binaryType = "arraybuffer", a.onopen = function (e) { console.log("客户端连接成功"), a.send(JSON.stringify({ signal: "start" })) }, a.onmessage = function (e) { const g = e.data ? JSON.parse(e.data) : {}; r(g), g.type == "asr" && a.close() }, a.onerror = function (e) { console.log("连接失败了", e) }, a.onclose = function () { a = null }, a }, micro = (h, t) => { if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { let { recStart: n, recStop: r, recRecord: l } = jsRecorder(function (a) { h(a) }, () => { t({ type: "1", val: "获取麦克权限成功" }) }, () => { t({ type: "0", val: "获取麦克权限失败" }) }); return { recStart: n, recStop: r, recRecord: l } } else t({ type: "0", val: "环境不支持!" }) }; function asrPlayer({ host: h, _projectId: t, token: n, cb: r }) { if (!t || !n) { r({ type: "error", value: "参数缺失" }); return } let l = null, a = !1; const { recStart: e, recStop: g, recRecord: _ } = micro(function (A) { try { (l == null ? void 0 : l.readyState) == 1 && l.send(A) } catch (I) { console.log(I) } }, function (A) { A.type == "1" && r(A) }) || {}; return { asrStart: () => { if (e) { if (a) return r({ type: "0", val: "请先stop" }); a = !0, e(), l = websocketInit(h, t, n, A => { r(A) }) } }, asrStop: () => { if (g) { if (!a) return r({ type: "0", val: "请误重复stop" }); a = !1, l.send(JSON.stringify({ signal: "end" })), g() } }, asrSignStart: () => { l.send(JSON.stringify({ signal: "start" })) }, asrSignEnd: () => { l.send(JSON.stringify({ signal: "end" })) }, asrDestroy: () => { l && l.close(), l = null, console.log("ws 关闭") } } } class Emitter { on(t, n, r) { const l = this.e || (this.e = {}); return (l[t] || (l[t] = [])).push({ fn: n, ctx: r }), this } once(t, n, r) { const l = this; function a(...e) { l.off(t, a), n.apply(r, e) } return a._ = n, this.on(t, a, r) } emit(t, ...n) { const r = ((this.e || (this.e = {}))[t] || []).slice(); for (let l = 0; l < r.length; l += 1)r[l].fn.apply(r[l].ctx, n); return this } off(t, n) { const r = this.e || (this.e = {}), l = r[t], a = []; if (l && n) for (let e = 0, g = l.length; e < g; e += 1)l[e].fn !== n && l[e].fn._ !== n && a.push(l[e]); return a.length ? r[t] = a : delete r[t], this } } function getNowTime() { return performance && typeof performance.now == "function" ? performance.now() : Date.now() } const PCMPlayer = function () { function h(t) { this.init(t) } return h.prototype.init = function (t) { var n = { encoding: "16bitInt", channels: 1, sampleRate: 16e3, flushingTime: 240 }; this.option = Object.assign({}, n, t), this.samples = new Float32Array, this.flush = this.flush.bind(this), this.interval = setInterval(this.flush, this.option.flushingTime), this.maxValue = this.getMaxValue(), this.typedArray = this.getTypedArray(), this.createContext() }, h.prototype.getMaxValue = function () { var t = { "8bitInt": 128, "16bitInt": 32768, "32bitInt": 2147483648, "32bitFloat": 1 }; return t[this.option.encoding] ? t[this.option.encoding] : t["16bitInt"] }, h.prototype.getTypedArray = function () { var t = { "8bitInt": Int8Array, "16bitInt": Int16Array, "32bitInt": Int32Array, "32bitFloat": Float32Array }; return t[this.option.encoding] ? t[this.option.encoding] : t["16bitInt"] }, h.prototype.createContext = function () { this.audioCtx = new (window.AudioContext || window.webkitAudioContext), this.gainNode = this.audioCtx.createGain(), this.gainNode.gain.value = 1, this.gainNode.connect(this.audioCtx.destination), this.startTime = this.audioCtx.currentTime }, h.prototype.isTypedArray = function (t) { return t.byteLength && t.buffer && t.buffer.constructor == ArrayBuffer }, h.prototype.feed = function (t) { if (this.isTypedArray(t)) { t = this.getFormatedValue(t); var n = new Float32Array(this.samples.length + t.length); n.set(this.samples, 0), n.set(t, this.samples.length), this.samples = n } }, h.prototype.getFormatedValue = function (n) { var n = new this.typedArray(n.buffer), r = new Float32Array(n.length), l; for (l = 0; l < n.length; l++)r[l] = n[l] / this.maxValue; return r }, h.prototype.volume = function (t) { this.gainNode.gain.value = t }, h.prototype.destroy = function () { this.interval && clearInterval(this.interval), this.samples = null, this.audioCtx.close(), this.audioCtx = null }, h.prototype.flush = function () { if (this.samples.length) { var t = this.audioCtx.createBufferSource(), n = this.samples.length / this.option.channels, r = this.audioCtx.createBuffer(this.option.channels, n, this.option.sampleRate), l, a, e, g, _; for (a = 0; a < this.option.channels; a++)for (l = r.getChannelData(a), e = a, _ = 50, g = 0; g < n; g++)l[g] = this.samples[e], g < 50 && (l[g] = l[g] * g / 50), g >= n - 51 && (l[g] = l[g] * _-- / 50), e += this.option.channels; this.startTime < this.audioCtx.currentTime && (this.startTime = this.audioCtx.currentTime), t.buffer = r, t.connect(this.gainNode), t.start(this.startTime), this.startTime += r.duration, this.samples = new Float32Array } }, h.prototype.getTimestamp = function () { return this.audioCtx ? this.audioCtx.currentTime : 0 }, h.prototype.play = function (t) { if (this.isTypedArray(t) && (t = this.getFormatedValue(t), !!t.length)) { var n = this.audioCtx.createBufferSource(), r = t.length / this.option.channels, l = this.audioCtx.createBuffer(this.option.channels, r, this.option.sampleRate), a, e, g, _, y; for (e = 0; e < this.option.channels; e++)for (a = l.getChannelData(e), g = e, y = 50, _ = 0; _ < r; _++)a[_] = t[g], _ < 50 && (a[_] = a[_] * _ / 50), _ >= r - 51 && (a[_] = a[_] * y-- / 50), g += this.option.channels; this.startTime < this.audioCtx.currentTime && (this.startTime = this.audioCtx.currentTime), n.buffer = l, n.connect(this.gainNode), n.start(this.startTime), n.onended = () => { this.option.endCallback() }, this.startTime += l.duration } }, h.prototype.pause = function () { this.audioCtx.state === "running" && this.audioCtx.suspend() }, h.prototype.resume = function () { this.audioCtx.state === "suspended" && this.audioCtx.resume() }, h }(); class AudioPlayer { constructor(t) { const { flv: n } = t; this.playing = !1, this.audioPts = [], this.outAudioIndex = 0, this.inputAudioIndex = 0, this.volume = n.options.volume, this.audioCtrl = new PCMPlayer({ encoding: "16bitInt", channels: 1, sampleRate: 16e3, endCallback: () => { this.playing = !1 } }), this.audioCtrl.volume(this.volume), n.on("audioData", (r, l) => { this.outAudioIndex++, this.audioCtrl.feed(r), this.audioPts.push({ pts: l }) }), n.on("destroy", () => { this.audioPts = [], this.audioCtrl.destroy() }), n.on("timeupdate", r => { const l = this.audioPts[0].pts; l && r > l && this.feed(0) }) } get decoding() { return this.outAudioIndex !== this.inputAudioIndex } get framePlay() { return this.audioPts.length > 0 && this.playing } get getTimestamp() { var t; return (t = this.audioCtrl) == null ? void 0 : t.getTimestamp() } feed(t) { if (this.inputAudioIndex++, !this.audioPts[t]) return !1; this.audioPts.shift() } play() { this.audioPts.length > 0 ? (this.playing = !0, this.audioCtrl.resume()) : this.playing = !1 } reset() { this.playing = !1, this.audioCtrl.destroy(), this.audioCtrl = new PCMPlayer({ encoding: "16bitInt", channels: 1, sampleRate: 16e3, endCallback: () => { this.playing = !1 } }), this.audioCtrl.volume(this.volume), this.audioPts = [], this.outAudioIndex = 0, this.inputAudioIndex = 0 } stop() { this.playing = !1, this.audioCtrl.pause() } resume() { this.playing = !0, this.audioCtrl.resume() } } class Play { constructor(t) { this.flv = t, this.streaming = !1, this.ended = !0, this.animationFrameTimer = null, this.audioDecoder = new AudioPlayer(this), this.sign = 0, this.resultSign = 0, this.playerStatus = "", this.currentTime = 0, this.lastUpdateTime = 0, t.on("destroy", () => { this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.animationFrameTimer && cancelAnimationFrame(this.animationFrameTimer), this.animationFrameTimer = null, this.ended = !0 }), t.on("streaming", () => { this.streaming = !0 }), t.on("streamEnd", () => { this.streaming = !1, this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null }) } init() { this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.currentTime = 0, this.lastUpdateTime = 0, this.animationFrame(), this.ended = !1 } animationFrame() { this.animationFrameTimer = requestAnimationFrame(() => { if (this.audioDecoder.framePlay) { this.flv.stearmPtsH || (this.flv.stearmPtsH = !0, this.currentTime = 0, this.flv.options.canPlay()); const t = getNowTime(); this.currentTime += t - this.lastUpdateTime, this.lastUpdateTime = t, this.flv.emit("timeupdate", this.currentTime) } else if (this.streaming || this.audioDecoder.decoding) { this.audioDecoder.stop(), this.waitingTimer = setTimeout(() => { this.lastUpdateTime = getNowTime(), this.play(), this.audioDecoder.framePlay ? this.playerStatus != "canplay" && (this.playerStatus = "canplay", this.flv.options.canPlay(), this.flv.stearmPtsH = !0) : this.playerStatus != "waiting" && (this.playerStatus = "waiting", this.flv.options.waiting()) }, 200); return } this.animationFrame() }) } play() { this.audioDecoder.play(), this.animationFrame() } restart() { this.audioDecoder.reset(), this.currentTime = 0, this.lastUpdateTime = 0, this.playerStatus = "" } continue() { this.lastUpdateTime = getNowTime(), this.audioDecoder.resume(), this.animationFrame() } stop() { this.audioDecoder.stop(), this.waitingTimer && clearTimeout(this.waitingTimer), this.waitingTimer = null, this.animationFrameTimer && cancelAnimationFrame(this.animationFrameTimer), this.animationFrameTimer = null } } class flvStearmLoad extends Emitter { constructor(t) { super(), this.options = Object.assign({ url: "", volume: 1, ...t }), this.audioTimestamp = 0, this.init(), this.stearmPtsH = !1 } init() { this.options.webcodeDisabled && (window.VideoDecoder = !1), this.player = new Play(this), this.stearmInit(), this.player.init(), this.audioTimestamp = 0 } stearmInit() { const t = this; this.socket = new WebSocket(this.options.url), this.socket.binaryType = "arraybuffer", this.socket.onopen = () => { t.options.cbOpen(t.socket), t.emit("streamStart") }, this.socket.onmessage = n => { t.options.cbMessage(t.socket, n, function (r, l) { if (r.byteLength == 1) { t.options.wxServerEnd(); return } t.emit("streaming"), r[0] === 80 && r[1] === 67 && r[2] === 77 && (t.audioTimestamp += 40, t.emit("audioData", r.slice(3), t.audioTimestamp)) }) }, this.socket.onerror = n => { throw t.options.cbError(t.socket, n), t.emit("streamError", n), n }, this.socket.onclose = () => { this.stearmPtsH = !1, t.options.cbClose(t.socket), t.emit("streamEnd") }, console.log(this.options.url) } destroy() { this.emit("destroy") } restart() { console.error("restart"), this.audioTimestamp = 0, this.stearmPtsH = !1, this.player.restart() } changeVolume(t) { t ? this.player.audioDecoder.audioCtrl.volume(0) : this.player.audioDecoder.audioCtrl.volume(this.options.volume) } } const isPlat = judgeEnvironment().includes("Chrome"); let cartoonPlayer = null, pacemaker = !1, websocket = null, videoPlayerInit = !1, interval = 5, screenCanvas = null, avatarVideo = null, silentVideo = null, videoWidth = "", videoHeight = "", reqRes = null, emitter = new Emitter$2; const checkCondition = h => { "WebSocket" in window ? h(!0, "success") : h(!1, "当前浏览器不支持websocketio连接") }, webReconnect = (h = !1) => { videoPlayerInit = !0, cartoonPlayer.restart() }, loopConnect = () => { uninstallEvent(!1), startPlayer() }, pageAcitveStatusGet = () => { (() => { setTimeout(() => { interval += 5, interval > 30 && (interval = 30), loopConnect() }, interval * 1e3) })() }, uninstallEvent = (h = !0) => { pacemaker = h, videoPlayerInit = !1, heartPing.end(), cartoonPlayer && (cartoonPlayer == null || cartoonPlayer.destroy(), cartoonPlayer = null), websocket && (websocket.close(), websocket = null) }; let asrWsApp = null; const startPlayer = () => { let { _sign: h, _projectId: t, _drivertype: n, _volume: r, _asr: l } = commonObj; cartoonPlayer = new flvStearmLoad({ url: websocketInit$1({ _projectId: t, _sign: h, isPlat, type: 0, _drivertype: n, requestVideo }), volume: r, cbOpen: function (a) { console.error("建立websocket", a), websocket = a, l && asrWsApp && asrWsApp(a), heartPing.start(() => { (websocket == null ? void 0 : websocket.readyState) == 1 && (websocket == null || websocket.send(JSON.stringify({ signal: "ping" }))) }) }, cbMessage: isPlat ? function (a, e, g) { if (typeof e.data == "object") { const _ = new Uint8Array(e.data); _[0] !== 72 || _[1] !== 80 || _[2] !== 67 || _[3] !== 77 || (videoPlayerInit = !1, console.log("——————————loop new——————————————")), g(_, videoPlayerInit) } else if (e.data != "ppg-end") { if (e.data.includes("requests overload")) pacemaker = !0, emitter.emit("wsMessage", { type: "requests overload" }); else if (e.data.includes("{")) { const _ = JSON.parse(e.data); _.type == "asr-part" || _.type == "asr" || _.type == "answer" ? emitter.emit("wsMessage", _) : _.type == "startAsr" || _.type == "startSleep" || _.type == "wakeup" || (_.type == "server_ready" ? (console.error("可以发送语音文件"), emitter.emit("wsMessage", _)) : _.type == "server_ended" || _.type == "error" && emitter.emit("wsMessage", _)) } } } : function (a, e, g) { const _ = new Uint8Array(e.data); if (_[0] === 116 && _[1] === 101 && _[2] === 120 && _[3] === 116) { const y = get_text$1(_); if (console.log(y, "string"), y != "ppg-end") { if (y != "pong") { if (y.includes("requests overload")) pacemaker = !0, emitter.emit("wsMessage", { type: "requests overload" }); else if (y.includes("{")) { const x = JSON.parse(y); x.type == "asr-part" || x.type == "asr" || x.type == "answer" ? emitter.emit("wsMessage", x) : x.type == "startAsr" || x.type == "startSleep" || x.type == "wakeup" || (x.type == "server_ready" ? (console.error("可以发送语音文件"), emitter.emit("wsMessage", x)) : x.type == "server_ended" || x.type == "error" && emitter.emit("wsMessage", x)) } } } } else _[0] !== 72 || _[1] !== 80 || _[2] !== 67 || _[3] !== 77 || (videoPlayerInit = !1, console.log("——————————loop new——————————————")), g(_, videoPlayerInit) }, cbError: function (a, e) { console.error("websocket错误:", e), pacemaker = !0, heartPing.end() }, cbClose: function (a) { console.error("websocket关闭!"), pacemaker || pageAcitveStatusGet() }, wxServerEnd: function () { }, canPlay: function () { webglCut.videoPlay(), emitter.emit("videoStart"), this.streamImg = !0 }, waiting: function () { webglCut.slicePlay(), emitter.emit("videoEnd"), this.streamImg = !1, websocket == null || websocket.send(SendMsg.startAsr()) } }) }; function displayEle(h, t) { h.style.display = t } let requestVideo = ""; function player(h, t, n, r, l, a = 1) {
videoWidth = viewMap[t][l].width, videoHeight = viewMap[t][l].height, requestVideo = `requestWidth=${videoWidth}&requestHeight=${videoHeight}`, document.querySelector(h).innerHTML = `
`, screenCanvas = querySelectorEl("#screenPlayer"), avatarVideo = querySelectorEl("#avatarVideo"), silentVideo = querySelectorEl("#silentVideo"), displayEle(silentVideo, "none"), displayEle(avatarVideo, "none")
} class xxPlayer extends Emitter$2 { constructor({ environment: t, containerLable: n, token: r, projectId: l, quality: a, zoom: e, clientId: g, volume: _, asr: y }, x) { if (super(), y) { const { asrDestroy: E, asrWsAppoint: C, asrStart: L } = asrWs(A => { console.log(A, "mic") }); asrWsApp = C, L() } emitter = new Emitter$2, this.containerLable = n, commonObj._sign = r, commonObj._projectId = l, this.quality = a || 1, this.zoom = e || 1, commonObj._env = t || "prd", commonObj._volume = _ || 1, commonObj._asr = y || !1, reqRes = x, this.streamImg = !1 } init() { checkCondition(t => { if (t) { let { avatarSilenceUrl: n, avatarDirection: r, avatarChatUrl: l } = reqRes.data; player(this.containerLable, r, n, l, this.quality, this.zoom), emitter.on("videoEnd", () => { this.emit("message", { type: "videoEnd", data: {} }) }), emitter.on("videoStart", () => { this.emit("message", { type: "videoStart", data: {} }) }), emitter.on("wsMessage", a => { this.emit("message", { type: "wsMessage", data: a }) }), emitter.on("initCartoon", () => { this.emit("intialSucccess", { type: "2" }) }), this.emit("intialSucccess", { type: "1" }) } else this.emit("intialError", msg) }) } playSilentvideo() { silentVideo && silentVideo.play().then(t => { console.log("ffm交互静音视频播放") }).catch(t => { console.log("ffm交互静音视频播放失败-", t) }), avatarVideo && avatarVideo.play().then(t => { console.log("ffm交互静音视频播放") }).catch(t => { console.log("ffm交互静音视频播放失败-", t) }) } startPlay() { webglCut.load(avatarVideo, silentVideo, screenCanvas, t => { videoPlayerInit = !0, webglCut.slicePlay(), startPlayer(this.direction, this.quality), emitter.emit("initCartoon") }, isPlat ? "fragment-shader-nocut" : "") } setClientId(t) { t ? commonObj._clientId = t : console.log("clientId不能为空") } stopPlay() { uninstallEvent(), emitter = null, screenCanvas = null, avatarVideo = null, silentVideo = null, videoWidth = "", videoHeight = "", reqRes = null, asrWsApp = null, this.streamImg = !1 } playQA(t, n) { this.streamImg = !0, webglCut.slicePlay(), webReconnect(), websocket == null || websocket.send(SendMsg.qa(t, n)) } interrupt() { websocket == null || websocket.send(SendMsg.interrupt()), webglCut.slicePlay(), webReconnect(!0), this.streamImg = !1 } playText(t) { websocket == null || websocket.send(SendMsg.text(t)) } playStreamText(t) { websocket == null || websocket.send(SendMsg.streamText(t)) } playStreamTextStart(t, n) { websocket == null || websocket.send(SendMsg.streamTextStart(t, n)), this.streamImg = !0 } playStreamTextEnd() { websocket == null || websocket.send(SendMsg.streamTextEnd()) } playAudio(t) { websocket == null || websocket.send(SendMsg.streamAudio(t)), this.streamImg = !0 } playAudioEnd() { websocket == null || websocket.send(SendMsg.streamAudioEnd()) } playCurVideo() { this.streamImg && (websocket == null || websocket.send(SendMsg.resumePlay()), webglCut.videoPlay(), cartoonPlayer.player.continue()) } stopCurVideo() { this.streamImg && (websocket == null || websocket.send(SendMsg.pausePlay()), cartoonPlayer.player.stop(), webglCut.slicePlay()) } } var vconsole_min = { exports: {} };/*!
* vConsole v3.15.1 (https://github.com/Tencent/vConsole)
*
* Tencent is pleased to support the open source community by making vConsole available.
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/(function (module, exports) {
(function (h, t) { module.exports = t() })(commonjsGlobal || self, function () {
return function () {
var __webpack_modules__ = {
4264: function (h, t, n) { h.exports = n(7588) }, 5036: function (h, t, n) { n(1719), n(5677), n(6394), n(5334), n(6969), n(2021), n(8328), n(2129); var r = n(1287); h.exports = r.Promise }, 2582: function (h, t, n) { n(1646), n(6394), n(2004), n(462), n(8407), n(2429), n(1172), n(8288), n(1274), n(8201), n(6626), n(3211), n(9952), n(15), n(9831), n(7521), n(2972), n(6956), n(5222), n(2257); var r = n(1287); h.exports = r.Symbol }, 8257: function (h, t, n) { var r = n(7583), l = n(9212), a = n(5637), e = r.TypeError; h.exports = function (g) { if (l(g)) return g; throw e(a(g) + " is not a function") } }, 1186: function (h, t, n) { var r = n(7583), l = n(2097), a = n(5637), e = r.TypeError; h.exports = function (g) { if (l(g)) return g; throw e(a(g) + " is not a constructor") } }, 9882: function (h, t, n) { var r = n(7583), l = n(9212), a = r.String, e = r.TypeError; h.exports = function (g) { if (typeof g == "object" || l(g)) return g; throw e("Can't set " + a(g) + " as a prototype") } }, 6288: function (h, t, n) { var r = n(3649), l = n(3590), a = n(4615), e = r("unscopables"), g = Array.prototype; g[e] == null && a.f(g, e, { configurable: !0, value: l(null) }), h.exports = function (_) { g[e][_] = !0 } }, 4761: function (h, t, n) { var r = n(7583), l = n(2447), a = r.TypeError; h.exports = function (e, g) { if (l(g, e)) return e; throw a("Incorrect invocation") } }, 2569: function (h, t, n) { var r = n(7583), l = n(794), a = r.String, e = r.TypeError; h.exports = function (g) { if (l(g)) return g; throw e(a(g) + " is not an object") } }, 5766: function (h, t, n) { var r = n(2977), l = n(6782), a = n(1825), e = function (g) { return function (_, y, x) { var E, C = r(_), L = a(C), A = l(x, L); if (g && y != y) { for (; L > A;)if ((E = C[A++]) != E) return !0 } else for (; L > A; A++)if ((g || A in C) && C[A] === y) return g || A || 0; return !g && -1 } }; h.exports = { includes: e(!0), indexOf: e(!1) } }, 4805: function (h, t, n) { var r = n(2938), l = n(7386), a = n(5044), e = n(1324), g = n(1825), _ = n(4822), y = l([].push), x = function (E) { var C = E == 1, L = E == 2, A = E == 3, I = E == 4, D = E == 6, w = E == 7, S = E == 5 || D; return function (O, F, j, P) { for (var $, V, q = e(O), ee = a(q), re = r(F, j), ye = g(ee), ce = 0, Q = P || _, se = C ? Q(O, ye) : L || w ? Q(O, 0) : void 0; ye > ce; ce++)if ((S || ce in ee) && (V = re($ = ee[ce], ce, q), E)) if (C) se[ce] = V; else if (V) switch (E) { case 3: return !0; case 5: return $; case 6: return ce; case 2: y(se, $) } else switch (E) { case 4: return !1; case 7: y(se, $) }return D ? -1 : A || I ? I : se } }; h.exports = { forEach: x(0), map: x(1), filter: x(2), some: x(3), every: x(4), find: x(5), findIndex: x(6), filterReject: x(7) } }, 9269: function (h, t, n) { var r = n(6544), l = n(3649), a = n(4061), e = l("species"); h.exports = function (g) { return a >= 51 || !r(function () { var _ = []; return (_.constructor = {})[e] = function () { return { foo: 1 } }, _[g](Boolean).foo !== 1 }) } }, 4546: function (h, t, n) { var r = n(7583), l = n(6782), a = n(1825), e = n(5999), g = r.Array, _ = Math.max; h.exports = function (y, x, E) { for (var C = a(y), L = l(x, C), A = l(E === void 0 ? C : E, C), I = g(_(A - L, 0)), D = 0; L < A; L++, D++)e(I, D, y[L]); return I.length = D, I } }, 6917: function (h, t, n) { var r = n(7386); h.exports = r([].slice) }, 5289: function (h, t, n) { var r = n(7583), l = n(4521), a = n(2097), e = n(794), g = n(3649)("species"), _ = r.Array; h.exports = function (y) { var x; return l(y) && (x = y.constructor, (a(x) && (x === _ || l(x.prototype)) || e(x) && (x = x[g]) === null) && (x = void 0)), x === void 0 ? _ : x } }, 4822: function (h, t, n) { var r = n(5289); h.exports = function (l, a) { return new (r(l))(a === 0 ? 0 : a) } }, 3616: function (h, t, n) { var r = n(3649)("iterator"), l = !1; try { var a = 0, e = { next: function () { return { done: !!a++ } }, return: function () { l = !0 } }; e[r] = function () { return this }, Array.from(e, function () { throw 2 }) } catch { } h.exports = function (g, _) { if (!_ && !l) return !1; var y = !1; try { var x = {}; x[r] = function () { return { next: function () { return { done: y = !0 } } } }, g(x) } catch { } return y } }, 9624: function (h, t, n) { var r = n(7386), l = r({}.toString), a = r("".slice); h.exports = function (e) { return a(l(e), 8, -1) } }, 3058: function (h, t, n) { var r = n(7583), l = n(8191), a = n(9212), e = n(9624), g = n(3649)("toStringTag"), _ = r.Object, y = e(function () { return arguments }()) == "Arguments"; h.exports = l ? e : function (x) { var E, C, L; return x === void 0 ? "Undefined" : x === null ? "Null" : typeof (C = function (A, I) { try { return A[I] } catch { } }(E = _(x), g)) == "string" ? C : y ? e(E) : (L = e(E)) == "Object" && a(E.callee) ? "Arguments" : L } }, 1509: function (h, t, n) { var r = n(7386)("".replace), l = String(Error("zxcasd").stack), a = /\n\s*at [^:]*:[^\n]*/, e = a.test(l); h.exports = function (g, _) { if (e && typeof g == "string") for (; _--;)g = r(g, a, ""); return g } }, 3478: function (h, t, n) { var r = n(2870), l = n(929), a = n(6683), e = n(4615); h.exports = function (g, _, y) { for (var x = l(_), E = e.f, C = a.f, L = 0; L < x.length; L++) { var A = x[L]; r(g, A) || y && r(y, A) || E(g, A, C(_, A)) } } }, 926: function (h, t, n) { var r = n(6544); h.exports = !r(function () { function l() { } return l.prototype.constructor = null, Object.getPrototypeOf(new l) !== l.prototype }) }, 4683: function (h, t, n) { var r = n(2365).IteratorPrototype, l = n(3590), a = n(4677), e = n(8821), g = n(339), _ = function () { return this }; h.exports = function (y, x, E, C) { var L = x + " Iterator"; return y.prototype = l(r, { next: a(+!C, E) }), e(y, L, !1, !0), g[L] = _, y } }, 57: function (h, t, n) { var r = n(8494), l = n(4615), a = n(4677); h.exports = r ? function (e, g, _) { return l.f(e, g, a(1, _)) } : function (e, g, _) { return e[g] = _, e } }, 4677: function (h) { h.exports = function (t, n) { return { enumerable: !(1 & t), configurable: !(2 & t), writable: !(4 & t), value: n } } }, 5999: function (h, t, n) { var r = n(8734), l = n(4615), a = n(4677); h.exports = function (e, g, _) { var y = r(g); y in e ? l.f(e, y, a(0, _)) : e[y] = _ } }, 9012: function (h, t, n) { var r = n(7263), l = n(8262), a = n(6268), e = n(4340), g = n(9212), _ = n(4683), y = n(729), x = n(7496), E = n(8821), C = n(57), L = n(1270), A = n(3649), I = n(339), D = n(2365), w = e.PROPER, S = e.CONFIGURABLE, O = D.IteratorPrototype, F = D.BUGGY_SAFARI_ITERATORS, j = A("iterator"), P = "keys", $ = "values", V = "entries", q = function () { return this }; h.exports = function (ee, re, ye, ce, Q, se, fe) { _(ye, re, ce); var G, K, de, ve = function (Oe) { if (Oe === Q && ne) return ne; if (!F && Oe in U) return U[Oe]; switch (Oe) { case P: case $: case V: return function () { return new ye(this, Oe) } }return function () { return new ye(this) } }, ae = re + " Iterator", J = !1, U = ee.prototype, X = U[j] || U["@@iterator"] || Q && U[Q], ne = !F && X || ve(Q), we = re == "Array" && U.entries || X; if (we && (G = y(we.call(new ee))) !== Object.prototype && G.next && (a || y(G) === O || (x ? x(G, O) : g(G[j]) || L(G, j, q)), E(G, ae, !0, !0), a && (I[ae] = q)), w && Q == $ && X && X.name !== $ && (!a && S ? C(U, "name", $) : (J = !0, ne = function () { return l(X, this) })), Q) if (K = { values: ve($), keys: se ? ne : ve(P), entries: ve(V) }, fe) for (de in K) (F || J || !(de in U)) && L(U, de, K[de]); else r({ target: re, proto: !0, forced: F || J }, K); return a && !fe || U[j] === ne || L(U, j, ne, { name: Q }), I[re] = ne, K } }, 2219: function (h, t, n) { var r = n(1287), l = n(2870), a = n(491), e = n(4615).f; h.exports = function (g) { var _ = r.Symbol || (r.Symbol = {}); l(_, g) || e(_, g, { value: a.f(g) }) } }, 8494: function (h, t, n) { var r = n(6544); h.exports = !r(function () { return Object.defineProperty({}, 1, { get: function () { return 7 } })[1] != 7 }) }, 6668: function (h, t, n) { var r = n(7583), l = n(794), a = r.document, e = l(a) && l(a.createElement); h.exports = function (g) { return e ? a.createElement(g) : {} } }, 6778: function (h) { h.exports = { CSSRuleList: 0, CSSStyleDeclaration: 0, CSSValueList: 0, ClientRectList: 0, DOMRectList: 0, DOMStringList: 0, DOMTokenList: 1, DataTransferItemList: 0, FileList: 0, HTMLAllCollection: 0, HTMLCollection: 0, HTMLFormElement: 0, HTMLSelectElement: 0, MediaList: 0, MimeTypeArray: 0, NamedNodeMap: 0, NodeList: 1, PaintRequestList: 0, Plugin: 0, PluginArray: 0, SVGLengthList: 0, SVGNumberList: 0, SVGPathSegList: 0, SVGPointList: 0, SVGStringList: 0, SVGTransformList: 0, SourceBufferList: 0, StyleSheetList: 0, TextTrackCueList: 0, TextTrackList: 0, TouchList: 0 } }, 9307: function (h, t, n) { var r = n(6668)("span").classList, l = r && r.constructor && r.constructor.prototype; h.exports = l === Object.prototype ? void 0 : l }, 2274: function (h) { h.exports = typeof window == "object" }, 3256: function (h, t, n) { var r = n(6918), l = n(7583); h.exports = /ipad|iphone|ipod/i.test(r) && l.Pebble !== void 0 }, 7020: function (h, t, n) { var r = n(6918); h.exports = /(?:ipad|iphone|ipod).*applewebkit/i.test(r) }, 5354: function (h, t, n) { var r = n(9624), l = n(7583); h.exports = r(l.process) == "process" }, 6846: function (h, t, n) { var r = n(6918); h.exports = /web0s(?!.*chrome)/i.test(r) }, 6918: function (h, t, n) { var r = n(5897); h.exports = r("navigator", "userAgent") || "" }, 4061: function (h, t, n) { var r, l, a = n(7583), e = n(6918), g = a.process, _ = a.Deno, y = g && g.versions || _ && _.version, x = y && y.v8; x && (l = (r = x.split("."))[0] > 0 && r[0] < 4 ? 1 : +(r[0] + r[1])), !l && e && (!(r = e.match(/Edge\/(\d+)/)) || r[1] >= 74) && (r = e.match(/Chrome\/(\d+)/)) && (l = +r[1]), h.exports = l }, 5690: function (h) { h.exports = ["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString", "toString", "valueOf"] }, 1178: function (h, t, n) { var r = n(6544), l = n(4677); h.exports = !r(function () { var a = Error("a"); return !("stack" in a) || (Object.defineProperty(a, "stack", l(1, 7)), a.stack !== 7) }) }, 7263: function (h, t, n) { var r = n(7583), l = n(6683).f, a = n(57), e = n(1270), g = n(460), _ = n(3478), y = n(4451); h.exports = function (x, E) { var C, L, A, I, D, w = x.target, S = x.global, O = x.stat; if (C = S ? r : O ? r[w] || g(w, {}) : (r[w] || {}).prototype) for (L in E) { if (I = E[L], A = x.noTargetGet ? (D = l(C, L)) && D.value : C[L], !y(S ? L : w + (O ? "." : "#") + L, x.forced) && A !== void 0) { if (typeof I == typeof A) continue; _(I, A) } (x.sham || A && A.sham) && a(I, "sham", !0), e(C, L, I, x) } } }, 6544: function (h) { h.exports = function (t) { try { return !!t() } catch { return !0 } } }, 1611: function (h, t, n) { var r = n(8987), l = Function.prototype, a = l.apply, e = l.call; h.exports = typeof Reflect == "object" && Reflect.apply || (r ? e.bind(a) : function () { return e.apply(a, arguments) }) }, 2938: function (h, t, n) { var r = n(7386), l = n(8257), a = n(8987), e = r(r.bind); h.exports = function (g, _) { return l(g), _ === void 0 ? g : a ? e(g, _) : function () { return g.apply(_, arguments) } } }, 8987: function (h, t, n) { var r = n(6544); h.exports = !r(function () { var l = (function () { }).bind(); return typeof l != "function" || l.hasOwnProperty("prototype") }) }, 8262: function (h, t, n) { var r = n(8987), l = Function.prototype.call; h.exports = r ? l.bind(l) : function () { return l.apply(l, arguments) } }, 4340: function (h, t, n) { var r = n(8494), l = n(2870), a = Function.prototype, e = r && Object.getOwnPropertyDescriptor, g = l(a, "name"), _ = g && (function () { }).name === "something", y = g && (!r || r && e(a, "name").configurable); h.exports = { EXISTS: g, PROPER: _, CONFIGURABLE: y } }, 7386: function (h, t, n) { var r = n(8987), l = Function.prototype, a = l.bind, e = l.call, g = r && a.bind(e, e); h.exports = r ? function (_) { return _ && g(_) } : function (_) { return _ && function () { return e.apply(_, arguments) } } }, 5897: function (h, t, n) { var r = n(7583), l = n(9212), a = function (e) { return l(e) ? e : void 0 }; h.exports = function (e, g) { return arguments.length < 2 ? a(r[e]) : r[e] && r[e][g] } }, 8272: function (h, t, n) { var r = n(3058), l = n(911), a = n(339), e = n(3649)("iterator"); h.exports = function (g) { if (g != null) return l(g, e) || l(g, "@@iterator") || a[r(g)] } }, 6307: function (h, t, n) { var r = n(7583), l = n(8262), a = n(8257), e = n(2569), g = n(5637), _ = n(8272), y = r.TypeError; h.exports = function (x, E) { var C = arguments.length < 2 ? _(x) : E; if (a(C)) return e(l(C, x)); throw y(g(x) + " is not iterable") } }, 911: function (h, t, n) { var r = n(8257); h.exports = function (l, a) { var e = l[a]; return e == null ? void 0 : r(e) } }, 7583: function (h, t, n) { var r = function (l) { return l && l.Math == Math && l }; h.exports = r(typeof globalThis == "object" && globalThis) || r(typeof window == "object" && window) || r(typeof self == "object" && self) || r(typeof n.g == "object" && n.g) || function () { return this }() || Function("return this")() }, 2870: function (h, t, n) { var r = n(7386), l = n(1324), a = r({}.hasOwnProperty); h.exports = Object.hasOwn || function (e, g) { return a(l(e), g) } }, 4639: function (h) { h.exports = {} }, 2716: function (h, t, n) { var r = n(7583); h.exports = function (l, a) { var e = r.console; e && e.error && (arguments.length == 1 ? e.error(l) : e.error(l, a)) } }, 482: function (h, t, n) { var r = n(5897); h.exports = r("document", "documentElement") }, 275: function (h, t, n) { var r = n(8494), l = n(6544), a = n(6668); h.exports = !r && !l(function () { return Object.defineProperty(a("div"), "a", { get: function () { return 7 } }).a != 7 }) }, 5044: function (h, t, n) { var r = n(7583), l = n(7386), a = n(6544), e = n(9624), g = r.Object, _ = l("".split); h.exports = a(function () { return !g("z").propertyIsEnumerable(0) }) ? function (y) { return e(y) == "String" ? _(y, "") : g(y) } : g }, 9734: function (h, t, n) { var r = n(7386), l = n(9212), a = n(1314), e = r(Function.toString); l(a.inspectSource) || (a.inspectSource = function (g) { return e(g) }), h.exports = a.inspectSource }, 4402: function (h, t, n) { var r = n(794), l = n(57); h.exports = function (a, e) { r(e) && "cause" in e && l(a, "cause", e.cause) } }, 2743: function (h, t, n) { var r, l, a, e = n(9491), g = n(7583), _ = n(7386), y = n(794), x = n(57), E = n(2870), C = n(1314), L = n(9137), A = n(4639), I = "Object already initialized", D = g.TypeError, w = g.WeakMap; if (e || C.state) { var S = C.state || (C.state = new w), O = _(S.get), F = _(S.has), j = _(S.set); r = function ($, V) { if (F(S, $)) throw new D(I); return V.facade = $, j(S, $, V), V }, l = function ($) { return O(S, $) || {} }, a = function ($) { return F(S, $) } } else { var P = L("state"); A[P] = !0, r = function ($, V) { if (E($, P)) throw new D(I); return V.facade = $, x($, P, V), V }, l = function ($) { return E($, P) ? $[P] : {} }, a = function ($) { return E($, P) } } h.exports = { set: r, get: l, has: a, enforce: function ($) { return a($) ? l($) : r($, {}) }, getterFor: function ($) { return function (V) { var q; if (!y(V) || (q = l(V)).type !== $) throw D("Incompatible receiver, " + $ + " required"); return q } } } }, 114: function (h, t, n) { var r = n(3649), l = n(339), a = r("iterator"), e = Array.prototype; h.exports = function (g) { return g !== void 0 && (l.Array === g || e[a] === g) } }, 4521: function (h, t, n) { var r = n(9624); h.exports = Array.isArray || function (l) { return r(l) == "Array" } }, 9212: function (h) { h.exports = function (t) { return typeof t == "function" } }, 2097: function (h, t, n) { var r = n(7386), l = n(6544), a = n(9212), e = n(3058), g = n(5897), _ = n(9734), y = function () { }, x = [], E = g("Reflect", "construct"), C = /^\s*(?:class|function)\b/, L = r(C.exec), A = !C.exec(y), I = function (w) { if (!a(w)) return !1; try { return E(y, x, w), !0 } catch { return !1 } }, D = function (w) { if (!a(w)) return !1; switch (e(w)) { case "AsyncFunction": case "GeneratorFunction": case "AsyncGeneratorFunction": return !1 }try { return A || !!L(C, _(w)) } catch { return !0 } }; D.sham = !0, h.exports = !E || l(function () { var w; return I(I.call) || !I(Object) || !I(function () { w = !0 }) || w }) ? D : I }, 4451: function (h, t, n) { var r = n(6544), l = n(9212), a = /#|\.prototype\./, e = function (E, C) { var L = _[g(E)]; return L == x || L != y && (l(C) ? r(C) : !!C) }, g = e.normalize = function (E) { return String(E).replace(a, ".").toLowerCase() }, _ = e.data = {}, y = e.NATIVE = "N", x = e.POLYFILL = "P"; h.exports = e }, 794: function (h, t, n) { var r = n(9212); h.exports = function (l) { return typeof l == "object" ? l !== null : r(l) } }, 6268: function (h) { h.exports = !1 }, 5871: function (h, t, n) { var r = n(7583), l = n(5897), a = n(9212), e = n(2447), g = n(7786), _ = r.Object; h.exports = g ? function (y) { return typeof y == "symbol" } : function (y) { var x = l("Symbol"); return a(x) && e(x.prototype, _(y)) } }, 4026: function (h, t, n) { var r = n(7583), l = n(2938), a = n(8262), e = n(2569), g = n(5637), _ = n(114), y = n(1825), x = n(2447), E = n(6307), C = n(8272), L = n(7093), A = r.TypeError, I = function (w, S) { this.stopped = w, this.result = S }, D = I.prototype; h.exports = function (w, S, O) { var F, j, P, $, V, q, ee, re = O && O.that, ye = !(!O || !O.AS_ENTRIES), ce = !(!O || !O.IS_ITERATOR), Q = !(!O || !O.INTERRUPTED), se = l(S, re), fe = function (K) { return F && L(F, "normal", K), new I(!0, K) }, G = function (K) { return ye ? (e(K), Q ? se(K[0], K[1], fe) : se(K[0], K[1])) : Q ? se(K, fe) : se(K) }; if (ce) F = w; else { if (!(j = C(w))) throw A(g(w) + " is not iterable"); if (_(j)) { for (P = 0, $ = y(w); $ > P; P++)if ((V = G(w[P])) && x(D, V)) return V; return new I(!1) } F = E(w, j) } for (q = F.next; !(ee = a(q, F)).done;) { try { V = G(ee.value) } catch (K) { L(F, "throw", K) } if (typeof V == "object" && V && x(D, V)) return V } return new I(!1) } }, 7093: function (h, t, n) { var r = n(8262), l = n(2569), a = n(911); h.exports = function (e, g, _) { var y, x; l(e); try { if (!(y = a(e, "return"))) { if (g === "throw") throw _; return _ } y = r(y, e) } catch (E) { x = !0, y = E } if (g === "throw") throw _; if (x) throw y; return l(y), _ } }, 2365: function (h, t, n) { var r, l, a, e = n(6544), g = n(9212), _ = n(3590), y = n(729), x = n(1270), E = n(3649), C = n(6268), L = E("iterator"), A = !1;[].keys && ("next" in (a = [].keys()) ? (l = y(y(a))) !== Object.prototype && (r = l) : A = !0), r == null || e(function () { var I = {}; return r[L].call(I) !== I }) ? r = {} : C && (r = _(r)), g(r[L]) || x(r, L, function () { return this }), h.exports = { IteratorPrototype: r, BUGGY_SAFARI_ITERATORS: A } }, 339: function (h) { h.exports = {} }, 1825: function (h, t, n) { var r = n(97); h.exports = function (l) { return r(l.length) } }, 2095: function (h, t, n) { var r, l, a, e, g, _, y, x, E = n(7583), C = n(2938), L = n(6683).f, A = n(8117).set, I = n(7020), D = n(3256), w = n(6846), S = n(5354), O = E.MutationObserver || E.WebKitMutationObserver, F = E.document, j = E.process, P = E.Promise, $ = L(E, "queueMicrotask"), V = $ && $.value; V || (r = function () { var q, ee; for (S && (q = j.domain) && q.exit(); l;) { ee = l.fn, l = l.next; try { ee() } catch (re) { throw l ? e() : a = void 0, re } } a = void 0, q && q.enter() }, I || S || w || !O || !F ? !D && P && P.resolve ? ((y = P.resolve(void 0)).constructor = P, x = C(y.then, y), e = function () { x(r) }) : S ? e = function () { j.nextTick(r) } : (A = C(A, E), e = function () { A(r) }) : (g = !0, _ = F.createTextNode(""), new O(r).observe(_, { characterData: !0 }), e = function () { _.data = g = !g })), h.exports = V || function (q) { var ee = { fn: q, next: void 0 }; a && (a.next = ee), l || (l = ee, e()), a = ee } }, 783: function (h, t, n) { var r = n(7583); h.exports = r.Promise }, 8640: function (h, t, n) { var r = n(4061), l = n(6544); h.exports = !!Object.getOwnPropertySymbols && !l(function () { var a = Symbol(); return !String(a) || !(Object(a) instanceof Symbol) || !Symbol.sham && r && r < 41 }) }, 9491: function (h, t, n) { var r = n(7583), l = n(9212), a = n(9734), e = r.WeakMap; h.exports = l(e) && /native code/.test(a(e)) }, 5084: function (h, t, n) { var r = n(8257), l = function (a) { var e, g; this.promise = new a(function (_, y) { if (e !== void 0 || g !== void 0) throw TypeError("Bad Promise constructor"); e = _, g = y }), this.resolve = r(e), this.reject = r(g) }; h.exports.f = function (a) { return new l(a) } }, 2764: function (h, t, n) { var r = n(8320); h.exports = function (l, a) { return l === void 0 ? arguments.length < 2 ? "" : a : r(l) } }, 3590: function (h, t, n) { var r, l = n(2569), a = n(8728), e = n(5690), g = n(4639), _ = n(482), y = n(6668), x = n(9137), E = x("IE_PROTO"), C = function () { }, L = function (D) { return "