UNPKG

@anov/core

Version:

ANOV Visualization Platform Kernel encapsulates all basic services, such as face recognition, gesture recognition, speech recognition, theme skin changing, internationalization, animation engine, basic components

1,188 lines (1,186 loc) 525 kB
import { moment, gpu, qs, annyang, checkVideo, isPlainObject, isArray, Browser, checkAudio, cloneDeep } from "dtc"; import * as CryptoJS from "crypto-js"; import CryptoJS__default from "crypto-js"; import axios from "axios"; import { merge, debounce, compact, throttle, isPlainObject as isPlainObject$1, isArray as isArray$1, isFunction, isString, startsWith, isBoolean, mapKeys, has, mergeWith, reverse, unionBy, concat } from "lodash-es"; import { GestureRecognizer, FilesetResolver } from "@mediapipe/tasks-vision"; import hotkeys from "hotkeys-js"; import { Howler, Howl } from "howler"; import UPNG from "upng-js"; import Vue from "vue"; function mitt(r) { return r = r || /* @__PURE__ */ Object.create(null), { $on(t, e) { (r[t] || (r[t] = [])).push(e); }, $once(t, e) { let i = this; this.$on(t, function o() { i.$off(t, o), e.apply(i, arguments); }); }, $off(t, e) { r[t] && r[t].splice(r[t].indexOf(e) >>> 0, 1); }, $emit(t, e) { (r[t] || []).slice().map((i) => { i(e); }), (r["*"] || []).slice().map((i) => { i(t, e); }); } }; } const __sys_bus_emitter = mitt(); class EventBusServer { } Object.assign(EventBusServer.prototype, { getEventBus: () => __sys_bus_emitter }); class VuexServer { } Object.assign(VuexServer.prototype, { getState() { return this.getAppStore().state[this._type]; }, mapState(r) { return mapState(this._type, r); }, mapGetters(r) { return mapGetters(this._type, r); }, mapMutations(r) { return mapMutations(this._type, r); }, callState(r) { return this.getAppStore().state[this._type][r]; }, callGetter(r, t) { return this.getAppStore().getters[this._type + "/" + r](t); }, callMutation(r, t) { this.getAppStore().commit(this._type + "/" + r, t); } }); const mapState = normalizeNamespace((r, t) => { const e = {}; return normalizeMap(t).forEach(({ key: i, val: o }) => { e[i] = function() { let s = this.$store.state, a = this.$store.getters; if (r) { const u = getModuleByNamespace(this.$store, "mapState", r); if (!u) return; s = u.context.state, a = u.context.getters; } return typeof o == "function" ? o.call(this, s, a) : s[o]; }, e[i].vuex = !0; }), e; }), mapMutations = normalizeNamespace((r, t) => { const e = {}; return normalizeMap(t).forEach(({ key: i, val: o }) => { e[i] = function(...s) { let a = this.$store.commit; if (r) { const u = getModuleByNamespace(this.$store, "mapMutations", r); if (!u) return; a = u.context.commit; } return typeof o == "function" ? o.apply(this, [a].concat(s)) : a.apply(this.$store, [o].concat(s)); }; }), e; }), mapGetters = normalizeNamespace((r, t) => { const e = {}; return normalizeMap(t).forEach(({ key: i, val: o }) => { o = r + o, e[i] = function() { if (!r || getModuleByNamespace(this.$store, "mapGetters", r)) { if (process.env.NODE_ENV === "production" || o in this.$store.getters) return this.$store.getters[o]; console.error(`[vuex] unknown getter: ${o}`); } }, e[i].vuex = !0; }), e; }); function normalizeMap(r) { return Array.isArray(r) ? r.map((t) => ({ key: t, val: t })) : Object.keys(r).map((t) => ({ key: t, val: r[t] })); } function normalizeNamespace(r) { return (t, e) => (typeof t != "string" ? (e = t, t = "") : t.charAt(t.length - 1) !== "/" && (t += "/"), r(t, e)); } function getModuleByNamespace(r, t, e) { const i = r._modulesNamespaceMap[e]; return process.env.NODE_ENV === "production" || i || console.error(`[vuex] module namespace not found in ${t}(): ${e}`), i; } let EventDispatcher$1 = class { }; Object.assign(EventDispatcher$1.prototype, { addEventListener(r, t) { this._listeners === void 0 && (this._listeners = {}); var e = this._listeners; e[r] === void 0 && (e[r] = []), e[r].indexOf(t) === -1 && e[r].push(t); }, hasEventListener(r, t) { if (this._listeners === void 0) return !1; var e = this._listeners; return e[r] !== void 0 && e[r].indexOf(t) !== -1; }, removeEventListener(r, t) { if (this._listeners !== void 0) { var e = this._listeners[r]; if (e !== void 0) { var i = e.indexOf(t); i !== -1 && e.splice(i, 1); } } }, dispatchEvent(r) { if (this._listeners !== void 0) { var t = this._listeners[r.type]; if (t !== void 0) { r.target = this; for (var e = t.slice(0), i = 0, o = e.length; i < o; i++) e[i].call(this, r); } } } }); const __sys_error = [], _maxCount$1 = 50; class MonitorServer { constructor() { this.initNormalError(), this.initConsoleError(), this.initPromiseError(); } initNormalError() { window.onerror = (t, e, i, o, s) => { let a = s ? s.stack : t + ` ` + e + ":" + i + ":" + o; this._write(a); }; } initConsoleError() { var t = console.error; console.error = (e) => { let i = e + ` ` + window.location.href + ":0:0[console]"; return this._write(i), t(e); }; } initPromiseError() { window.onunhandledrejection = (t) => { let e = ""; e = typeof t.reason == "object" ? JSON.stringify(t.reason) : t.reason; let i = e + ` ` + window.location.href + ":0:0[promise]"; this._write(i); }; } _write(t) { try { app && app.runtimeServer ? __sys_error.length > 0 ? (__sys_error.map((e) => { app.runtimeServer.addError(e); }), __sys_error.splice(0)) : app.runtimeServer.addError(t) : (__sys_error.length >= _maxCount$1 && __sys_error.shift(), __sys_error.push(t)); } catch { } } } new MonitorServer(); const __sys_log = [], _maxCount = 200; class LogServer { } Object.assign(LogServer.prototype, { addError(r) { this._addLog({ type: "error", msg: r }); }, addWarn(r) { this._addLog({ type: "warn", msg: r }); }, addInfo(r) { this._addLog({ type: "info", msg: r }); }, _addLog(r) { r = Object.assign({ module: this._type, date: moment().format("HH:mm:ss") }, r), __sys_log.length >= _maxCount && __sys_log.shift(), __sys_log.push(r), this.getEventBus().$emit("logging", r); }, getLog: () => __sys_log, delLog() { __sys_log.splice(0); } }); let __sys_current_context = null, __appStore = null, __http = null; class BaseServer { constructor(t) { if (!t) throw new Error("Anov:server type is not null"); this._type = t, this._http = __http, this._addLog({ type: "info", module: "system", msg: this._type + "Server initialization" }); } _extractConfig(t) { return t[this._type]; } getAppStore() { return __appStore; } getCurrentContext() { return __sys_current_context; } static _setCurrentContext(t) { __sys_current_context = t; } static _setAppStore(t) { __appStore = t; } } Object.assign(BaseServer.prototype, LogServer.prototype), Object.assign(BaseServer.prototype, EventDispatcher$1.prototype), Object.assign(BaseServer.prototype, EventBusServer.prototype), Object.assign(BaseServer.prototype, VuexServer.prototype); const T_KEY$1 = "anov@2019:helloX", T_IV$1 = "anov@2020:helloX", expire = 30, token$1 = { ct: (r, t) => getAesString$1(r + "|" + t, T_KEY$1, T_IV$1), vt(r) { let t = getDAesString(r, T_KEY$1, T_IV$1); if (t && t.split("|")[1]) { let e = +t.split("|")[1], i = 1e3 * expire; return (/* @__PURE__ */ new Date()).getTime() - e < i; } return !1; } }; function getAesString$1(r, t, e) { return t = CryptoJS__default.enc.Utf8.parse(t), e = CryptoJS__default.enc.Utf8.parse(e), CryptoJS__default.AES.encrypt(r, t, { iv: e, mode: CryptoJS__default.mode.CBC, padding: CryptoJS__default.pad.Pkcs7 }).toString(); } function getDAesString(r, t, e) { return t = CryptoJS__default.enc.Utf8.parse(t), e = CryptoJS__default.enc.Utf8.parse(e), CryptoJS__default.AES.decrypt(r, t, { iv: e, mode: CryptoJS__default.mode.CBC, padding: CryptoJS__default.pad.Pkcs7 }).toString(CryptoJS__default.enc.Utf8); } const ga = { info: {}, getInfo() { var r = {}; document && (r.domain = document.domain || "", r.url = document.URL || "", r.title = document.title || "", r.referrer = document.referrer || ""), window && window.screen && (r.sh = window.screen.height || 0, r.sw = window.screen.width || 0, r.cd = window.screen.colorDepth || 0), navigator && (r.lang = navigator.language || ""), r.GPUmodel = this.info.GPUmodel || gpu() && gpu().name, r.GPUmanufacturer = this.info.GPUmanufacturer || "", r.memoryTotalJsHeapSize = this.info.memoryTotalJsHeapSize || 0, r.memoryUsedJsHeapSize = this.info.memoryUsedJsHeapSize || 0, r.fps = this.info.fps || 0; var t = ""; for (var e in r) t != "" && (t += "&"), t += e + "=" + encodeURIComponent(r[e]); return t; } }, httpInterceptors = { init(r) { r.http && (this.http = r.http, r.request && this.openRequestInterceptors(r.http), r.response && this.openResponseInterceptors(r.http)); }, openRequestInterceptors(r) { r.interceptors.request.use((t) => { if (!__ANOV__ENV) return void console.warn("__ANOV__ENV全局对象未配置。"); let e = (/* @__PURE__ */ new Date()).getTime(), i = token$1.ct(__ANOV__ENV.projectId, e); return i && (t.headers["X-Anov-Token"] = i, t.headers.GA = ga.getInfo(), t.headers["X-Anov-Client-Type"] = getClientType()), t; }, (t) => Promise.error(t)); }, openResponseInterceptors(r) { r.interceptors.response.use((t) => t.status === 200 ? Promise.resolve(t.data) : Promise.reject(t.data), (t) => (__ANOV__ENV.debug && console.error(t), t.response && t.response.status && t.response.status, Promise.reject(t.response))); } }; function getClientType() { let r = "anov-null"; if (__ANOV__ENV && __ANOV__ENV.platformName) switch (__ANOV__ENV.platformName.toLowerCase()) { case "anov": case "anov-dev": r = "screen"; break; case "anov-go": r = "go"; break; case "anov-remote": r = "remote"; break; case "anov-admin": r = "server"; } return r; } const sender = Symbol("sender"), sendAck = Symbol("ack"), ACK = "ACK", SEQ = "SEQ", STATE = "STATE", CONTROLL = "CONTROLL", ACTION = "ACTION", INFO = "INFO", SYS = "SYS", RTS = "RTS", LOG = "LOG", GET = "GET"; function isSupportWS() { return !!WebSocket; } function interceptors(r = {}) { const { type: t, data: e, target: { readyState: i } } = r; let o, s; try { o = JSON.parse(e); } catch { s = e; } return { type: t, data: o, message: s, readyState: i }; } class Eventer { addEventListener(t, e) { this._listeners === void 0 && (this._listeners = {}); let i = this._listeners; i[t] === void 0 && (i[t] = []), i[t].indexOf(e) === -1 && i[t].push(e); } hasEventListener(t, e) { if (this._listeners === void 0) return !1; let i = this._listeners; return i[t] !== void 0 && i[t].indexOf(e) !== -1; } removeEventListener(t, e) { if (this._listeners === void 0) return; let i = this._listeners[t]; if (i !== void 0) { let o = i.indexOf(e); o !== -1 && i.splice(o, 1); } } dispatchEvent(t, e, i) { if (this._listeners === void 0) return; let o = this._listeners[t]; if (o !== void 0) { let s = o.slice(0); for (let a = 0, u = s.length; a < u; a++) s[a](e, i); } } } class Remote extends Eventer { constructor(t, e, i = !1) { if (super(), this.sendReslove = {}, this.sendReject = {}, this.sendTimer = {}, this.sentMsgIds = [], this.url = t, this.closed = !0, this.readyState = 3, this._gap = 0, this._breakpoint = [], this.status = new Proxy({ up: 0, down: 0 }, { get: function(o, s) { return o[s]; }, set: (o, s, a) => { let u = o.up + o.down; o[s] = a; let l = o.up + o.down; return l !== u && this.dispatchEvent("wsStatus", l), !0; } }), this.confirm = typeof e == "boolean" ? e : i, this.remoteId = typeof e == "string" ? e : "", !isSupportWS()) return console.error("Your browser does not support WebSocket connections!"), /* @__PURE__ */ Object.create(null); /^ws/.test(t) && this.connect(this.url, this.remoteId, this.confirm); } [sendAck](t, e = ACK, i, o) { const s = { ack: t, timestamp: o, type: e, data: i, confirm: !0, screenCode: this.screenCode }; this.ws.send(JSON.stringify(s)); } [sender](t, e = !1, i = SEQ) { let o = { seq: CryptoJS__default.MD5(JSON.stringify(t) + (/* @__PURE__ */ new Date()).getTime()).toString(), timestamp: (/* @__PURE__ */ new Date()).getTime(), type: i, data: t, confirm: e, screenCode: this.screenCode }; return this.status.up = 1, new Promise((s, a) => { this.ws && this.ws.readyState === 1 ? (this.ws.send(JSON.stringify(o)), this.sentMsgIds.push(o.seq), this.sendReslove[`seq_${o.seq}`] = s, this.sendReject[`seq_${o.seq}`] = a, this.sendTimer[`seq_${o.seq}`] = setTimeout(() => { typeof this.sendReslove[`seq_${o.seq}`] == "function" && (delete this.sendReslove[`seq_${o.seq}`], delete this.sendReject[`seq_${o.seq}`]), this.status.down = 0, a({ message: "timeout", id: o.seq }); }, 3100)) : (this.status.up = 0, this.status.down = 0, a({ message: "state error", code: this.ws && this.ws.readyState })); }); } connect(t, e, i = !1) { if (!/^ws(s)?:\/\//.test(t)) return console.warn("Ensure the correct websocket address!"), Promise.reject(); if (this.readyState !== 3) return console.warn("You already have One WebSocket instance!"), Promise.reject(); this.url = t; const o = t.split("/"), s = o.length; return this.appCode = o[s - 2], this.screenCode = o[s - 1], this.confirm = typeof e == "boolean" ? e : i, this.remoteId = typeof e == "string" ? e : "", this.ws = new WebSocket(t), this.ws.addEventListener("message", (a) => { const u = interceptors(a), l = u && u.data && u.data.type, h = u && u.data && u.data.confirm, p = u && u.data && u.data.timestamp || (/* @__PURE__ */ new Date()).getTime(); if (l === "PING") { clearTimeout(this.serverTimeoutTimer), clearTimeout(this.hartbeatTimer); let T = u && u.data && u.data.seq; typeof this.sendReslove[`seq_${T}`] == "function" && this.sendReslove[`seq_${T}`](u); const F = this.sendTimer[`seq_${T}`]; return F && clearTimeout(F), delete this.sendReslove[`seq_${T}`], delete this.sendReject[`seq_${T}`], void (!this.closed && this.hartbeat()); } if (l === SYS) return void this.dispatchEvent("sys", u); if (!u.data) return void this.dispatchEvent("error", u); if (u.data.toCodeId !== (this.appCode || this.screenCode)) return; const g = u && u.data && u.data.seq; let C = this.sentMsgIds.findIndex((T) => T === g); if (C >= 0) return this.sentMsgIds.splice(C, 1), h || (this.dispatchEvent("serverDelay", (/* @__PURE__ */ new Date()).getTime() - u.data.timestamp), clearTimeout(this.sendTimer[`seq_${g}`]), typeof this.sendReslove[`seq_${g}`] == "function" && (this.sendReslove[`seq_${g}`](!0), delete this.sendReslove[`seq_${g}`], delete this.sendReject[`seq_${g}`])), void (this.status.down = 2); if (l === ACK) { const T = u && u.data && u.data.ack, F = u && u.data && u.data.data && u.data.data.success; typeof this.sendReslove[`seq_${T}`] == "function" && (F === !1 ? this.sendReject[`seq_${T}`](u) : this.sendReslove[`seq_${T}`](u)), this.dispatchEvent("clientDelay", (/* @__PURE__ */ new Date()).getTime() - u.data.timestamp); const S = this.sendTimer[`seq_${T}`]; S && clearTimeout(S), delete this.sendReslove[`seq_${T}`], delete this.sendReject[`seq_${T}`]; } else this.dispatchEvent("message", u, (T) => { const F = u && u.data && u.data.seq; let S = { success: !0 }; typeof T == "boolean" ? S.success = T : typeof T == "object" && (S = T), this[sendAck](F, ACK, S, p); }); }), this.readyState = this.ws.readyState, new Promise((a, u) => { const l = ["open", "close", "error"]; for (let h = 0; h < l.length; h++) this.ws.addEventListener(l[h], (p) => { const { type: g } = p; this.readyState = this.ws.readyState, clearTimeout(this.reconnectTimer), g === "open" ? (this.closed = !1, this.hartbeat(), a(p)) : (!this.closed && this.readyState !== 1 && this._autoReconnect(), this.dispatchEvent("serverDelay", NaN), this.dispatchEvent("clientDelay", NaN), this.status.up = 0, this.status.down = 0, u(p)), this.dispatchEvent(l[h], p); }); }); } send(t, e = !1) { return this[sender](t, e, SEQ); } ping() { return this[sender](null, !1, "PING"); } sendState(t, e = !1) { return this[sender](t, e, STATE); } sendControll(t, e = !1) { return this[sender](t, e, CONTROLL); } sendAction(t, e = !0) { return this[sender](t, e, ACTION); } sendRTS(t, e = !0) { return this[sender](t, e, RTS); } sendInfo(t, e = !1) { return this[sender](t, e, INFO); } sendLog(t) { return this[sender](t, !1, LOG); } sendCustomize(t, e, i = !1) { if (typeof e == "string") return this[sender](t, !!i, e); } getState(t, e = !0) { return this[sender](t, e, GET); } reconnect() { this.readyState !== 1 ? this.connect(this.url, this.remoteId, this.confirm).then(() => { this.dispatchEvent("reconnect", "network"); }) : this.dispatchEvent("reconnect", !0); } _autoReconnect() { this.closed || (this.reconnectTimer = setTimeout(() => { this.dispatchEvent("reconnecting", !0), this.connect(this.url, this.remoteId, this.confirm).then(() => { this.dispatchEvent("reconnect", !0); }).catch(() => { }); }, 1e3 * this._updateGap())); } _updateGap() { if (!this._breakpoint.length) { for (let e = 1; e <= 5; e++) { let i = 10 * (10 + 5 * (e - 1)) * 100 + (this._breakpoint[e - 2] || 0); this._breakpoint.push(i); } return 1; } let t = this._breakpoint.findIndex((e) => e > this._gap); return this._gap = this._gap + 100 * (10 + 5 * t), ~t ? 2 + 1 * t : 60; } hartbeat() { this.hartbeatTimer = setTimeout(() => { this.ping().catch((t) => console.log(t)), this.serverTimeoutTimer = setTimeout(() => { this.ws.close(4003, "ping timeout"); }, 3e3); }, 3e4); } close(t, e) { this.closed = !0, this.ws && this.ws.close(t, e), clearTimeout(this.serverTimeoutTimer), clearTimeout(this.hartbeatTimer), Object.values(this.sendTimer).forEach((i) => { clearTimeout(i); }); } } const WS = /* @__PURE__ */ function() { let r; return function(t, e, i = !1) { return r || (r = new Remote(t, e, i)); }; }(); class RemoteServer { constructor(t) { return this.ws = new WS(), t && t.test(/^ws(s)?:\/\//.test(t)) && this.ws.connect(t), this.ws; } } function createInstance(r) { var t = new WS(); return r && r.test(/^ws(s)?:\/\//.test(r)) && t.connect(r), t; } let remote$1 = /* @__PURE__ */ function() { let r; return function(t, e) { return r ? (r.config = t, r) : (r = new RemoteServer(e), r.config = t, r); }; }(); remote$1.create = function(r) { return createInstance(r); }; const TIMEOUT$1 = 6e3, eventType$a = { logined: "logined" }, setGlobal = (r) => { Object.assign(window, r), document.title = __ANOV__ENV.projectName, document.querySelector("#projectName").innerText = __ANOV__ENV.projectName, document.querySelector("#copyright").innerText = __ANOV__ENV.copyright; }; class AdminServer extends BaseServer { constructor() { super("admin"), this.addEventListener("connected"), this.getEventBus().$on("logging", this._addLogToServer.bind(this)); } get serverPath() { return this.callState("serverPath"); } get connected() { return this.callState("connected"); } get isActive() { return this.callState("isActive"); } setConnected(t) { this.callMutation("setConnected", t); } setServerPath(t) { this.callMutation("setServerPath", t); } setIsActive(t) { this.callMutation("setIsActive", t); } init(t) { let e = this._extractConfig(t); if (!e.serverPath) return void this.addWarn("Server address not configured,[serverPath] is null."); this.setServerPath(e.serverPath); let i = e.timeout || TIMEOUT$1; this._http = axios.create({ baseURL: this.serverPath, timeout: i, headers: { "Content-Type": "application/json;charset=UTF-8" }, withCredentials: !0 }), httpInterceptors.init({ http: this._http, request: !0, response: !0 }), this._httpScreenshot = axios.create({ timeout: i, headers: { "Content-Type": "application/json;charset=UTF-8" }, withCredentials: !0 }), httpInterceptors.init({ http: this._httpScreenshot, request: !0, response: !0 }), this.ws = remote$1(t.remote); } getVerifyCodeImg(t) { this._http && this._http.get("/auth/code").then((e) => { t && t(e); }).catch((e) => { t && t(!1), this.addError(e.message); }); } login(t, e) { this._http && this._http.post("/auth/login", { name: t.name, code: t.code, imgCode: t.imgCode, uuid: t.uuid }).then((i) => { e && e(i), this.dispatchEvent({ type: eventType$a.logined, result: i }); }).catch((i) => { e && e(i), this.addError(i.message); }).finally(() => { }); } getConfig(t, e) { return t.key ? __ANOV__ENV ? this._http({ url: `/api/devs/v1/${t.key}/verify?rnd=` + Math.random(), headers: { "X-Anov-Version": __ANOV__ENV.platformVersion, "X-Anov-Core-Version": __ANOV__ENV.platformCoreVersion, "X-Anov-Level": __ANOV__ENV.level || "", "X-Anov-Debug": __ANOV__ENV.debug, "X-Anov-Dir": encodeURIComponent(__ANOV__ENV.projectLocalDir), "X-Anov-Client-Code": t.code || __ANOV__ENV.pkgid }, method: "post", data: { pkginfo: token$1.ct(__ANOV__ENV.pkginfo, (/* @__PURE__ */ new Date()).getTime()) } }).then((i) => (e && e(i), this.code = i.data ? i.data.clientCode : "", i)).catch((i) => (this.addError(i && i.msg), e && e(!1), Promise.reject(i))) : (console.warn("__ANOV__ENV全局对象未配置。"), e && e(!1), Promise.reject(1)) : (this.addError("ProjectId is null"), e && e(!1), Promise.reject(0)); } vaildateToken(t) { return token$1.vt(t); } _init_screenshot_params(t) { this._httpScreenshot && this._httpScreenshot.post("/take", { origin: this.serverPath, ...t }).catch(() => { }); } _screenshot_upload() { if (process.env.NODE_ENV === "development" && this._httpScreenshot) return this._httpScreenshot.post("/upload").catch(() => { }); } _addLogToServer(t) { if (!this.ws || !__ANOV__ENV.projectId || this.ws.readyState !== 1) return; const { module: e, msg: i, type: o } = t; this.ws.sendLog({ logType: o.toUpperCase(), logModule: e.toUpperCase(), logDesc: i }).catch((s) => { console.log(s); }); } screenshotUpload(t, e) { let i = new FormData(); i.append("file", t), this._http.post("/api/localStorage/screenFileUpLoad", i).then((o) => { e && e(o); }).catch((o) => { }); } saveScreenImg(t, e) { let i = { screenImg: t.id, screenKey: t.key }; this._http.post("/api/devBigScreen/saveScreenImg", i).then((o) => { e && e(o); }).catch((o) => { }); } getTerminalInfo(t, e) { this._http && this._http.get(`/api/devScreenOnline/findOnlineApp?key=${t.key}&code=${t.code}`).then((i) => { e && e(i); }).catch((i) => { this.addError(i.message), e && e(!1); }); } shareCodeVerify(t, e) { this._http && this._http.get(`/api/v1/go/v1/${t.key}/check/${t.code}`).then((i) => { e && e(i); }).catch((i) => { this.addError(i.message), e && e(!1); }); } } const adminServer = new AdminServer(); Object.defineProperty(adminServer, "setGlobal", { value: setGlobal, writable: !1, configurable: !1 }); class RuntimeServer extends BaseServer { constructor() { super("runtime"); } init(r) { this._sysConfigInit(r); } setAppStore(r) { r && BaseServer._setAppStore(r); } setCurrentContext(r) { r && BaseServer._setCurrentContext(r); } exec(code) { try { eval(code); } catch (r) { this.addError("代码注入异常:" + error.stack); } } _sysConfigInit(r) { let t = window.location.href.split("?")[1] || ""; t = t.split("#")[0]; let e = qs.parse(t, { allowDots: !0, decoder: function(i, o) { return i === "true" || i !== "false" && o(i = i.replace(/\%20|\+/g, "%2B")); } }); merge(r, e); } } const runtimeServer = new RuntimeServer(), eventType$9 = { execAction: "execAction" }; class ActionServer extends BaseServer { constructor() { super("action"), this._items = []; } init(t) { } addActions(t) { Array.isArray(t) ? t.map((e) => { this._add(e); }) : this._add(t); } removeActions(t) { Array.isArray(t) ? t.map((e) => { this._remove(e); }) : this._remove(t); } getActionById(t) { return this._items.find((e) => e.id === t); } getActionByName(t) { return this._items.find((e) => e.name === t); } getActions() { return this._items; } exec(t, e, i = !0) { let o = this.getActionById(t) || this.getActionByName(t); o ? (o.exec(this.getCurrentContext(), e), i && this.addInfo("执行动作 " + o.id + ":" + o.name), this.dispatchEvent({ type: eventType$9.execAction, result: o })) : i && this.addWarn("动作不存在"); } _add(t) { this._items.find((e) => e.id === t.id) ? this.addError("Anov.ActionServer._add(action):Unable to add, because " + t.id + " action is exists") : this._items.push(t); } _remove(t) { this._items.splice(this._items.findIndex((e) => e.id === t), 1); } } class Action { constructor(t) { this.id = t.id, this.name = t.name, this.exec = t.exec; } exec(t) { this.exec && this.exec(...t); } } const actionServer = new ActionServer(); class DataSourceServer extends BaseServer { constructor() { super("dataSource"), this._ds = {}; } init(t) { let e = this._extractConfig(t); this.type = e.type, this.dataPlan = t.dataPlan; } addDataSources(t) { this._ds = t; } get type() { return this.callState("type"); } set type(t) { this.type != t && this.callMutation("setType", t); } get dataPlan() { return this.callState("dataPlan"); } set dataPlan(t) { this.callMutation("setDataPlan", t); } get currentPlan() { return this.callState("currentPlan"); } set currentPlan(t) { let e = ""; this.dataPlan && this.pagePlan.option && (e = this.pagePlan.option.find((i) => i.plan == t)), e ? this.callMutation("setCurrentPlan", t) : this.addError(`${t} no exits!`); } get pagePlan() { return this.callState("pagePlan"); } set pagePlan(t) { this.callMutation("setPagePlan", t); } create() { return this._ds[this.type.toUpperCase()]; } setOption(t) { Array.isArray(t) && this.callMutation("SET_OPTION", t); } setDataPlan(t) { Array.isArray(t) && this.callMutation("setDataPlan", t); } initPagePlan(t) { let e = t || this.getCurrentContext().$router.currentRoute.path; this.dataPlan && this.dataPlan.forEach((i) => { i.path == e && (this.pagePlan = i, this.currentPlan = i.plan); }); } } const dataSourceServer = new DataSourceServer(), codeString$1 = `self.onmessage = function (e) { switch (e.data.command) { case "transform": transform.transaction(e.data.buffer); break; } } var transform = { transaction(buffer) { let bufTo16kHz = transform.to16kHz(buffer) let bufTo16BitPCM = transform.to16BitPCM(bufTo16kHz) // let bufToBase64 = transform.toBase64(bufTo16BitPCM) self.postMessage({ 'buffer': bufTo16BitPCM }) }, to16kHz(buffer) { var data = new Float32Array(buffer) var fitCount = Math.round(data.length * (16000 / 44100)) var newData = new Float32Array(fitCount) var springFactor = (data.length - 1) / (fitCount - 1) newData[0] = data[0] for (let i = 1; i < fitCount - 1; i++) { var tmp = i * springFactor var before = Math.floor(tmp).toFixed() var after = Math.ceil(tmp).toFixed() var atPoint = tmp - before newData[i] = data[before] + (data[after] - data[before]) * atPoint } newData[fitCount - 1] = data[data.length - 1] return newData }, to16BitPCM(input) { var dataLength = input.length * (16 / 8) var dataBuffer = new ArrayBuffer(dataLength) var dataView = new DataView(dataBuffer) var offset = 0 for (var i = 0; i < input.length; i++, offset += 2) { var s = Math.max(-1, Math.min(1, input[i])) dataView.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true) } return Array.from(new Int8Array(dataView.buffer)) }, toBase64(buffer) { var binary = '' var bytes = new Uint8Array(buffer) var len = bytes.byteLength for (var i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]) } return window.btoa(binary) } }`; var blob$1 = new Blob([codeString$1]), url$1 = window.URL.createObjectURL(blob$1); let recorderWorker = new Worker(url$1), buffer$1 = [], AudioContext = window.AudioContext || window.webkitAudioContext; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia, recorderWorker.onmessage = function(r) { buffer$1.push(...r.data.buffer); }; class IatRecorder { constructor(t = {}) { this.config = t, this.state = "ing", this.xfid = this.config.configInfo.ID, this.whisper = this.config.configInfo.WHISPER, this.uri = this.config.configInfo.xfUri; } isSupport() { return !!(navigator.getUserMedia && AudioContext && recorderWorker); } start() { if (this.isSupport() && !this.ws) { this.abort(), this.state = "ing"; var t = new AudioContext(); this.context = t, this.recorder = t.createScriptProcessor(0, 1, 1); var e = (o) => { if (t.state === "running") { this._mediaStreamTrack = o; var s = this.context.createMediaStreamSource(o); this.mediaStream = s, this.recorder.onaudioprocess = (a) => { this.sendData(a.inputBuffer.getChannelData(0)); }, this.connectWebsocket(); } else this.config.onError && this.config.onError({ error: "getMediaFail" }); }, i = (o) => { this.recorder = null, this.mediaStream = null, this.context = null, this.config.onError && this.config.onError({ error: "getMediaFail" }); }; navigator.mediaDevices && navigator.mediaDevices.getUserMedia ? navigator.mediaDevices.getUserMedia({ audio: !0, video: !1 }).then((o) => { e(o); }).catch((o) => { i(); }) : navigator.getUserMedia({ audio: !0, video: !1 }, (o) => { e(o); }, function(o) { i(); }); } else this.isSupport() || this.config.onError && this.config.onError({ error: "getMediaFail" }); } abort() { this.state = "end"; try { if (this._mediaStreamTrack && this._mediaStreamTrack.getTracks().forEach((t) => { t.stop(); }), this.context && this.context.suspend(), this.mediaStream && this.recorder) try { this.recorder.disconnect(), this.mediaStream.disconnect(); } catch (t) { console.log("Disconnect error:", t); } this.mediaStream = null, this.recorder = null, this._mediaStreamTrack = null; } catch (t) { console.log("讯飞abort error", t); } } pause() { this.context.state === "running" && this.context.suspend(); } resume() { this.context.state === "suspended" && this.context.resume(); } sendData(t) { recorderWorker.postMessage({ command: "transform", buffer: t }); } getHandShakeParams() { var t = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3), e = CryptoJS.MD5(this.xfid + t).toString(), i = CryptoJS.HmacSHA1(e, this.whisper), o = CryptoJS.enc.Base64.stringify(i); return o = encodeURIComponent(o), "?appid=" + this.xfid + "&ts=" + t + "&signa=" + o; } connectWebsocket() { console.log("asdddd", this.uri); var t = this.uri; if (t = `${t}${this.getHandShakeParams()}`, "WebSocket" in window) this.ws = new WebSocket(t); else { if (!("MozWebSocket" in window)) return this.config.onError && this.config.onError({ error: "not-websocket" }), null; this.ws = new MozWebSocket(t); } this.ws.onopen = (e) => { this.mediaStream.connect(this.recorder), this.recorder.connect(this.context.destination), setTimeout(() => { this.wsOpened(e); }, 500); }, this.ws.onmessage = (e) => { this.wsOnMessage(e); }, this.ws.onerror = (e) => { this.abort(), this.config.onError && this.config.onError({ error: "network" }); }, this.ws.onclose = (e) => { this.abort(), this.ws = null; }; } wsOpened() { if (this.ws && this.ws.readyState === 1) { var t = buffer$1.splice(0, 2560); this.ws.send(new Int8Array(t)), this.clearBuffer = setInterval(() => { buffer$1.length > 3e3 && (buffer$1 = []); }, 1e3), this.handlerInterval = setInterval(() => { if (this.ws && this.ws.readyState !== 1) return clearInterval(this.clearBuffer), void clearInterval(this.handlerInterval); if (buffer$1.length === 0) return this.state === "end" && this.ws && (this.ws.close(), this.ws = null, clearInterval(this.handlerInterval), clearInterval(this.clearBuffer)), !1; var e = buffer$1.splice(0, 2560); e.length > 0 && this.ws && this.ws.send(new Int8Array(e)); }, 40); } } wsOnMessage(t) { let e = JSON.parse(t.data); e.action == "started" ? this.config.onStart && this.config.onStart(t) : e.action == "result" ? (this.state !== "end" && this.config.onSoundStart && this.config.onSoundStart(), this.setResult(JSON.parse(e.data))) : e.action == "error" && (console.log("实时语音转写API错误码" + e.code), e.code === "10110" ? this.config.onError && this.config.onError({ error: "no-license" }) : this.config.onError && this.config.onError({ error: "websocket" })); } setResult(t) { if (t.cn.st.type != 0) return; let e = ""; t.cn.st.rt[0].ws.forEach((i, o) => { o != 0 || i.cw[0].w != "," && i.cw[0].w != "。" && i.cw[0].w != "、" && i.cw[0].w != "?" || (i.cw[0].w = ""), i.cw[0].w != "啊" && i.cw[0].w != "嗯" && i.cw[0].w != "呃" && i.cw[0].w != "唉" && i.cw[0].w != "噢" || (i.cw[0].w = ""), e += i.cw[0].w; }), e.length >= 2 && this.config.onMessage && this.config.onMessage([e], t.cn.st.type); } } (function(r) { var t = function() { }, e = function(f) { return new w(f); }; e.LM = "2023-02-01 18:05"; var i = "Recorder", o = "getUserMedia", s = "srcSampleRate", a = "sampleRate", u = "catch"; e.IsOpen = function() { var f = e.Stream; if (f) { var y = (f.getTracks && f.getTracks() || f.audioTracks || [])[0]; if (y) { var x = y.readyState; return x == "live" || x == y.LIVE; } } return !1; }, e.BufferSize = 4096, e.Destroy = function() { for (var f in S(i + " Destroy"), F(), l) l[f](); }; var l = {}; e.BindDestroy = function(f, y) { l[f] = y; }, e.Support = function() { var f = navigator.mediaDevices || {}; return f[o] || (f = navigator)[o] || (f[o] = f.webkitGetUserMedia || f.mozGetUserMedia || f.msGetUserMedia), !!f[o] && (e.Scope = f, !!e.GetContext()); }, e.GetContext = function() { var f = r.AudioContext; return f || (f = r.webkitAudioContext), f ? (e.Ctx && e.Ctx.state != "closed" || (e.Ctx = new f(), e.BindDestroy("Ctx", function() { var y = e.Ctx; y && y.close && (y.close(), e.Ctx = 0); })), e.Ctx) : null; }; var h = "ConnectEnableWebM"; e[h] = !0; var p = "ConnectEnableWorklet"; e[p] = !1; var g = function(f, y) { var x, k, O, L = f.BufferSize || e.BufferSize, V = e.Ctx, H = f.Stream, q = function(Et) { var jt = H._m = V.createMediaStreamSource(H), $t = V.destination, Lt = "createMediaStreamDestination"; V[Lt] && ($t = V[Lt]()), jt.connect(Et), Et.connect($t); }, et = "", I = H._call, it = function(Et) { for (var jt in I) { for (var $t = Et.length, Lt = new Int16Array($t), Ht = 0, Jt = 0; Jt < $t; Jt++) { var It = Math.max(-1, Math.min(1, Et[Jt])); It = It < 0 ? 32768 * It : 32767 * It, Lt[Jt] = It, Ht += Math.abs(It); } for (var Ut in I) I[Ut](Lt, Ht); return; } }, dt = "ScriptProcessor", K = "audioWorklet", lt = i + " " + K, Q = "RecProc", nt = "MediaRecorder", ct = nt + ".WebM.PCM", J = V.createScriptProcessor || V.createJavaScriptNode, St = "。由于" + K + "内部1秒375次回调,在移动端可能会有性能问题导致回调丢失录音变短,PC端无影响,暂不建议开启" + K + "。", kt = function() { k = H.isWorklet = !1, C(H), S("Connect采用老的" + dt + "," + (e[p] ? "但已" : "可") + "设置" + i + "." + p + "=true尝试启用" + K + et + St, 3); var Et = H._p = J.call(V, L, 1, 1); q(Et); var jt = "_D220626", $t = e[jt]; $t && S("Use " + i + "." + jt, 3), Et.onaudioprocess = function(Lt) { var Ht = Lt.inputBuffer.getChannelData(0); $t ? (Ht = new Float32Array(Ht), setTimeout(function() { it(Ht); })) : it(Ht); }; }, v = function() { x = H.isWebM = !1, T(H), k = H.isWorklet = !J || e[p]; var Et = r.AudioWorkletNode; if (k && V[K] && Et) { var jt = function() { return k && H._na; }, $t = H._na = function() { O !== "" && (clearTimeout(O), O = setTimeout(function() { O = 0, jt() && (S(K + "未返回任何音频,恢复使用" + dt, 3), J && kt()); }, 500)); }, Lt = function() { if (jt()) { var Ht = H._n = new Et(V, Q, { processorOptions: { bufferSize: L } }); q(Ht), Ht.port.onmessage = function(Jt) { O && (clearTimeout(O), O = ""), jt() ? it(Jt.data.val) : k || S(K + "多余回调", 3); }, S("Connect采用" + K + ",设置" + i + "." + p + "=false可恢复老式" + dt + et + St, 3); } }; V.resume()[I && "finally"](function() { if (jt()) if (V[Q]) Lt(); else { var Ht = (It = "class " + Q + " extends AudioWorkletProcessor{", It += "constructor " + (Jt = function(Ut) { return Ut.toString().replace(/^function|DEL_/g, "").replace(/\$RA/g, lt); })(function(Ut) { DEL_super(Ut); var Gt = this, te = Ut.processorOptions.bufferSize; Gt.bufferSize = te, Gt.buffer = new Float32Array(2 * te), Gt.pos = 0, Gt.port.onmessage = function(bt) { bt.data.kill && (Gt.kill = !0, console.log("$RA kill call")); }, console.log("$RA .ctor call", Ut); }), It += "process " + Jt(function(Ut, Gt, te) { var bt = this, me = bt.bufferSize, ee = bt.buffer, Mt = bt.pos; if ((Ut = (Ut[0] || [])[0] || []).length) { ee.set(Ut, Mt); var ye = ~~((Mt += Ut.length) / me) * me; if (ye) { this.port.postMessage({ val: ee.slice(0, ye) }); var Ct = ee.subarray(ye, Mt); (ee = new Float32Array(2 * me)).set(Ct), Mt = Ct.length, bt.buffer = ee; } bt.pos = Mt; } return !bt.kill; }), It += '}try{registerProcessor("' + Q + '", ' + Q + ')}catch(e){console.error("' + lt + '注册失败",e)}', "data:text/javascript;base64," + btoa(unescape(encodeURIComponent(It)))); V[K].addModule(Ht).then(function(Ut) { jt() && (V[Q] = 1, Lt(), O && $t()); })[u](function(Ut) { S(K + ".addModule失败", 1, Ut), jt() && kt(); }); } var Jt, It; }); } else kt(); }; (function() { var Et = r[nt], jt = "ondataavailable", $t = "audio/webm; codecs=pcm"; x = H.isWebM = e[h]; var Lt = Et && jt in Et.prototype && Et.isTypeSupported($t); if (et = Lt ? "" : "(此浏览器不支持" + ct + ")", y && x && Lt) { var Ht = function() { return x && H._ra; }; H._ra = function() { O !== "" && (clearTimeout(O), O = setTimeout(function() { Ht() && (S(nt + "未返回任何音频,降级使用" + K, 3), v()); }, 500)); }; var Jt = Object.assign({ mimeType: $t }, e.ConnectWebMOptions), It = H._r = new Et(H, Jt), Ut = H._rd = { sampleRate: V[a] }; It[jt] = function(Gt) { var te = new FileReader(); te.onloadend = function() { if (Ht()) { var bt = A(new Uint8Array(te.result), Ut); if (!bt) return; if (bt == -1) return void v(); O && (clearTimeout(O), O = ""), it(bt); } else x || S(nt + "多余回调", 3); }, te.readAsArrayBuffer(Gt.data); }, It.start(~~(L / 48)), S("Connect采用" + ct + ",设置" + i + "." + h + "=false可恢复使用" + K + "或老式" + dt); } else v(); })(); }, C = function(f) { f._na = null, f._n && (f._n.port.postMessage({ kill: !0 }), f._n.disconnect(), f._n = null); }, T = function(f) { f._ra = null, f._r && (f._r.stop(), f._r = null); }, F = function(f) { var y = (f = f || e) == e, x = f.Stream; if (x && (x._m && (x._m.disconnect(), x._m = null), x._p && (x._p.disconnect(), x._p.onaudioprocess = x._p = null), C(x), T(x), y)) { for (var k = x.getTracks && x.getTracks() || x.audioTracks || [], O = 0; O < k.length; O++) { var L = k[O]; L.stop && L.stop(); } x.stop && x.stop(); } f.Stream = 0; }; e.SampleData = function(f, y, x, k, O) { k || (k = {}); var L = k.index || 0, V = k.offset || 0, H = k.frameNext || []; O || (O = {}); var q = O.frameSize || 1; O.frameType && (q = O.frameType == "mp3" ? 1152 : 1); var et = f.length; L > et + 1 && S("SampleData似乎传入了未重置chunk " + L + ">" + et, 3); for (var I = 0, it = L; it < et; it++) I += f[it].length; I = Math.max(0, I - Math.floor(V)); var dt = y / x; dt > 1 ? I = Math.floor(I / dt) : (dt = 1, x = y), I += H.length; var K = new Int16Array(I), lt = 0; for (it = 0; it < H.length; it++) K[lt] = H[it], lt++; for (; L < et; L++) { for (var Q = f[L], nt = (it = V, Q.length); it < nt; ) { var ct = Math.floor(it), J = Math.ceil(it), St = it - ct, kt = Q[ct], v = J < nt ? Q[J] : (f[L + 1] || [kt])[0] || 0; K[lt] = kt + (v - kt) * St, lt++, it += dt; } V = it - nt; } H = null; var Et = K.length % q; if (Et > 0) { var jt = 2 * (K.length - Et); H = new Int16Array(K.buffer.slice(jt)), K = new Int16Array(K.buffer.slice(0, jt)); } return { index: L, offset: V, frameNext: H, sampleRate: x, data: K }; }, e.PowerLevel = function(f, y) { var x = f / y || 0; return x < 1251 ? Math.round(x / 1250 * 10) : Math.round(Math.min(100, Math.max(0, 100 * (1 + Math.log(x / 1e4) / Math.log(10))))); }, e.PowerDBFS = function(f) { var y = Math.max(0.1, f || 0); return y = Math.min(y, 32767), y = 20 * Math.log(y / 32767) / Math.log(10), Math.max(-100, Math.round(y)); }, e.CLog = function(f, y) { var x = /* @__PURE__ */ new Date(), k = ("0" + x.getMinutes()).substr(-2) + ":" + ("0" + x.getSeconds()).substr(-2) + "." + ("00" + x.getMilliseconds()).substr(-3), O = this && this.envIn && this.envCheck && this.id, L = ["[" + k + " " + i + (O ? ":" + O : "") + "]" + f], V = arguments, H = r.console || {}, q = 2, et = H.log; for (typeof y == "number" ? et = y == 1 ? H.error : y == 3 ? H.warn : et : q = 1; q < V.length; q++) L.push(V[q]); m ? et && et("[IsLoser]" + L[0], L.length > 1 ? L : "") : et.apply(H, L); }; var S = function() { e.CLog.apply(this, arguments); }, m = !0; try { m = !console.log.apply; } catch { } var D = 0; function w(f) { this.id = ++D, z(); var y = { type: "mp3", bitRate: 16, sampleRate: 16e3, onProcess: t }; for (var x in f) y[x] = f[x]; this.set = y, this._S = 9, this.Sync = { O: 9, C: 9 }; } e.Sync = { O: 9, C: 9 }, e.prototype = w.prototype = { CLog: S, _streamStore: function() { return this.set.sourceStream ? this : e; }, open: function(f, y) { var x = this, k = x._streamStore(); f = f || t; var O = function(ct, J) { J = !!J, x.CLog("录音open失败:" + ct + ",isUserNotAllow:" + J, 1), y && y(ct, J); }, L = function() { x.CLog("open ok id:" + x.id), f(), x._SO = 0; }, V = k.Sync, H = ++V.O, q = V.C; x._O = x._O_ = H, x._SO = x._S; var et = x.envCheck({ envName: "H5", canProcess: !0 }); if (et) O("不能录音:" + et); else if (x.set.sourceStream) { if (!e.GetContext()) return void O("不支持此浏览器从流中获取录音"); F(k), x.Stream = x.set.sourceStream, x.Stream._call = {}; try { g(k); } catch (ct) { return void O("从流中打开录音失败:" + ct.message); } L(); } else { var I = function(ct, J) { try { r.top.a; } catch { return void O('无权录音(跨域,请尝试给iframe添加麦克风访问策略,如allow="camera;microphone")'); } /Permission|Allow/i.test(ct) ? O("用户拒绝了录音权限", !0) : r.isSecureContext === !1 ? O("浏览器禁止不安全页面录音,可开启https解决") : /Found/i.test(ct) ? O(J + ",无可用麦克风") : O(J); }; if (e.IsOpen()) L(); else if (e.Support()) { var it = function(ct) { setTimeout(function() { ct._call = {}; var J = e.Stream; J && (F(), ct._call = J._call), e.Stream = ct, function() { if (q != V.C || !x._O) { var St = "open被取消"; return H == V.O ? x.close() : St = "open被中断", O(St), !0; } }() || (e.IsOpen() ? (J && x.CLog("发现同时多次调用open", 1), g(k, 1), L()) : O("录音功能无效:无音频流")); }, 100); }, dt = function(ct) { var J = ct.name || ct.message || ct.code + ":" + ct; x.CLog("请求录音权限错误", 1, ct), I(J, "无法录音:" + J); }, K = { noiseSuppression: !1, echoCancellation: !1 }, lt = x.set.audioTrackSet; for (var Q in lt) K[Q] = lt[Q]; K.sampleRate = e.Ctx.sampleRate; try { var nt = e.Scope[o]({ audio: K }, it, dt); } catch (ct) { x.CLog(o, 3, ct), nt = e.Scope[o]({ audio: !0 }, it, dt); } nt && nt.then && nt.then(it)[u](dt); } else I("", "此浏览器不支持录音"); } }, close: function(f) { f = f || t; var y = this, x = y._streamStore(); y._stop(); var k = x.Sync; if (y._O = 0, y._O_ != k.O) return y.CLog("close被忽略(因为同时open了多个rec,只有最后一个会真正close)", 3), void f(); k.C++, F(x), y.CLog("close"), f(); }, mock: function(f, y) { var x = this; return x._stop(), x.isMock = 1, x.mockEnvInfo = null, x.buffers = [f], x.recSize = f.length, x[s] = y, x; }, envCheck: function(f) { var y, x = this, k = x.set, O = "CPU_BE"; if (y || e[O] || !r.Int8Array || new Int8Array(new Int32Array([1]).buffer)[0] || (z(O), y = "不支持" + O + "架构"), !y) { var L = k.type; x[L + "_envCheck"] ? y = x[L + "_envCheck"](f, k) : k.takeoffEncodeChunk && (y = L + "类型" + (x[L] ? "" : "(未加载编码器)") + "不支持设置takeoffEncodeChunk"); } return y || ""; }, envStart: function(f, y) { var x = this, k = x.set; x.isMock = f ? 1 : 0, x.mockEnvInfo = f, x.buffers = [], x.recSize = 0, x.envInLast = 0, x.envInFirst = 0, x.envInFix = 0, x.envInFixTs = []; var O = k[a]; if (O > y ? k[a] = y : O = 0, x[s] = y, x.CLog(s + ": " + y + " set." + a + ": " + k[a] + (O ? " 忽略" + O : ""), O ? 3 : 0), x.engineCtx = 0, x[k.type + "_start"]) { var L = x.engineCtx = x[k.type + "_start"](k); L && (L.pcmDatas = [], L.pcmSize = 0); } }, envResume: function() { this.envInFixTs = []; }, envIn: function(f, y) { var x = this, k = x.set, O = x.engineCtx, L = x[s], V = f.length, H = e.PowerLevel(y, V), q = x.buffers, et = q.length; q.push(f); var I = q, it = et, dt = Date.now(), K = Math.round(V / L * 1e3); x.envInLast = dt, x.buffers.length == 1 && (x.envInFirst = dt - K); var lt = x.envInFixTs; lt.splice(0, 0, { t: dt, d: K }); for (var Q = dt, nt = 0, ct = 0; ct < lt.length; ct++) { var J = lt[ct]; if (dt - J.t > 3e3) { lt.length = ct; break; } Q = J.t, nt += J.d; } var St = lt[1], kt = dt - Q; if (kt - nt > kt / 3 && (St && kt > 1e3 || lt.length >= 6)) { var v = dt - St.t - K; if (v > K / 5) { var Et = !k.disableEnvInFix; if (x.CLog("[" + dt + "]" + (Et ? "" : "未") + "补偿" + v + "ms", 3), x.envInFix += v, Et) { var jt = new Int16Array(v * L / 1e3); V += jt.length, q.push(jt); } } } var $t = x.recSize, Lt = V, Ht = $t + Lt; if (x.recSize = Ht, O) { var Jt = e.SampleData(q, L, k[a], O.chunkInfo); O.chunkInfo = Jt, Ht = ($t = O.pcmSize) + (Lt = Jt.data.length), O.pcmSize = Ht, q = O.pcmDatas, et = q.length, q.push(Jt.data), L = Jt[a]; } var It = Math.round(Ht / L * 1e3), Ut = q.length, Gt = I.length, te = function() { for (var ye = bt ? 0 : -Lt, Ct = q[0] == null, Ot = et; Ot < Ut; Ot++) { var _e = q[Ot]; _e == null ? Ct = 1 : (ye += _e.length, O && _e.length && x[k.type + "_encode"](O, _e)); } if (Ct && O) for (Ot = it, I[0] && (Ot = 0); Ot < Gt; Ot++) I[Ot] = null; Ct && (ye = bt ? Lt : 0, q[0] = null), O ? O.pcmSize += ye : x.recSize += ye; }, bt = 0, me = "rec.set.onProcess"; try { bt = k.onProcess(q, H, It, L, et, te); } catch (ye) { console.error(me + "回调出错是不允许的,需保证不会抛异常", ye); } var ee = Date.now() - dt; if (ee > 10 && x.envInFirst - dt > 1e3 && x.CLog(me + "低性能,耗时" + ee + "ms", 3), bt === !0) { var Mt = 0; for (ct = et; ct < Ut; ct++) q[ct] == null ? Mt = 1 : q[ct] = new Int16Array(0); Mt ? x.CLog("未进入异步前不能清除buffers", 3) : O ? O.pcmSize -= Lt : x.recSize -= Lt; } else te(); }, start: function() { var f = this, y = e.Ctx, x = 1; if (f.set.sourceStream ? f.Stream || (x = 0) : e.IsOpen() || (x = 0), x) if (f.CLog("开始录音"), f._stop(), f.state = 3, f.envStart(null, y[a]), f._SO && f._SO + 1 != f._S) f.CLog("start被中断", 3); else { f._SO = 0; var k = function() { f.state == 3 && (f.state = 1, f.resume()); }; if (y.state == "suspended") { var O = "AudioContext resume