@crh-fe/oava-customer-sdk 1.0.56 → 1.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/customerComponent.js +1134 -134
- package/dist/customerComponent.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
/*
|
|
3
|
-
* Version: 1.0.
|
|
4
|
-
* Build Time: 2026/11/
|
|
3
|
+
* Version: 1.0.59
|
|
4
|
+
* Build Time: 2026/11/26 15:07:18
|
|
5
5
|
*/
|
|
6
6
|
var commonjsGlobal = 'undefined' != typeof globalThis ? globalThis : 'undefined' != typeof window ? window : 'undefined' != typeof global ? global : 'undefined' != typeof self ? self : {};
|
|
7
7
|
|
|
@@ -8069,6 +8069,19 @@ function captureLocal(videoId) {
|
|
|
8069
8069
|
}));
|
|
8070
8070
|
}
|
|
8071
8071
|
|
|
8072
|
+
function getAnswerLists(correct_answerlist, error_answerlist) {
|
|
8073
|
+
let error_answer = error_answerlist || '不是,不是的,不是啊,不对,否';
|
|
8074
|
+
return {
|
|
8075
|
+
whiteList: (correct_answerlist || '是,是的,是啊,对的,是的是的,是的是的是的,是是,是是的,是的的,是是的是的,是的的,嗯,对,行,没错,确实,那是,绝对是,对的').split(','),
|
|
8076
|
+
blackList: error_answer.split(',')
|
|
8077
|
+
};
|
|
8078
|
+
}
|
|
8079
|
+
|
|
8080
|
+
function matchAnswerResult(resultText, correct_answerlist, error_answerlist) {
|
|
8081
|
+
const {whiteList, blackList} = getAnswerLists(correct_answerlist, error_answerlist);
|
|
8082
|
+
return whiteList.includes(resultText) ? 1 : blackList.includes(resultText) ? 2 : 3;
|
|
8083
|
+
}
|
|
8084
|
+
|
|
8072
8085
|
function commonjsRequire(path) {
|
|
8073
8086
|
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
8074
8087
|
}
|
|
@@ -20893,7 +20906,8 @@ class IRtcClient extends EventTarget {
|
|
|
20893
20906
|
}
|
|
20894
20907
|
let customEvent = new CustomEvent(IRTC_CUSTOMEREVENT.MESSAGE, {
|
|
20895
20908
|
detail: {
|
|
20896
|
-
message: eve.message
|
|
20909
|
+
message: eve.message,
|
|
20910
|
+
origin: eve.origin
|
|
20897
20911
|
}
|
|
20898
20912
|
});
|
|
20899
20913
|
this.dispatchEvent(customEvent);
|
|
@@ -21995,8 +22009,9 @@ class ComponentClient extends EventTarget {
|
|
|
21995
22009
|
this.publication && this.publication.stop(), this.localStream && this.client.stopStream(this.localStream);
|
|
21996
22010
|
}
|
|
21997
22011
|
destroy() {
|
|
21998
|
-
this.removeEventListener('api-error', this.onApiErrorCallback),
|
|
21999
|
-
this.localStream && this.client.stopStream(this.localStream),
|
|
22012
|
+
this.destroyed || (this.destroyed = !0, this.removeEventListener('api-error', this.onApiErrorCallback),
|
|
22013
|
+
this.client.destroy(), this.localStream && this.client.stopStream(this.localStream),
|
|
22014
|
+
this.client.leaveRoom());
|
|
22000
22015
|
}
|
|
22001
22016
|
}
|
|
22002
22017
|
|
|
@@ -22010,12 +22025,36 @@ function styleInject(css, ref) {
|
|
|
22010
22025
|
}
|
|
22011
22026
|
}
|
|
22012
22027
|
|
|
22013
|
-
var css_248z = '#root,body,html{height:100%;margin:0;min-height:100%;padding:0}.customer-widget-container{background-color:#000;height:100%;min-height:100%;position:relative;width:100%;z-index:999999999}.customer-widget-iframe-wrapper{background:transparent;height:100%;left:0;position:fixed;top:0;width:100%;z-index:99}.customer-widget-iframe-wrapper iframe{border:none;display:block;height:100%;width:100%}.back-btn{background:transparent;border:none;box-shadow:none;left:0;margin:0;padding:0;width:40px}.back-btn,.recording-status-indicator{align-items:center;display:flex;height:40px;justify-content:center;position:absolute;top:50px;z-index:30}.recording-status-indicator{border-radius:20px;left:50%;min-width:80px;padding:0 16px;transform:translateX(-50%)}.recording-dot{animation:recording-pulse 1.5s ease-in-out infinite;background-color:red;border-radius:50%;height:8px;margin-right:8px;width:8px}.recording-text{color:#fff;font-size:14px;margin:0}@keyframes recording-pulse{0%{opacity:1;transform:scale(1)}50%{opacity:.5;transform:scale(1.2)}to{opacity:1;transform:scale(1)}}.customer-widget-container video.customer-background-video,.customer-widget-container video.customer-top-left-video{pointer-events:none}.customer-widget-container video.customer-background-video::-webkit-media-controls,.customer-widget-container video.customer-background-video::-webkit-media-controls-enclosure,.customer-widget-container video.customer-top-left-video::-webkit-media-controls,.customer-widget-container video.customer-top-left-video::-webkit-media-controls-enclosure{display:none!important}.customer-widget-container video.customer-background-video::-webkit-media-controls-start-playback-button,.customer-widget-container video.customer-top-left-video::-webkit-media-controls-start-playback-button{-webkit-appearance:none;display:none!important}.customer-widget-container>.customer-background-video{border:0;display:block;height:100%;left:0;margin:0;object-fit:cover;object-position:center center;padding:0;position:absolute;top:0;width:100%;z-index:10}.customer-video-container{height:
|
|
22028
|
+
var css_248z = '#root,body,html{height:100%;margin:0;min-height:100%;padding:0}.customer-widget-container{background-color:#000;height:100%;min-height:100%;position:relative;width:100%;z-index:999999999}.customer-widget-iframe-wrapper{background:transparent;height:100%;left:0;position:fixed;top:0;width:100%;z-index:99}.customer-widget-iframe-wrapper iframe{border:none;display:block;height:100%;width:100%}.back-btn{background:transparent;border:none;box-shadow:none;left:0;margin:0;padding:0;width:40px}.back-btn,.recording-status-indicator{align-items:center;display:flex;height:40px;justify-content:center;position:absolute;top:50px;z-index:30}.recording-status-indicator{border-radius:20px;left:50%;min-width:80px;padding:0 16px;transform:translateX(-50%)}.recording-dot{animation:recording-pulse 1.5s ease-in-out infinite;background-color:red;border-radius:50%;height:8px;margin-right:8px;width:8px}.recording-text{color:#fff;font-size:14px;margin:0}@keyframes recording-pulse{0%{opacity:1;transform:scale(1)}50%{opacity:.5;transform:scale(1.2)}to{opacity:1;transform:scale(1)}}.customer-widget-container video.customer-background-video,.customer-widget-container video.customer-top-left-video{pointer-events:none}.customer-widget-container video.customer-background-video::-webkit-media-controls,.customer-widget-container video.customer-background-video::-webkit-media-controls-enclosure,.customer-widget-container video.customer-top-left-video::-webkit-media-controls,.customer-widget-container video.customer-top-left-video::-webkit-media-controls-enclosure{display:none!important}.customer-widget-container video.customer-background-video::-webkit-media-controls-start-playback-button,.customer-widget-container video.customer-top-left-video::-webkit-media-controls-start-playback-button{-webkit-appearance:none;display:none!important}.customer-widget-container>.customer-background-video{border:0;display:block;height:100%;left:0;margin:0;object-fit:cover;object-position:center center;padding:0;position:absolute;top:0;width:100%;z-index:10}.customer-video-container{height:100%;position:relative;top:0;width:100%;z-index:20}.customer-top-section{background:#000;border-bottom-left-radius:8px;border-bottom-right-radius:8px;border-radius:8px;display:flex;height:98px;left:10px;overflow:hidden;position:absolute;right:10px;top:90px}.customer-top-left-video{border-radius:8px;display:block;height:100%;object-fit:cover;width:130px}.customer-widget-subtitle-area-container{background-color:#000;flex:1;height:100%}.customer-widget-human-info-area{word-wrap:break-word;box-sizing:border-box;color:#fff;display:block;font-size:12px;max-height:100px;overflow-wrap:break-word;overflow-wrap:anywhere;overflow-y:auto;padding:6px;text-align:left;word-break:break-all}.customer-widget-human-info-area::-webkit-scrollbar{background:#d9d9d9;border-radius:2px;flex-shrink:0;height:34px;width:3px}.customer-widget-human-info-area::-webkit-scrollbar-thumb{background:#d9d9d9;border-radius:2px}.customer-widget-human-info-area::-webkit-scrollbar-track{background:transparent}.customer-subtitle-text{word-wrap:break-word;-webkit-overflow-scrolling:touch;-ms-overflow-style:none;box-sizing:border-box;color:#fff;display:block;flex:0 1 auto;font-family:PingFang SC;font-size:16px;font-style:normal;font-weight:600;line-height:1.6;max-height:120px;overflow-wrap:break-word;overflow-x:hidden;overflow-y:auto;padding:6px;scrollbar-width:none;text-align:center;text-align:left;white-space:pre-line;width:100%;word-break:break-all}.customer-subtitle-text::-webkit-scrollbar{display:none;height:0;width:0}.customer-agent-message-area{word-wrap:break-word;align-items:flex-start;color:#fff;display:flex;font-size:12px;font-weight:400;line-height:18px;overflow-wrap:break-word;padding:13px}.customer-face-tip-group{align-items:center;display:flex;flex-direction:column;gap:10px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:99}.customer-no-face-title{align-items:center;background:#ff221a;border-radius:6px;box-sizing:border-box;color:#fff;display:flex;font-size:14px;justify-content:center;line-height:20px;min-height:35px;min-width:149px;opacity:.9;padding:0 12px;text-align:center}.customer-no-face-title-wide{min-width:220px;white-space:nowrap}.customer-widget-bottom-container{align-items:center;background-color:rgba(0,0,0,.78);border-top-left-radius:16px;border-top-right-radius:16px;bottom:0;display:flex;height:160px;justify-content:center;left:0;margin-bottom:calc(env(safe-area-inset-bottom, 0px)*-1);position:fixed;right:0;width:100%;z-index:20}.customer-widget-bottom-content{align-items:stretch;box-sizing:border-box;display:flex;flex-direction:column;height:100%;justify-content:flex-start;min-height:0;padding:5px 20px 20px;width:100%}.customer-widget-bottom-section{align-items:center;display:flex;flex-direction:column;flex-shrink:0;justify-content:center;margin-top:10px}.customer-asr-text{font-feature-settings:"liga" off,"clig" off;color:#fff;font-family:PingFang SC;font-size:16px;font-style:normal;font-weight:500;line-height:normal;margin-top:20px;overflow:hidden;text-align:center;text-overflow:ellipsis;white-space:wrap;width:100%}.customer-widget-bottom-text{background:#4053ff;border-radius:5px;color:#fff;display:inline-block;font-size:13px;padding:10px 20px}.customer-widget-waitView{height:60px;width:60px}.customer-widget-bottom-container-asr{height:auto;max-height:60vh}.customer-widget-bottom-container-asr .customer-widget-bottom-content{-webkit-overflow-scrolling:touch;height:auto;max-height:60vh;min-height:min(160px,60vh);overflow-y:auto;overscroll-behavior:contain}.customer-widget-bottom-container-asr .customer-subtitle-text{flex:0 0 auto}.customer-widget-bottom-container-asr .customer-widget-bottom-section{gap:8px;min-width:0}.customer-widget-bottom-container-asr .customer-asr-text{-webkit-overflow-scrolling:touch;flex:0 0 auto;line-height:24px;margin-top:0;max-height:72px;overflow-wrap:anywhere;overflow-y:auto;text-overflow:clip;white-space:pre-wrap}.customer-widget-bottom-container-asr .customer-widget-waitView{flex:0 0 60px}.customer-bottom-text p{margin:0}.progress-wrapper{height:60px;position:relative;width:60px}.remainingTime{color:#ffa100;font-size:24px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:1}.iframe-loading-overlay{align-items:center;background:rgba(0,0,0,.8);display:flex;height:100%;justify-content:center;left:0;position:absolute;top:0;width:100%;z-index:10}.iframe-loading-content{color:#fff;text-align:center}.loading-spinner{animation:spin 1s linear infinite;border:4px solid hsla(0,0%,100%,.3);border-radius:50%;border-top-color:#fff;height:40px;margin:0 auto 15px;width:40px}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.iframe-loading-content p{color:hsla(0,0%,100%,.8);font-size:14px;margin:0}.customer-image-stack{height:100vh;pointer-events:none;position:relative;width:100%}.customer-middle-image{bottom:160px;left:0;object-fit:contain;pointer-events:none;position:absolute;width:100%;z-index:19}.exit-dialog-mask{background:rgba(0,0,0,.45);height:100vh;justify-content:center;left:0;position:fixed;top:0;width:100vw;z-index:99999}.exit-dialog,.exit-dialog-mask{align-items:center;display:flex}.exit-dialog{background:#fff;border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,.18);flex-direction:column;padding:0;width:300px}.exit-dialog-title{color:#333;font-family:PingFang SC;font-size:18px;font-weight:700;font-weight:500;letter-spacing:0;line-height:28px;margin-bottom:12px;padding:24px 20px 0}.exit-dialog-content,.exit-dialog-title{box-sizing:border-box;text-align:center;width:100%}.exit-dialog-content{color:#27333e;font-size:16px;margin-bottom:16px;padding:12px 20px 0}.exit-dialog-hline{background:#e9eaf7;height:1px;margin:0;width:100%}.exit-dialog-actions{align-items:stretch;display:flex;gap:0;height:56px;justify-content:center;width:100%}.exit-cancel-text,.exit-confirm-text{align-items:center;background:none;border:none;cursor:pointer;display:flex;flex:1;font-size:16px;height:56px;justify-content:center;min-width:0;text-align:center;-webkit-user-select:none;user-select:none}.exit-cancel-text{color:#666}.exit-confirm-text{color:#eb3b3b}.exit-dialog-divider{align-self:stretch;border-left:1px solid #e9eaf7;height:100%;margin:0;width:1px}.customer-widget-container>.svg-overlay{height:100%;left:0;pointer-events:none;position:absolute;top:0;width:100%;z-index:19}.custom-scroll-track{background:transparent;height:100px;pointer-events:none;top:0}.custom-scroll-thumb,.custom-scroll-track{border-radius:2px;position:absolute;right:0;width:3px}.custom-scroll-thumb{background:#b0b0b0;cursor:pointer;top:12px;transition:background .2s}';
|
|
22014
22029
|
|
|
22015
22030
|
styleInject(css_248z);
|
|
22016
22031
|
|
|
22017
22032
|
var kefu = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQMAAADACAYAAAAA2gZlAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAB5uSURBVHgB7Z3rctzGlcdPDymRFClSFMWLKMoiLZlxJOu2trOu3drE/rC1ldoPyRvYeQPnCWI/Qp4gzhOk8mUrqaTKymbXSVXstaS1tJJsibrGokxKJMU7h4PF6RlgGo1uDGYGA2Bm/j95PINGA2iA6D/OOX2BOD414ZCG4zi0urZOW1tbBADoDnq54qvs7u3RysoalUqlUOYjR47QpUuX6Cc/+Yn8PTs7SwCA/HH//n26du0aXblyha5evRprm151YXNzi9ZerocysQC8//779MEHH0gRAAC0DywMH3/8sRQG/m1DTE2OS9NgfWOD1tc3Ayu54v/iF7+gDz/8kAAA7Y0nCp988olxvRQDdg2eP18JrGBr4De/+Q1cAQA6DBaDn//85244IFjnxfixMef5ixXa39/3E1kIPv30U7gEAHQoHEd47733AoIgBgb6na2tbT+BLYEvv/wSQgBAh8OCcPnyZX+5p1gsfuQtsBCwRTA1NUUAgM6G6zk/9H//+9/LZeF+/LbFX/3qV7LFAADQPbC7wC0NvhiwVbCwsEAAgO6ChYAFoeAlcBMiAKD7ePfdd+XHtwxevHiBoCEAXQo3N0oxYFXgwCEAoDvhJkbpJrAYAAC6F/YKpBhcvHiR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IBAPINCwBXfO5DxC5BrQGJ/w+MiQFWh1rnOgAAAABJRU5ErkJggg==';
|
|
22018
22033
|
|
|
22034
|
+
function asrDebug(event, detail = {}) {
|
|
22035
|
+
console.log(`[ASR DEBUG] ${event}`, _objectSpread2({
|
|
22036
|
+
at: (new Date).toISOString()
|
|
22037
|
+
}, detail));
|
|
22038
|
+
}
|
|
22039
|
+
|
|
22040
|
+
function describeAsrUrl(value) {
|
|
22041
|
+
try {
|
|
22042
|
+
const url = new URL(value), signedAt = url.searchParams.get('date'), signedTime = Date.parse(signedAt);
|
|
22043
|
+
return {
|
|
22044
|
+
endpoint: `${url.origin}${url.pathname}`,
|
|
22045
|
+
queryKeys: [ ...url.searchParams.keys() ],
|
|
22046
|
+
signedHost: url.searchParams.get('host'),
|
|
22047
|
+
signedAt,
|
|
22048
|
+
signatureAgeSeconds: Number.isFinite(signedTime) ? Math.round((Date.now() - signedTime) / 1e3) : null,
|
|
22049
|
+
authorizationLength: (url.searchParams.get('authorization') || '').length
|
|
22050
|
+
};
|
|
22051
|
+
} catch (_) {
|
|
22052
|
+
return {
|
|
22053
|
+
validUrl: !1
|
|
22054
|
+
};
|
|
22055
|
+
}
|
|
22056
|
+
}
|
|
22057
|
+
|
|
22019
22058
|
const isJsonString = str => {
|
|
22020
22059
|
try {
|
|
22021
22060
|
const toObj = JSON.parse(str);
|
|
@@ -22210,6 +22249,683 @@ class Request {
|
|
|
22210
22249
|
}
|
|
22211
22250
|
}
|
|
22212
22251
|
|
|
22252
|
+
const XFYUN_IAT_BUSINESS = Object.freeze({
|
|
22253
|
+
language: 'zh_cn',
|
|
22254
|
+
domain: 'iat',
|
|
22255
|
+
ltc: 2,
|
|
22256
|
+
ptt: 0,
|
|
22257
|
+
pcm: 0,
|
|
22258
|
+
accent: 'mandarin',
|
|
22259
|
+
vad_eos: 5e3,
|
|
22260
|
+
dwa: 'wpgs'
|
|
22261
|
+
});
|
|
22262
|
+
|
|
22263
|
+
function getRealtimeAsrDuration(seconds) {
|
|
22264
|
+
const value = Number(seconds);
|
|
22265
|
+
return !Number.isFinite(value) || value <= 0 ? 5 : Math.max(1, Math.round(1e3 * Math.min(value, 10))) / 1e3;
|
|
22266
|
+
}
|
|
22267
|
+
|
|
22268
|
+
function getAsrConfig(config, requireLicenseCode = !1) {
|
|
22269
|
+
if (null == config) {
|
|
22270
|
+
return {
|
|
22271
|
+
type: 0
|
|
22272
|
+
};
|
|
22273
|
+
}
|
|
22274
|
+
if ('object' != typeof config || Array.isArray(config)) {
|
|
22275
|
+
throw new Error('asrConfig 必须是配置对象');
|
|
22276
|
+
}
|
|
22277
|
+
if (0 !== config.type && 1 !== config.type) {
|
|
22278
|
+
throw new Error('asrConfig.type 必须为 0(离线)或 1(实时)');
|
|
22279
|
+
}
|
|
22280
|
+
if (1 === config.type && requireLicenseCode) {
|
|
22281
|
+
if ('string' != typeof config.licenseCode || !config.licenseCode.trim()) {
|
|
22282
|
+
throw new Error('asrConfig.licenseCode 不能为空');
|
|
22283
|
+
}
|
|
22284
|
+
return {
|
|
22285
|
+
type: 1,
|
|
22286
|
+
licenseCode: config.licenseCode.trim()
|
|
22287
|
+
};
|
|
22288
|
+
}
|
|
22289
|
+
return {
|
|
22290
|
+
type: config.type
|
|
22291
|
+
};
|
|
22292
|
+
}
|
|
22293
|
+
|
|
22294
|
+
function normalizeRealtimeAsrCredentials(config) {
|
|
22295
|
+
const wsUrl = 'string' == typeof (null == config ? void 0 : config.ws_url) ? config.ws_url.trim() : '', appId = 'string' == typeof (null == config ? void 0 : config.token) ? config.token.trim() : '';
|
|
22296
|
+
let validUrl = !1;
|
|
22297
|
+
try {
|
|
22298
|
+
const url = new URL(wsUrl);
|
|
22299
|
+
validUrl = [ 'wss:', 'ws:' ].includes(url.protocol) && Boolean(url.hostname);
|
|
22300
|
+
} catch (_) {}
|
|
22301
|
+
if (!validUrl) {
|
|
22302
|
+
throw new Error('实时 ASR 接口返回的 ws_url 必须是完整 WebSocket 地址');
|
|
22303
|
+
}
|
|
22304
|
+
if (!appId) {
|
|
22305
|
+
throw new Error('实时 ASR 接口返回的 token 不能为空');
|
|
22306
|
+
}
|
|
22307
|
+
return {
|
|
22308
|
+
wsUrl,
|
|
22309
|
+
appId
|
|
22310
|
+
};
|
|
22311
|
+
}
|
|
22312
|
+
|
|
22313
|
+
function getRealtimeAsrBusiness(_config, seconds) {
|
|
22314
|
+
return _objectSpread2(_objectSpread2({}, XFYUN_IAT_BUSINESS), {}, {
|
|
22315
|
+
vad_eos: 1e3 * getRealtimeAsrDuration(seconds)
|
|
22316
|
+
});
|
|
22317
|
+
}
|
|
22318
|
+
|
|
22319
|
+
function redactRealtimeAsrOptions(options) {
|
|
22320
|
+
return null != options && options.asrConfig ? _objectSpread2(_objectSpread2({}, options), {}, {
|
|
22321
|
+
asrConfig: _objectSpread2(_objectSpread2({}, options.asrConfig), null != options.asrConfig.licenseCode ? {
|
|
22322
|
+
licenseCode: '[redacted]'
|
|
22323
|
+
} : {})
|
|
22324
|
+
}) : options;
|
|
22325
|
+
}
|
|
22326
|
+
|
|
22327
|
+
function queryRealtimeAsrConfig(_x, _x2) {
|
|
22328
|
+
return _queryRealtimeAsrConfig.apply(this, arguments);
|
|
22329
|
+
}
|
|
22330
|
+
|
|
22331
|
+
function _queryRealtimeAsrConfig() {
|
|
22332
|
+
return (_queryRealtimeAsrConfig = _asyncToGenerator((function*(aiServerUrl, asrConfig) {
|
|
22333
|
+
var _response$data$data, _response$data;
|
|
22334
|
+
const config = getAsrConfig(asrConfig, !0);
|
|
22335
|
+
if (0 === config.type) {
|
|
22336
|
+
return null;
|
|
22337
|
+
}
|
|
22338
|
+
if ('string' != typeof aiServerUrl || !aiServerUrl.trim()) {
|
|
22339
|
+
throw new Error('实时 ASR 需要配置 aiServerUrl');
|
|
22340
|
+
}
|
|
22341
|
+
const url = `${aiServerUrl.trim().replace(/\/+$/, '')}/witness/queryRealAsrConfig`;
|
|
22342
|
+
let response;
|
|
22343
|
+
asrDebug('config.request', {
|
|
22344
|
+
url,
|
|
22345
|
+
method: 'POST',
|
|
22346
|
+
hasBody: !1,
|
|
22347
|
+
hasLicenseCode: Boolean(config.licenseCode)
|
|
22348
|
+
});
|
|
22349
|
+
try {
|
|
22350
|
+
response = yield (new Request).post(url, null, {
|
|
22351
|
+
headers: {
|
|
22352
|
+
'license-code': config.licenseCode
|
|
22353
|
+
}
|
|
22354
|
+
}, 5e3);
|
|
22355
|
+
} catch (error) {
|
|
22356
|
+
throw asrDebug('config.request.failed', {
|
|
22357
|
+
status: null == error ? void 0 : error.status,
|
|
22358
|
+
errorType: (null == error ? void 0 : error.name) || (null == error ? void 0 : error.type) || 'request-error'
|
|
22359
|
+
}), error;
|
|
22360
|
+
}
|
|
22361
|
+
const body = null !== (_response$data$data = null === (_response$data = response.data) || void 0 === _response$data ? void 0 : _response$data.data) && void 0 !== _response$data$data ? _response$data$data : response.data;
|
|
22362
|
+
asrDebug('config.response', {
|
|
22363
|
+
status: response.status,
|
|
22364
|
+
responseKeys: Object.keys(response.data || {}),
|
|
22365
|
+
credentialKeys: Object.keys(body || {}),
|
|
22366
|
+
token: null == body ? void 0 : body.token,
|
|
22367
|
+
url: describeAsrUrl(null == body ? void 0 : body.ws_url)
|
|
22368
|
+
});
|
|
22369
|
+
try {
|
|
22370
|
+
const credentials = normalizeRealtimeAsrCredentials(body);
|
|
22371
|
+
return asrDebug('config.ready', {
|
|
22372
|
+
appId: credentials.appId,
|
|
22373
|
+
url: describeAsrUrl(credentials.wsUrl)
|
|
22374
|
+
}), credentials;
|
|
22375
|
+
} catch (error) {
|
|
22376
|
+
throw asrDebug('config.invalid', {
|
|
22377
|
+
message: error.message
|
|
22378
|
+
}), error;
|
|
22379
|
+
}
|
|
22380
|
+
}))).apply(this, arguments);
|
|
22381
|
+
}
|
|
22382
|
+
|
|
22383
|
+
class Pcm16Encoder {
|
|
22384
|
+
constructor(inputRate, outputRate = 16e3) {
|
|
22385
|
+
if (!(inputRate > 0 && outputRate > 0)) {
|
|
22386
|
+
throw new Error('无效的采样率');
|
|
22387
|
+
}
|
|
22388
|
+
this.ratio = inputRate / outputRate, this.remaining = this.ratio, this.sum = 0;
|
|
22389
|
+
}
|
|
22390
|
+
push(samples) {
|
|
22391
|
+
const output = [];
|
|
22392
|
+
for (const value of samples) {
|
|
22393
|
+
let available = 1;
|
|
22394
|
+
const sample = Number.isFinite(value) ? Math.max(-1, Math.min(1, value)) : 0;
|
|
22395
|
+
for (;available > 1e-9; ) {
|
|
22396
|
+
const weight = Math.min(available, this.remaining);
|
|
22397
|
+
this.sum += sample * weight, this.remaining -= weight, available -= weight, this.remaining < 1e-9 && (output.push(this.sum / this.ratio),
|
|
22398
|
+
this.sum = 0, this.remaining = this.ratio);
|
|
22399
|
+
}
|
|
22400
|
+
}
|
|
22401
|
+
return this.encode(output);
|
|
22402
|
+
}
|
|
22403
|
+
flush() {
|
|
22404
|
+
const weight = this.ratio - this.remaining, bytes = weight > 1e-9 ? this.encode([ this.sum / weight ]) : new Uint8Array;
|
|
22405
|
+
return this.sum = 0, this.remaining = this.ratio, bytes;
|
|
22406
|
+
}
|
|
22407
|
+
encode(samples) {
|
|
22408
|
+
const bytes = new Uint8Array(2 * samples.length), view = new DataView(bytes.buffer);
|
|
22409
|
+
return samples.forEach(((sample, index) => {
|
|
22410
|
+
view.setInt16(2 * index, Math.round(sample * (sample < 0 ? 32768 : 32767)), !0);
|
|
22411
|
+
})), bytes;
|
|
22412
|
+
}
|
|
22413
|
+
}
|
|
22414
|
+
|
|
22415
|
+
class ByteQueue {
|
|
22416
|
+
constructor() {
|
|
22417
|
+
this.chunks = [], this.length = 0, this.offset = 0;
|
|
22418
|
+
}
|
|
22419
|
+
push(bytes) {
|
|
22420
|
+
bytes.length && (this.chunks.push(bytes), this.length += bytes.length);
|
|
22421
|
+
}
|
|
22422
|
+
take(size) {
|
|
22423
|
+
size = Math.min(size, this.length);
|
|
22424
|
+
const bytes = new Uint8Array(size);
|
|
22425
|
+
let written = 0;
|
|
22426
|
+
for (;written < size; ) {
|
|
22427
|
+
const chunk = this.chunks[0], count = Math.min(chunk.length - this.offset, size - written);
|
|
22428
|
+
bytes.set(chunk.subarray(this.offset, this.offset + count), written), written += count,
|
|
22429
|
+
this.offset += count, this.offset === chunk.length && (this.chunks.shift(), this.offset = 0);
|
|
22430
|
+
}
|
|
22431
|
+
return this.length -= size, bytes;
|
|
22432
|
+
}
|
|
22433
|
+
clear() {
|
|
22434
|
+
this.chunks = [], this.length = 0, this.offset = 0;
|
|
22435
|
+
}
|
|
22436
|
+
}
|
|
22437
|
+
|
|
22438
|
+
function toBase64(bytes) {
|
|
22439
|
+
let binary = '';
|
|
22440
|
+
for (const byte of bytes) {
|
|
22441
|
+
binary += String.fromCharCode(byte);
|
|
22442
|
+
}
|
|
22443
|
+
return globalThis.btoa(binary);
|
|
22444
|
+
}
|
|
22445
|
+
|
|
22446
|
+
class Transcript {
|
|
22447
|
+
constructor() {
|
|
22448
|
+
this.segments = new Map, this.sequence = 0;
|
|
22449
|
+
}
|
|
22450
|
+
update(data) {
|
|
22451
|
+
const id = Number(null == data.sn ? this.sequence++ : data.sn);
|
|
22452
|
+
if (!Number.isFinite(id)) {
|
|
22453
|
+
throw new Error('无效的 IAT 结果序号');
|
|
22454
|
+
}
|
|
22455
|
+
if ('rpl' === data.pgs && Array.isArray(data.rg)) {
|
|
22456
|
+
for (const key of this.segments.keys()) {
|
|
22457
|
+
key >= Number(data.rg[0]) && key <= Number(data.rg[1]) && this.segments.delete(key);
|
|
22458
|
+
}
|
|
22459
|
+
}
|
|
22460
|
+
const text = (data.ws || []).map((item => {
|
|
22461
|
+
var _item$cw;
|
|
22462
|
+
return (null === (_item$cw = item.cw) || void 0 === _item$cw || null === (_item$cw = _item$cw[0]) || void 0 === _item$cw ? void 0 : _item$cw.w) || '';
|
|
22463
|
+
})).join('');
|
|
22464
|
+
return this.segments.set(id, {
|
|
22465
|
+
id,
|
|
22466
|
+
text,
|
|
22467
|
+
final: !1
|
|
22468
|
+
}), this.snapshot();
|
|
22469
|
+
}
|
|
22470
|
+
snapshot() {
|
|
22471
|
+
const segments = [ ...this.segments.values() ].sort(((a, b) => a.id - b.id));
|
|
22472
|
+
return {
|
|
22473
|
+
text: segments.map((item => item.text)).join(''),
|
|
22474
|
+
finalText: segments.filter((item => item.final)).map((item => item.text)).join(''),
|
|
22475
|
+
interimText: segments.filter((item => !item.final)).map((item => item.text)).join(''),
|
|
22476
|
+
segments
|
|
22477
|
+
};
|
|
22478
|
+
}
|
|
22479
|
+
finalize() {
|
|
22480
|
+
for (const segment of this.segments.values()) {
|
|
22481
|
+
segment.final = !0;
|
|
22482
|
+
}
|
|
22483
|
+
return this.snapshot();
|
|
22484
|
+
}
|
|
22485
|
+
}
|
|
22486
|
+
|
|
22487
|
+
const pcmWorkletSource = '\nclass PcmCaptureProcessor extends AudioWorkletProcessor {\n constructor() {\n super();\n this.pending = [];\n this.size = 0;\n this.active = true;\n this.port.onmessage = ({ data }) => {\n if (data === \'stop\') {\n this.active = false;\n this.flush();\n this.port.postMessage({ type: \'stopped\' });\n }\n };\n }\n flush() {\n if (!this.size) return;\n const samples = new Float32Array(this.size);\n let offset = 0;\n for (const chunk of this.pending) { samples.set(chunk, offset); offset += chunk.length; }\n this.pending = [];\n this.size = 0;\n this.port.postMessage({ type: \'samples\', samples }, [samples.buffer]);\n }\n process(inputs) {\n const channels = inputs[0];\n if (this.active && channels && channels.length && channels[0].length) {\n const mono = new Float32Array(channels[0].length);\n for (const channel of channels) {\n for (let i = 0; i < mono.length; i++) mono[i] += channel[i] / channels.length;\n }\n this.pending.push(mono);\n this.size += mono.length;\n if (this.size >= 1024) this.flush();\n }\n return true;\n }\n}\nregisterProcessor(\'sdk-iat-pcm-capture\', PcmCaptureProcessor);\n', FRAME_BYTES = 1280, MAX_QUEUE_BYTES = 16e4, aborted = () => Object.assign(new Error('已取消语音识别'), {
|
|
22488
|
+
name: 'AbortError'
|
|
22489
|
+
});
|
|
22490
|
+
|
|
22491
|
+
class CompatibleEventTarget {
|
|
22492
|
+
constructor() {
|
|
22493
|
+
this.listeners = new Map;
|
|
22494
|
+
}
|
|
22495
|
+
addEventListener(type, callback, options = {}) {
|
|
22496
|
+
if (!callback) {
|
|
22497
|
+
return;
|
|
22498
|
+
}
|
|
22499
|
+
const listeners = this.listeners.get(type) || [];
|
|
22500
|
+
listeners.some((item => item.callback === callback)) || listeners.push({
|
|
22501
|
+
callback,
|
|
22502
|
+
once: !(!options || !options.once)
|
|
22503
|
+
}), this.listeners.set(type, listeners);
|
|
22504
|
+
}
|
|
22505
|
+
removeEventListener(type, callback) {
|
|
22506
|
+
this.listeners.set(type, (this.listeners.get(type) || []).filter((item => item.callback !== callback)));
|
|
22507
|
+
}
|
|
22508
|
+
dispatchEvent(event) {
|
|
22509
|
+
for (const item of [ ...this.listeners.get(event.type) || [] ]) {
|
|
22510
|
+
item.once && this.removeEventListener(event.type, item.callback), 'function' == typeof item.callback ? item.callback.call(this, event) : item.callback.handleEvent(event);
|
|
22511
|
+
}
|
|
22512
|
+
return !event.defaultPrevented;
|
|
22513
|
+
}
|
|
22514
|
+
}
|
|
22515
|
+
|
|
22516
|
+
const hasNativeEvents = 'function' == typeof globalThis.EventTarget && 'function' == typeof globalThis.Event, EventTargetBase = hasNativeEvents ? globalThis.EventTarget : CompatibleEventTarget;
|
|
22517
|
+
|
|
22518
|
+
class RealtimeAsrClient extends EventTargetBase {
|
|
22519
|
+
constructor({wsUrl, appId, mediaStream, business = {}} = {}) {
|
|
22520
|
+
super(), this.wsUrl = wsUrl, this.appId = appId, this.mediaStream = mediaStream,
|
|
22521
|
+
this.business = _objectSpread2(_objectSpread2({}, XFYUN_IAT_BUSINESS), business),
|
|
22522
|
+
this.state = 'idle', this.text = '', this._session = null, this._lastEnd = null;
|
|
22523
|
+
}
|
|
22524
|
+
_emit(type, detail) {
|
|
22525
|
+
const event = hasNativeEvents ? new globalThis.Event(type) : {
|
|
22526
|
+
type
|
|
22527
|
+
};
|
|
22528
|
+
Object.defineProperty(event, 'detail', {
|
|
22529
|
+
value: detail
|
|
22530
|
+
}), this.dispatchEvent(event);
|
|
22531
|
+
}
|
|
22532
|
+
_state(state) {
|
|
22533
|
+
this.state = state, asrDebug('client.state', {
|
|
22534
|
+
state
|
|
22535
|
+
}), this._emit('statechange', {
|
|
22536
|
+
state
|
|
22537
|
+
});
|
|
22538
|
+
}
|
|
22539
|
+
_check(session) {
|
|
22540
|
+
if (!session.active) {
|
|
22541
|
+
throw aborted();
|
|
22542
|
+
}
|
|
22543
|
+
}
|
|
22544
|
+
start() {
|
|
22545
|
+
var _this = this;
|
|
22546
|
+
return _asyncToGenerator((function*() {
|
|
22547
|
+
if (_this._session) {
|
|
22548
|
+
throw new Error('语音识别会话正在进行');
|
|
22549
|
+
}
|
|
22550
|
+
const session = {
|
|
22551
|
+
active: !0,
|
|
22552
|
+
queue: new ByteQueue,
|
|
22553
|
+
transcript: new Transcript,
|
|
22554
|
+
capturing: !1,
|
|
22555
|
+
draining: !1,
|
|
22556
|
+
endSent: !1,
|
|
22557
|
+
ownsStream: !_this.mediaStream,
|
|
22558
|
+
sentBytes: 0,
|
|
22559
|
+
sentFrames: 0
|
|
22560
|
+
};
|
|
22561
|
+
_this._session = session, _this._lastEnd = null, _this.text = '', _this._state('starting');
|
|
22562
|
+
try {
|
|
22563
|
+
var _globalThis$location, _globalThis$navigator;
|
|
22564
|
+
let url;
|
|
22565
|
+
_this._check(session);
|
|
22566
|
+
try {
|
|
22567
|
+
url = new URL(_this.wsUrl);
|
|
22568
|
+
} catch (_unused) {
|
|
22569
|
+
throw new Error('缺少有效的完整 ASR WebSocket 地址');
|
|
22570
|
+
}
|
|
22571
|
+
if (![ 'wss:', 'ws:' ].includes(url.protocol)) {
|
|
22572
|
+
throw new Error('ASR 地址必须使用 wss:// 或 ws://');
|
|
22573
|
+
}
|
|
22574
|
+
if ('https:' === (null === (_globalThis$location = globalThis.location) || void 0 === _globalThis$location ? void 0 : _globalThis$location.protocol) && 'wss:' !== url.protocol) {
|
|
22575
|
+
throw new Error('HTTPS 页面必须使用 wss://');
|
|
22576
|
+
}
|
|
22577
|
+
if ('string' != typeof _this.appId || !_this.appId.trim()) {
|
|
22578
|
+
throw new Error('缺少 ASR AppID');
|
|
22579
|
+
}
|
|
22580
|
+
const AudioContextClass = globalThis.AudioContext || globalThis.webkitAudioContext;
|
|
22581
|
+
if (!AudioContextClass || !globalThis.WebSocket) {
|
|
22582
|
+
throw new Error('浏览器不支持 Web Audio 或 WebSocket');
|
|
22583
|
+
}
|
|
22584
|
+
if (!(_this.mediaStream || null !== (_globalThis$navigator = globalThis.navigator) && void 0 !== _globalThis$navigator && null !== (_globalThis$navigator = _globalThis$navigator.mediaDevices) && void 0 !== _globalThis$navigator && _globalThis$navigator.getUserMedia)) {
|
|
22585
|
+
throw new Error('无法访问麦克风,请使用 HTTPS 并检查浏览器权限');
|
|
22586
|
+
}
|
|
22587
|
+
session.context = new AudioContextClass;
|
|
22588
|
+
const resume = session.context.resume(), request = _this.mediaStream ? Promise.resolve(_this.mediaStream) : globalThis.navigator.mediaDevices.getUserMedia({
|
|
22589
|
+
audio: {
|
|
22590
|
+
channelCount: 1,
|
|
22591
|
+
echoCancellation: !0,
|
|
22592
|
+
noiseSuppression: !0,
|
|
22593
|
+
autoGainControl: !0
|
|
22594
|
+
},
|
|
22595
|
+
video: !1
|
|
22596
|
+
});
|
|
22597
|
+
yield Promise.all([ request.then((stream => {
|
|
22598
|
+
if (!session.active) {
|
|
22599
|
+
throw session.ownsStream && stream.getTracks().forEach((track => track.stop())),
|
|
22600
|
+
aborted();
|
|
22601
|
+
}
|
|
22602
|
+
session.stream = stream;
|
|
22603
|
+
})), resume ]), _this._check(session);
|
|
22604
|
+
const tracks = session.stream.getAudioTracks().filter((track => 'live' === track.readyState));
|
|
22605
|
+
if (!tracks.length) {
|
|
22606
|
+
throw new Error('没有可用的麦克风音轨');
|
|
22607
|
+
}
|
|
22608
|
+
return session.onTrackEnded = () => _this._fail(session, new Error('麦克风音轨已断开')),
|
|
22609
|
+
tracks.forEach((track => track.addEventListener('ended', session.onTrackEnded))),
|
|
22610
|
+
asrDebug('audio.ready', {
|
|
22611
|
+
contextState: session.context.state,
|
|
22612
|
+
sampleRate: session.context.sampleRate,
|
|
22613
|
+
trackCount: tracks.length,
|
|
22614
|
+
tracks: tracks.map((track => ({
|
|
22615
|
+
readyState: track.readyState,
|
|
22616
|
+
enabled: track.enabled,
|
|
22617
|
+
muted: track.muted
|
|
22618
|
+
})))
|
|
22619
|
+
}), session.encoder = new Pcm16Encoder(session.context.sampleRate), yield _this._prepareCapture(session),
|
|
22620
|
+
_this._check(session), asrDebug('audio.capture.prepared', {
|
|
22621
|
+
processor: session.worklet ? 'AudioWorklet' : 'ScriptProcessor'
|
|
22622
|
+
}), yield _this._connect(session, url.href, _this.appId.trim()), _this._check(session),
|
|
22623
|
+
session.capturing = !0, session.source = session.context.createMediaStreamSource(session.stream),
|
|
22624
|
+
session.silentGain = session.context.createGain(), session.silentGain.gain.value = 0,
|
|
22625
|
+
session.source.connect(session.processor), session.processor.connect(session.silentGain),
|
|
22626
|
+
session.silentGain.connect(session.context.destination), session.context.onstatechange = () => {
|
|
22627
|
+
session.active && 'recording' === _this.state && 'suspended' === session.context.state && _this._fail(session, new Error('音频采样已暂停,请保持页面在前台'));
|
|
22628
|
+
}, _this._state('recording'), _this._check(session), session.sendTimer = setInterval((() => _this._tick(session)), 40),
|
|
22629
|
+
!0;
|
|
22630
|
+
} catch (error) {
|
|
22631
|
+
if (!session.active) {
|
|
22632
|
+
if ('error' === session.reason) {
|
|
22633
|
+
throw session.errorCause || error;
|
|
22634
|
+
}
|
|
22635
|
+
return !1;
|
|
22636
|
+
}
|
|
22637
|
+
throw _this._fail(session, error), error;
|
|
22638
|
+
}
|
|
22639
|
+
}))();
|
|
22640
|
+
}
|
|
22641
|
+
_prepareCapture(session) {
|
|
22642
|
+
var _this2 = this;
|
|
22643
|
+
return _asyncToGenerator((function*() {
|
|
22644
|
+
const context = session.context, URLClass = globalThis.URL;
|
|
22645
|
+
if (context.audioWorklet && globalThis.AudioWorkletNode && globalThis.Blob && null != URLClass && URLClass.createObjectURL) {
|
|
22646
|
+
let objectUrl;
|
|
22647
|
+
try {
|
|
22648
|
+
return objectUrl = URLClass.createObjectURL(new Blob([ pcmWorkletSource ], {
|
|
22649
|
+
type: 'application/javascript'
|
|
22650
|
+
})), yield context.audioWorklet.addModule(objectUrl), _this2._check(session), session.processor = new globalThis.AudioWorkletNode(context, 'sdk-iat-pcm-capture'),
|
|
22651
|
+
session.worklet = !0, session.processor.port.onmessage = ({data}) => {
|
|
22652
|
+
var _session$captureStopp;
|
|
22653
|
+
'samples' === data.type && _this2._samples(session, data.samples), 'stopped' === data.type && (null === (_session$captureStopp = session.captureStopped) || void 0 === _session$captureStopp || _session$captureStopp.call(session));
|
|
22654
|
+
}, void (session.processor.onprocessorerror = () => _this2._fail(session, new Error('音频处理器异常')));
|
|
22655
|
+
} catch (error) {
|
|
22656
|
+
_this2._check(session);
|
|
22657
|
+
} finally {
|
|
22658
|
+
objectUrl && URLClass.revokeObjectURL(objectUrl);
|
|
22659
|
+
}
|
|
22660
|
+
}
|
|
22661
|
+
if (!context.createScriptProcessor) {
|
|
22662
|
+
throw new Error('浏览器不支持音频采样');
|
|
22663
|
+
}
|
|
22664
|
+
session.processor = context.createScriptProcessor(1024, 1, 1), session.processor.onaudioprocess = ({inputBuffer}) => _this2._samples(session, inputBuffer.getChannelData(0));
|
|
22665
|
+
}))();
|
|
22666
|
+
}
|
|
22667
|
+
_samples(session, samples) {
|
|
22668
|
+
if (!session.active || !session.capturing || null == samples || !samples.length) {
|
|
22669
|
+
return;
|
|
22670
|
+
}
|
|
22671
|
+
if (session.queue.push(session.encoder.push(samples)), session.queue.length > MAX_QUEUE_BYTES) {
|
|
22672
|
+
return void this._fail(session, new Error('语音发送积压超过 5 秒'));
|
|
22673
|
+
}
|
|
22674
|
+
let squares = 0;
|
|
22675
|
+
for (let index = 0; index < samples.length; index++) {
|
|
22676
|
+
const sample = Number.isFinite(samples[index]) ? Math.max(-1, Math.min(1, samples[index])) : 0;
|
|
22677
|
+
squares += sample * sample;
|
|
22678
|
+
}
|
|
22679
|
+
const level = Math.max(0, Math.min(1, Math.sqrt(squares / samples.length)));
|
|
22680
|
+
this._emit('volume', {
|
|
22681
|
+
level
|
|
22682
|
+
});
|
|
22683
|
+
}
|
|
22684
|
+
_connect(session, url, appId) {
|
|
22685
|
+
return new Promise(((resolve, reject) => {
|
|
22686
|
+
let settled = !1;
|
|
22687
|
+
const settle = error => {
|
|
22688
|
+
settled || (settled = !0, clearTimeout(session.connectTimer), session.cancelConnect = null,
|
|
22689
|
+
error ? reject(error) : resolve());
|
|
22690
|
+
};
|
|
22691
|
+
let socket;
|
|
22692
|
+
session.cancelConnect = () => settle(aborted()), session.connectTimer = setTimeout((() => {
|
|
22693
|
+
const error = new Error('ASR WebSocket 连接超时');
|
|
22694
|
+
settle(error), this._fail(session, error);
|
|
22695
|
+
}), 1e4);
|
|
22696
|
+
let opened = !1;
|
|
22697
|
+
asrDebug('ws.connect', {
|
|
22698
|
+
appId,
|
|
22699
|
+
url: describeAsrUrl(url)
|
|
22700
|
+
});
|
|
22701
|
+
try {
|
|
22702
|
+
socket = new globalThis.WebSocket(url);
|
|
22703
|
+
} catch (_unused2) {
|
|
22704
|
+
return void settle(new Error('无法创建 ASR WebSocket'));
|
|
22705
|
+
}
|
|
22706
|
+
session.socket = socket, socket.onopen = () => {
|
|
22707
|
+
if (session.active) {
|
|
22708
|
+
opened = !0, asrDebug('ws.open', {
|
|
22709
|
+
readyState: socket.readyState,
|
|
22710
|
+
protocol: socket.protocol
|
|
22711
|
+
});
|
|
22712
|
+
try {
|
|
22713
|
+
const firstFrame = {
|
|
22714
|
+
common: {
|
|
22715
|
+
app_id: appId
|
|
22716
|
+
},
|
|
22717
|
+
business: _objectSpread2({}, this.business),
|
|
22718
|
+
data: {
|
|
22719
|
+
status: 0,
|
|
22720
|
+
format: 'audio/L16;rate=16000',
|
|
22721
|
+
encoding: 'raw',
|
|
22722
|
+
audio: ''
|
|
22723
|
+
}
|
|
22724
|
+
};
|
|
22725
|
+
asrDebug('ws.first-frame.sending', {
|
|
22726
|
+
frame: firstFrame
|
|
22727
|
+
}), socket.send(JSON.stringify(firstFrame)), asrDebug('ws.first-frame.sent', {
|
|
22728
|
+
appId,
|
|
22729
|
+
readyState: socket.readyState
|
|
22730
|
+
}), settle();
|
|
22731
|
+
} catch (_unused3) {
|
|
22732
|
+
settle(new Error('ASR 参数帧发送失败'));
|
|
22733
|
+
}
|
|
22734
|
+
}
|
|
22735
|
+
}, socket.onmessage = event => {
|
|
22736
|
+
if (session.active) {
|
|
22737
|
+
try {
|
|
22738
|
+
var _message$data, _message$data2;
|
|
22739
|
+
const message = JSON.parse(event.data);
|
|
22740
|
+
if (asrDebug('ws.message', {
|
|
22741
|
+
message
|
|
22742
|
+
}), message.sid && (session.sid = message.sid), null != message.code && '0' !== String(message.code)) {
|
|
22743
|
+
const error = Object.assign(new Error(message.message || message.desc || 'ASR 服务返回错误'), {
|
|
22744
|
+
code: message.code,
|
|
22745
|
+
sid: message.sid
|
|
22746
|
+
});
|
|
22747
|
+
return settle(error), void this._fail(session, error);
|
|
22748
|
+
}
|
|
22749
|
+
null !== (_message$data = message.data) && void 0 !== _message$data && _message$data.result && this._result(session, session.transcript.update(message.data.result)),
|
|
22750
|
+
2 === Number(null === (_message$data2 = message.data) || void 0 === _message$data2 ? void 0 : _message$data2.status) && (this._result(session, session.transcript.finalize()),
|
|
22751
|
+
settle(), this._finish(session, 'final'));
|
|
22752
|
+
} catch (_unused4) {
|
|
22753
|
+
const error = new Error('无法解析 ASR 服务消息');
|
|
22754
|
+
settle(error), this._fail(session, error);
|
|
22755
|
+
}
|
|
22756
|
+
}
|
|
22757
|
+
}, socket.onerror = () => {
|
|
22758
|
+
let message = opened ? 'ASR WebSocket 传输异常,连接已建立后发生网络错误' : 'ASR WebSocket 握手失败,浏览器未提供 HTTP 状态;请查看 Network/WS 握手响应,检查签名、网络和服务授权';
|
|
22759
|
+
if (!opened) {
|
|
22760
|
+
const signedAt = Date.parse(new URL(url).searchParams.get('date'));
|
|
22761
|
+
if (Number.isFinite(signedAt)) {
|
|
22762
|
+
message += `;签名时间与本机时间相差 ${Math.round(Math.abs(Date.now() - signedAt) / 1e3)} 秒,请核对服务端时间及签名有效期`;
|
|
22763
|
+
}
|
|
22764
|
+
}
|
|
22765
|
+
asrDebug('ws.error', {
|
|
22766
|
+
opened,
|
|
22767
|
+
readyState: socket.readyState,
|
|
22768
|
+
message,
|
|
22769
|
+
url: describeAsrUrl(url)
|
|
22770
|
+
});
|
|
22771
|
+
const error = new Error(message);
|
|
22772
|
+
settle(error), this._fail(session, error);
|
|
22773
|
+
}, socket.onclose = event => {
|
|
22774
|
+
if (!session.active) {
|
|
22775
|
+
return;
|
|
22776
|
+
}
|
|
22777
|
+
asrDebug('ws.close', {
|
|
22778
|
+
code: event.code,
|
|
22779
|
+
wasClean: event.wasClean,
|
|
22780
|
+
opened,
|
|
22781
|
+
sentFrames: session.sentFrames,
|
|
22782
|
+
sentBytes: session.sentBytes
|
|
22783
|
+
});
|
|
22784
|
+
const error = new Error(`ASR WebSocket 已断开,未收到最终结果(${event.code})`);
|
|
22785
|
+
settle(error), this._finish(session, 'closed', error);
|
|
22786
|
+
};
|
|
22787
|
+
}));
|
|
22788
|
+
}
|
|
22789
|
+
_result(session, result) {
|
|
22790
|
+
session.active && result && (this.text = result.text, this._emit('result', result));
|
|
22791
|
+
}
|
|
22792
|
+
_tick(session) {
|
|
22793
|
+
if (!session.active || session.endSent) {
|
|
22794
|
+
return;
|
|
22795
|
+
}
|
|
22796
|
+
const socket = session.socket;
|
|
22797
|
+
if (1 === (null == socket ? void 0 : socket.readyState)) {
|
|
22798
|
+
if (socket.bufferedAmount > MAX_QUEUE_BYTES) {
|
|
22799
|
+
this._fail(session, new Error('ASR 网络发送缓冲积压超过 5 秒'));
|
|
22800
|
+
} else if (!(socket.bufferedAmount > 4 * FRAME_BYTES)) {
|
|
22801
|
+
try {
|
|
22802
|
+
if (session.queue.length >= FRAME_BYTES || session.draining && session.queue.length) {
|
|
22803
|
+
const bytes = session.queue.take(FRAME_BYTES);
|
|
22804
|
+
socket.send(JSON.stringify({
|
|
22805
|
+
data: {
|
|
22806
|
+
status: 1,
|
|
22807
|
+
format: 'audio/L16;rate=16000',
|
|
22808
|
+
encoding: 'raw',
|
|
22809
|
+
audio: toBase64(bytes)
|
|
22810
|
+
}
|
|
22811
|
+
})), session.sentFrames++, session.sentBytes += bytes.length, 1 === session.sentFrames && asrDebug('audio.first-frame.sent', {
|
|
22812
|
+
status: 1,
|
|
22813
|
+
bytes: bytes.length
|
|
22814
|
+
});
|
|
22815
|
+
} else {
|
|
22816
|
+
session.draining && (socket.send(JSON.stringify({
|
|
22817
|
+
data: {
|
|
22818
|
+
status: 2,
|
|
22819
|
+
format: 'audio/L16;rate=16000',
|
|
22820
|
+
encoding: 'raw',
|
|
22821
|
+
audio: ''
|
|
22822
|
+
}
|
|
22823
|
+
})), asrDebug('audio.end-frame.sent', {
|
|
22824
|
+
status: 2,
|
|
22825
|
+
sentFrames: session.sentFrames,
|
|
22826
|
+
sentBytes: session.sentBytes
|
|
22827
|
+
}), session.endSent = !0, clearInterval(session.sendTimer), session.finalTimer = setTimeout((() => this._fail(session, new Error('等待 ASR 最终结果超时'))), 1e4));
|
|
22828
|
+
}
|
|
22829
|
+
} catch (_unused5) {
|
|
22830
|
+
this._fail(session, new Error('ASR 音频发送失败'));
|
|
22831
|
+
}
|
|
22832
|
+
}
|
|
22833
|
+
}
|
|
22834
|
+
}
|
|
22835
|
+
stop() {
|
|
22836
|
+
const session = this._session;
|
|
22837
|
+
return session ? session.stopPromise ? session.stopPromise : 'starting' === this.state ? Promise.resolve(this._finish(session, 'cancelled')) : (session.stopPromise = new Promise((resolve => {
|
|
22838
|
+
session.resolveStop = resolve;
|
|
22839
|
+
})), this._state('stopping'), session.active && this._stopCapture(session).catch((error => this._fail(session, error))),
|
|
22840
|
+
session.stopPromise) : Promise.resolve(this._lastEnd);
|
|
22841
|
+
}
|
|
22842
|
+
_stopCapture(session) {
|
|
22843
|
+
var _this3 = this;
|
|
22844
|
+
return _asyncToGenerator((function*() {
|
|
22845
|
+
var _session$source;
|
|
22846
|
+
null === (_session$source = session.source) || void 0 === _session$source || _session$source.disconnect(),
|
|
22847
|
+
session.worklet && (yield new Promise(((resolve, reject) => {
|
|
22848
|
+
session.captureStopped = resolve, session.captureStopTimer = setTimeout((() => reject(new Error('ASR 音频处理器收尾超时'))), 1e3),
|
|
22849
|
+
session.processor.port.postMessage('stop');
|
|
22850
|
+
})), clearTimeout(session.captureStopTimer)), session.active && (session.capturing = !1,
|
|
22851
|
+
session.queue.push(session.encoder.flush()), _this3._releaseAudio(session), _this3._emit('capturestop', {
|
|
22852
|
+
text: _this3.text
|
|
22853
|
+
}), session.active && (session.draining = !0, session.drainTimer = setTimeout((() => {
|
|
22854
|
+
session.endSent || _this3._fail(session, new Error('ASR 结束音频发送超时'));
|
|
22855
|
+
}), 7e3)));
|
|
22856
|
+
}))();
|
|
22857
|
+
}
|
|
22858
|
+
_releaseAudio(session) {
|
|
22859
|
+
if (session.audioReleased) {
|
|
22860
|
+
return;
|
|
22861
|
+
}
|
|
22862
|
+
session.audioReleased = !0;
|
|
22863
|
+
const disconnect = node => {
|
|
22864
|
+
try {
|
|
22865
|
+
null == node || node.disconnect();
|
|
22866
|
+
} catch (_unused6) {}
|
|
22867
|
+
};
|
|
22868
|
+
if (disconnect(session.source), disconnect(session.processor), disconnect(session.silentGain),
|
|
22869
|
+
session.processor && (session.processor.onaudioprocess = null, session.processor.onprocessorerror = null,
|
|
22870
|
+
session.worklet && (session.processor.port.onmessage = null, session.processor.port.close())),
|
|
22871
|
+
session.stream && (session.stream.getAudioTracks().forEach((track => track.removeEventListener('ended', session.onTrackEnded))),
|
|
22872
|
+
session.ownsStream && session.stream.getTracks().forEach((track => track.stop()))),
|
|
22873
|
+
session.context && 'closed' !== session.context.state) {
|
|
22874
|
+
session.context.onstatechange = null;
|
|
22875
|
+
try {
|
|
22876
|
+
Promise.resolve(session.context.close()).catch((() => {}));
|
|
22877
|
+
} catch (_unused7) {}
|
|
22878
|
+
}
|
|
22879
|
+
}
|
|
22880
|
+
_finish(session, reason, error) {
|
|
22881
|
+
var _session$cancelConnec, _session$captureStopp2, _session$resolveStop;
|
|
22882
|
+
if (!session.active) {
|
|
22883
|
+
return session.endDetail;
|
|
22884
|
+
}
|
|
22885
|
+
if (session.active = !1, session.capturing = !1, session.reason = reason, session.errorCause = error,
|
|
22886
|
+
null === (_session$cancelConnec = session.cancelConnect) || void 0 === _session$cancelConnec || _session$cancelConnec.call(session),
|
|
22887
|
+
clearInterval(session.sendTimer), [ 'connectTimer', 'finalTimer', 'drainTimer', 'captureStopTimer' ].forEach((key => clearTimeout(session[key]))),
|
|
22888
|
+
null === (_session$captureStopp2 = session.captureStopped) || void 0 === _session$captureStopp2 || _session$captureStopp2.call(session),
|
|
22889
|
+
this._releaseAudio(session), session.queue.clear(), session.socket && (session.socket.onopen = session.socket.onmessage = session.socket.onerror = session.socket.onclose = null,
|
|
22890
|
+
session.socket.readyState < 2)) {
|
|
22891
|
+
try {
|
|
22892
|
+
session.socket.close();
|
|
22893
|
+
} catch (_unused8) {}
|
|
22894
|
+
}
|
|
22895
|
+
this._session === session && (this._session = null);
|
|
22896
|
+
const detail = {
|
|
22897
|
+
text: this.text,
|
|
22898
|
+
reason
|
|
22899
|
+
};
|
|
22900
|
+
if (error) {
|
|
22901
|
+
const messages = {
|
|
22902
|
+
NotAllowedError: '麦克风权限被拒绝',
|
|
22903
|
+
NotFoundError: '未找到麦克风',
|
|
22904
|
+
NotReadableError: '麦克风无法读取'
|
|
22905
|
+
};
|
|
22906
|
+
detail.error = {
|
|
22907
|
+
message: messages[error.name] || error.message || '语音识别失败',
|
|
22908
|
+
code: error.code,
|
|
22909
|
+
sid: error.sid || session.sid
|
|
22910
|
+
};
|
|
22911
|
+
}
|
|
22912
|
+
return asrDebug('client.end', {
|
|
22913
|
+
reason,
|
|
22914
|
+
error: detail.error,
|
|
22915
|
+
sentFrames: session.sentFrames,
|
|
22916
|
+
sentBytes: session.sentBytes
|
|
22917
|
+
}), session.endDetail = detail, this._lastEnd = detail, this._state(error ? 'error' : 'idle'),
|
|
22918
|
+
detail.error && this._emit('error', detail.error), this._emit('end', detail), null === (_session$resolveStop = session.resolveStop) || void 0 === _session$resolveStop || _session$resolveStop.call(session, detail),
|
|
22919
|
+
detail;
|
|
22920
|
+
}
|
|
22921
|
+
_fail(session, error) {
|
|
22922
|
+
session.active && this._finish(session, 'error', error);
|
|
22923
|
+
}
|
|
22924
|
+
destroy() {
|
|
22925
|
+
return this._session ? this._finish(this._session, 'cancelled') : this._lastEnd;
|
|
22926
|
+
}
|
|
22927
|
+
}
|
|
22928
|
+
|
|
22213
22929
|
const faceCheckRequest = (url, faceBase64, userFaceBase64) => new Promise(function() {
|
|
22214
22930
|
var _ref = _asyncToGenerator((function*(resolve, reject) {
|
|
22215
22931
|
let r = new Request;
|
|
@@ -22266,7 +22982,7 @@ const faceCheckRequest = (url, faceBase64, userFaceBase64) => new Promise(functi
|
|
|
22266
22982
|
};
|
|
22267
22983
|
}());
|
|
22268
22984
|
|
|
22269
|
-
var name = '@crh-fe/oava-customer-sdk', version = '1.0.
|
|
22985
|
+
var name = '@crh-fe/oava-customer-sdk', version = '1.0.59', description = 'Customer JS SDK package for oava-widget', type = 'module', main = './dist/customerComponent.js', files = [ 'dist', 'README.md' ], publishConfig = {
|
|
22270
22986
|
access: 'public'
|
|
22271
22987
|
}, pkg = {
|
|
22272
22988
|
name,
|
|
@@ -22306,6 +23022,7 @@ const formatDateTime = date => `${date.getFullYear()}-${String(date.getMonth() +
|
|
|
22306
23022
|
sdkVersion: pkg.version,
|
|
22307
23023
|
extra: _objectSpread2({
|
|
22308
23024
|
roomTokenPresent: Boolean(roomToken),
|
|
23025
|
+
roomToken,
|
|
22309
23026
|
maxWaitTime,
|
|
22310
23027
|
faceCheckTimer: faceCheckTimer || 2e3,
|
|
22311
23028
|
hasUserFaceBase64: Boolean(hasUserFaceBase64),
|
|
@@ -22479,35 +23196,32 @@ propTypes.exports = factoryWithThrowingShims();
|
|
|
22479
23196
|
|
|
22480
23197
|
var propTypesExports = propTypes.exports, PropTypes = getDefaultExportFromCjs(propTypesExports);
|
|
22481
23198
|
|
|
22482
|
-
const dialogStyles = '\n
|
|
22483
|
-
const [
|
|
23199
|
+
const dialogStyles = '\n [data-oava-customer-dialog] {\n all: initial !important;\n display: block !important;\n position: fixed !important;\n top: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n left: 0 !important;\n z-index: 2147483647 !important;\n pointer-events: auto !important;\n }\n [data-oava-customer-dialog] *,\n [data-oava-customer-dialog] *::before,\n [data-oava-customer-dialog] *::after {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-mask,\n [data-oava-customer-dialog] .oava-customer-dialog-panel,\n [data-oava-customer-dialog] .oava-customer-dialog-content,\n [data-oava-customer-dialog] .oava-customer-dialog-button {\n all: unset;\n box-sizing: border-box;\n pointer-events: auto;\n }\n [data-oava-customer-dialog]::before,\n [data-oava-customer-dialog]::after,\n [data-oava-customer-dialog] *::before,\n [data-oava-customer-dialog] *::after {\n content: none;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-mask {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n padding-top: max(16px, env(safe-area-inset-top, 0px));\n padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));\n background: rgba(0, 0, 0, 0.45);\n color: #333;\n font-family: -apple-system, BlinkMacSystemFont, \'PingFang SC\', sans-serif;\n font-size: 18px;\n font-style: normal;\n font-weight: 400;\n line-height: normal;\n letter-spacing: normal;\n word-spacing: normal;\n text-align: left;\n text-indent: 0;\n text-transform: none;\n white-space: normal;\n direction: ltr;\n writing-mode: horizontal-tb;\n -webkit-text-size-adjust: 100%;\n text-size-adjust: 100%;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-panel {\n display: flex;\n flex-direction: column;\n width: 300px;\n max-width: 100%;\n max-height: 100%;\n min-width: 0;\n min-height: 0;\n padding: 20px 30px;\n overflow-x: hidden;\n overflow-y: auto;\n background: #fff;\n border-radius: 12px;\n box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);\n -webkit-overflow-scrolling: touch;\n overscroll-behavior: contain;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-panel > * {\n flex: 0 0 auto;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-content {\n display: block;\n margin-bottom: 24px;\n font-size: 18px;\n font-weight: 500;\n line-height: 28px;\n overflow-wrap: break-word;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-content-small {\n font-size: 15px;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-button {\n display: block;\n width: 100%;\n border: 0;\n font-family: inherit;\n font-style: normal;\n text-align: center;\n cursor: pointer;\n -webkit-appearance: none;\n appearance: none;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-confirm {\n min-height: 44px;\n padding: 10px 12px;\n border-radius: 24px;\n background: #eb3b3b;\n color: #fff;\n font-size: 16px;\n font-weight: 500;\n line-height: 24px;\n overflow-wrap: break-word;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-cancel {\n margin-top: 16px;\n background: transparent;\n color: #5e6d82;\n font-size: 14px;\n font-weight: 400;\n line-height: 22px;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-mask-face-check-fail {\n padding: 8px;\n padding-top: max(8px, env(safe-area-inset-top, 0px));\n padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));\n }\n [data-oava-customer-dialog] .oava-customer-dialog-face-check-fail {\n width: 340px;\n padding: 36px 38px 22px;\n border-radius: 9px;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-face-check-fail .oava-customer-dialog-content {\n margin-bottom: 34px;\n font-weight: 400;\n line-height: 28px;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-face-check-fail .oava-customer-dialog-confirm {\n min-height: 32px;\n padding: 5px 8px;\n border-radius: 4px;\n background: #ff0000;\n font-size: 14px;\n line-height: 22px;\n }\n [data-oava-customer-dialog] .oava-customer-dialog-face-check-fail .oava-customer-dialog-cancel {\n color: #333;\n }\n @media (max-width: 340px) {\n [data-oava-customer-dialog] .oava-customer-dialog-face-check-fail {\n padding-right: 20px;\n padding-left: 20px;\n }\n }\n', CustomerDialog = ({children, confirmText, onConfirm, cancelText, onCancel, smallText = !1, variant}) => {
|
|
23200
|
+
const [portalContainer, setPortalContainer] = reactExports.useState(null), contentId = reactExports.useId();
|
|
22484
23201
|
return reactExports.useLayoutEffect((() => {
|
|
22485
23202
|
const host = document.createElement('div');
|
|
22486
|
-
host.setAttribute('data-oava-customer-dialog', '')
|
|
22487
|
-
|
|
22488
|
-
|
|
22489
|
-
|
|
22490
|
-
return document.body.appendChild(host), setShadowRoot(root), () => host.remove();
|
|
22491
|
-
}), []), shadowRoot ? reactDomExports.createPortal(React.createElement(React.Fragment, null, React.createElement('style', null, dialogStyles), React.createElement('div', {
|
|
22492
|
-
className: 'dialog-mask'
|
|
23203
|
+
return host.setAttribute('data-oava-customer-dialog', ''), document.body.appendChild(host),
|
|
23204
|
+
setPortalContainer(host), () => host.remove();
|
|
23205
|
+
}), []), portalContainer ? reactDomExports.createPortal(React.createElement(React.Fragment, null, React.createElement('style', null, dialogStyles), React.createElement('div', {
|
|
23206
|
+
className: 'oava-customer-dialog-mask' + ('face-check-fail' === variant ? ' oava-customer-dialog-mask-face-check-fail' : '')
|
|
22493
23207
|
}, React.createElement('div', {
|
|
22494
|
-
className: 'dialog',
|
|
23208
|
+
className: 'oava-customer-dialog-panel' + ('face-check-fail' === variant ? ' oava-customer-dialog-face-check-fail' : ''),
|
|
22495
23209
|
role: 'alertdialog',
|
|
22496
23210
|
'aria-modal': 'true',
|
|
22497
23211
|
'aria-label': '视频见证提示',
|
|
22498
23212
|
'aria-describedby': contentId
|
|
22499
23213
|
}, React.createElement('div', {
|
|
22500
23214
|
id: contentId,
|
|
22501
|
-
className: 'dialog-content' + (smallText ? ' dialog-content-small' : '')
|
|
23215
|
+
className: 'oava-customer-dialog-content' + (smallText ? ' oava-customer-dialog-content-small' : '')
|
|
22502
23216
|
}, children), React.createElement('button', {
|
|
22503
23217
|
type: 'button',
|
|
22504
|
-
className: 'dialog-confirm',
|
|
23218
|
+
className: 'oava-customer-dialog-button oava-customer-dialog-confirm',
|
|
22505
23219
|
onClick: onConfirm
|
|
22506
23220
|
}, confirmText), cancelText && React.createElement('button', {
|
|
22507
23221
|
type: 'button',
|
|
22508
|
-
className: 'dialog-cancel',
|
|
23222
|
+
className: 'oava-customer-dialog-button oava-customer-dialog-cancel',
|
|
22509
23223
|
onClick: onCancel
|
|
22510
|
-
}, cancelText)))),
|
|
23224
|
+
}, cancelText)))), portalContainer) : null;
|
|
22511
23225
|
}, AudioCallToast = ({onAccept, onReject, visible}) => visible ? React.createElement(CustomerDialog, {
|
|
22512
23226
|
confirmText: '立即接听',
|
|
22513
23227
|
onConfirm: onAccept,
|
|
@@ -22553,15 +23267,20 @@ ErrorToast.propTypes = {
|
|
|
22553
23267
|
visible: !1
|
|
22554
23268
|
};
|
|
22555
23269
|
|
|
22556
|
-
const RecordFaceCheckFailToast = ({onConfirm, visible}) => visible ? React.createElement(CustomerDialog, {
|
|
22557
|
-
confirmText: '
|
|
22558
|
-
onConfirm,
|
|
23270
|
+
const RecordFaceCheckFailToast = ({onConfirm, onTransfer, visible, failureType = 'face'}) => visible ? React.createElement(CustomerDialog, {
|
|
23271
|
+
confirmText: '转接专属客服',
|
|
23272
|
+
onConfirm: onTransfer,
|
|
23273
|
+
cancelText: '退出,稍后重试',
|
|
23274
|
+
onCancel: onConfirm,
|
|
23275
|
+
variant: 'face-check-fail',
|
|
22559
23276
|
smallText: !0
|
|
22560
|
-
}, '
|
|
23277
|
+
}, 'answer' === failureType ? '检测到多次回答失败,是遇到问题了吗?您也可以选择专属客服服务完成视频录制' : React.createElement(React.Fragment, null, '因多次未检测到人脸,视频录制失败。', React.createElement('br', null), '可以为你转接专属客服完成视频录制')) : null;
|
|
22561
23278
|
|
|
22562
23279
|
RecordFaceCheckFailToast.propTypes = {
|
|
22563
23280
|
onConfirm: PropTypes.func.isRequired,
|
|
22564
|
-
|
|
23281
|
+
onTransfer: PropTypes.func.isRequired,
|
|
23282
|
+
visible: PropTypes.bool.isRequired,
|
|
23283
|
+
failureType: PropTypes.oneOf([ 'face', 'answer' ])
|
|
22565
23284
|
}, RecordFaceCheckFailToast.defaultProps = {
|
|
22566
23285
|
visible: !1
|
|
22567
23286
|
};
|
|
@@ -52650,10 +53369,10 @@ CpeProductsCicSDK_umd.exports, function(module, exports) {
|
|
|
52650
53369
|
|
|
52651
53370
|
var CpeProductsCicSDK_umdExports = CpeProductsCicSDK_umd.exports, CpeProductsCicSDK = getDefaultExportFromCjs(CpeProductsCicSDK_umdExports);
|
|
52652
53371
|
|
|
52653
|
-
const SUBTITLE_REVIEW = '正在审核您的开户资料,请稍等…';
|
|
53372
|
+
const FACE_CHECK_TRANSFER_REASON = 'face-check-transfer', CUSTOMER_FACE_CHECK_TRANSFER_CODE = '402', SUBTITLE_REVIEW = '正在审核您的开户资料,请稍等…', ASR_MATCH_STABLE_MS = 1e3, ASR_MATCH_SILENCE_MS = 800, ASR_SPEECH_LEVEL = .015;
|
|
52654
53373
|
|
|
52655
53374
|
function IndexWidget({customer, options}) {
|
|
52656
|
-
const {roomToken, aiServerUrl, faceCheckTimer, userFaceBase64, maxWaitTime = 180, authorization, apiUrl, logServiceUrl, request_no, isBrowserEnv = !0, showBackButton = !1, recordAnswerOnly = !1} = options, [asrWaitTimes, setAsrWaitTimes] = reactExports.useState(5), [subtitle, setSubtitle] = reactExports.useState(''), [textMessage, setTextMessage] = reactExports.useState(''), reviewTextMessageRef = reactExports.useRef(''), [playingList, setPlayingList] = reactExports.useState([]), [readyCount, setReadyCount] = reactExports.useState(0), [asrText, setAsrText] = reactExports.useState(''), asrResultTimerRef = reactExports.useRef(null), asrCountdownTimerRef = reactExports.useRef(null), isAwaitingAnswerRef = reactExports.useRef(!1), isAnsweringRef = reactExports.useRef(!1), isCustomerAudioMutedRef = reactExports.useRef(!1), audioOperationRef = reactExports.useRef(Promise.resolve()), isUnmountedRef = reactExports.useRef(!1), [noFaceCount, setNoFaceCount] = reactExports.useState(0), [isNoFace, setIsNoFace] = reactExports.useState(!1), [hasCompareResultFailed, setHasCompareResultFailed] = reactExports.useState(!1), [playingIndexs, setPlayingIndexs] = reactExports.useState([]), playingIndexsRef = reactExports.useRef(playingIndexs), [aiAgentStreamId, setAiAgentStreamId] = reactExports.useState(''), [customerStreamId, setCustomerStreamId] = reactExports.useState(''), [customerImage, setCustomerImage] = reactExports.useState(''), [isSend, setIsSend] = reactExports.useState(!1), [isSubscribeAgent, setIsSubscribeAgent] = reactExports.useState(!1), [showAgentInfo, setShowAgentInfo] = reactExports.useState(!1), [agentInfo, setAgentInfo] = reactExports.useState(''), aiAgentStreamIdRef = reactExports.useRef(aiAgentStreamId), silentAgentStreamIdRef = reactExports.useRef(null), playingListRef = reactExports.useRef(playingList), asrWaitTimesRef = reactExports.useRef(asrWaitTimes), customerImageRef = reactExports.useRef(customerImage), joinRoomTimes = reactExports.useRef(0), publishStreamTimes = reactExports.useRef(0), createStreamTimes = reactExports.useRef(0), subscribeStreamTimes = reactExports.useRef(0), [isReady, setIsReady] = reactExports.useState(!1), [isTransferring, setIsTransferring] = reactExports.useState(!1), [h5ExtraData, setH5ExtraData] = reactExports.useState(''), [isRecording, setIsRecording] = reactExports.useState(!1), [recordId, setRecordId] = reactExports.useState(''), recordIdRef = reactExports.useRef(recordId), isRecordingRef = reactExports.useRef(isRecording), recordFaceCheckFailCountRef = reactExports.useRef(0), recordFaceCheckFailReportedRef = reactExports.useRef(!1), recordFaceCheckFailThresholdRef = reactExports.useRef(0), [isCustomerVideoReady, setIsCustomerVideoReady] = reactExports.useState(!1), [showExitDialog, setShowExitDialog] = reactExports.useState(!1),
|
|
53375
|
+
const {roomToken, aiServerUrl, faceCheckTimer, userFaceBase64, maxWaitTime = 180, authorization, apiUrl, logServiceUrl, request_no, isBrowserEnv = !0, showBackButton = !1, recordAnswerOnly = !1, asrConfig} = options, realtimeAsrCredentialsRef = reactExports.useRef(null), realtimeAsrConfigRecordIdRef = reactExports.useRef(null), [asrWaitTimes, setAsrWaitTimes] = reactExports.useState(5), [subtitle, setSubtitle] = reactExports.useState(''), [textMessage, setTextMessage] = reactExports.useState(''), reviewTextMessageRef = reactExports.useRef(''), [playingList, setPlayingList] = reactExports.useState([]), [readyCount, setReadyCount] = reactExports.useState(0), [asrText, setAsrText] = reactExports.useState(''), asrResultTimerRef = reactExports.useRef(null), asrCountdownTimerRef = reactExports.useRef(null), realtimeAsrRoundRef = reactExports.useRef(null), seenRealtimeAsrRoundsRef = reactExports.useRef(new Set), isAwaitingAnswerRef = reactExports.useRef(!1), isAnsweringRef = reactExports.useRef(!1), isCustomerAudioMutedRef = reactExports.useRef(!1), audioOperationRef = reactExports.useRef(Promise.resolve()), isUnmountedRef = reactExports.useRef(!1), sessionEndingRef = reactExports.useRef(!1), answerFailureShownRef = reactExports.useRef(!1), recordFailureTimerRef = reactExports.useRef(null), [recordFailureType, setRecordFailureType] = reactExports.useState('face'), [noFaceCount, setNoFaceCount] = reactExports.useState(0), [isNoFace, setIsNoFace] = reactExports.useState(!1), [hasCompareResultFailed, setHasCompareResultFailed] = reactExports.useState(!1), [playingIndexs, setPlayingIndexs] = reactExports.useState([]), playingIndexsRef = reactExports.useRef(playingIndexs), [aiAgentStreamId, setAiAgentStreamId] = reactExports.useState(''), [customerStreamId, setCustomerStreamId] = reactExports.useState(''), [customerImage, setCustomerImage] = reactExports.useState(''), [isSend, setIsSend] = reactExports.useState(!1), [isSubscribeAgent, setIsSubscribeAgent] = reactExports.useState(!1), [showAgentInfo, setShowAgentInfo] = reactExports.useState(!1), [agentInfo, setAgentInfo] = reactExports.useState(''), aiAgentStreamIdRef = reactExports.useRef(aiAgentStreamId), silentAgentStreamIdRef = reactExports.useRef(null), playingListRef = reactExports.useRef(playingList), asrWaitTimesRef = reactExports.useRef(asrWaitTimes), customerImageRef = reactExports.useRef(customerImage), joinRoomTimes = reactExports.useRef(0), publishStreamTimes = reactExports.useRef(0), createStreamTimes = reactExports.useRef(0), subscribeStreamTimes = reactExports.useRef(0), [isReady, setIsReady] = reactExports.useState(!1), [isTransferring, setIsTransferring] = reactExports.useState(!1), [h5ExtraData, setH5ExtraData] = reactExports.useState(''), [isRecording, setIsRecording] = reactExports.useState(!1), [recordId, setRecordId] = reactExports.useState(''), recordIdRef = reactExports.useRef(recordId), isRecordingRef = reactExports.useRef(isRecording), recordFaceCheckFailCountRef = reactExports.useRef(0), recordFaceCheckFailReportedRef = reactExports.useRef(!1), recordFaceCheckFailThresholdRef = reactExports.useRef(0), [isCustomerVideoReady, setIsCustomerVideoReady] = reactExports.useState(!1), [showExitDialog, setShowExitDialog] = reactExports.useState(!1), [showPlayTip, setShowPlayTip] = reactExports.useState(!1), [playTipTarget, setPlayTipTarget] = reactExports.useState(''), [showAudioCallToast, setShowAudioCallToast] = reactExports.useState(!1), [isSilentAgentAudioMode, setIsSilentAgentAudioMode] = reactExports.useState(!1), isSilentAgentAudioModeRef = reactExports.useRef(isSilentAgentAudioMode), [showWaitView, setShowWaitView] = reactExports.useState(!1), [isHumanSilentAgent, setIsHumanSilentAgent] = reactExports.useState(!1);
|
|
52657
53376
|
reactExports.useRef(isHumanSilentAgent);
|
|
52658
53377
|
const [frameRateThreshold, setFrameRateThreshold] = reactExports.useState(null), [maxFrameRateCheckCount, setMaxFrameRateCheckCount] = reactExports.useState(3), maxFrameRateCheckCountRef = reactExports.useRef(maxFrameRateCheckCount), frameRateThresholdRef = reactExports.useRef(frameRateThreshold), [frameRateCheckCount, setFrameRateCheckCount] = reactExports.useState(0), frameRateCheckCountRef = reactExports.useRef(frameRateCheckCount), [showErrorToast, setShowErrorToast] = reactExports.useState(!1), [showRecordFaceCheckFailToast, setShowRecordFaceCheckFailToast] = reactExports.useState(!1), isCallConnected = Boolean(aiAgentStreamId && isReady), frameRateAlertReportedRef = reactExports.useRef(!1), reportLog = createBusinessTraceReporter({
|
|
52659
53378
|
logServiceUrl,
|
|
@@ -52684,23 +53403,217 @@ function IndexWidget({customer, options}) {
|
|
|
52684
53403
|
}
|
|
52685
53404
|
}))), audioOperationRef.current;
|
|
52686
53405
|
}
|
|
52687
|
-
}, updateAnswerAudio = answering => {
|
|
52688
|
-
|
|
53406
|
+
}, updateAnswerAudio = answering => (isAnsweringRef.current = answering, syncRecordingAudio()), getRealtimeAsrError = error => _objectSpread2({
|
|
53407
|
+
message: String((null == error ? void 0 : error.message) || error || '实时语音识别失败').replace(/wss?:\/\/[^\s"'<>]+/gi, '[WebSocket 地址已隐藏]').slice(0, 500)
|
|
53408
|
+
}, null != (null == error ? void 0 : error.code) ? {
|
|
53409
|
+
code: error.code
|
|
53410
|
+
} : {}), isCurrentRealtimeRound = round => !isUnmountedRef.current && round.active && realtimeAsrRoundRef.current === round, cancelRealtimeAsr = () => {
|
|
53411
|
+
var _round$client;
|
|
53412
|
+
const round = realtimeAsrRoundRef.current;
|
|
53413
|
+
round && (realtimeAsrRoundRef.current = null, round.active = !1, clearTimeout(round.deadlineTimer),
|
|
53414
|
+
clearTimeout(round.matchTimer), null === (_round$client = round.client) || void 0 === _round$client || _round$client.destroy());
|
|
53415
|
+
}, completeRealtimeAsr = (round, detail = {}) => {
|
|
53416
|
+
var _round$client2;
|
|
53417
|
+
if (!isCurrentRealtimeRound(round) || round.submitted) {
|
|
53418
|
+
return;
|
|
53419
|
+
}
|
|
53420
|
+
round.submitted = !0, round.active = !1, realtimeAsrRoundRef.current = null, clearTimeout(round.deadlineTimer),
|
|
53421
|
+
clearTimeout(round.matchTimer), clearAsrTimers(), isAwaitingAnswerRef.current = !1,
|
|
53422
|
+
updateAnswerAudio(!1), setShowWaitView(!1);
|
|
53423
|
+
const text = 'string' == typeof detail.text ? detail.text : round.text, error = detail.error || round.error, info = _objectSpread2({
|
|
53424
|
+
type: 'realtime-asr-result',
|
|
53425
|
+
roundId: round.roundId,
|
|
53426
|
+
questionKey: round.questionKey,
|
|
53427
|
+
text,
|
|
53428
|
+
reason: error ? 'error' : round.reason || detail.reason || 'final',
|
|
53429
|
+
answerType: matchAnswerResult(text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer)
|
|
53430
|
+
}, error ? {
|
|
53431
|
+
error: getRealtimeAsrError(error)
|
|
53432
|
+
} : {});
|
|
53433
|
+
console.log('[ASR] 本轮识别结束', {
|
|
53434
|
+
roundId: round.roundId,
|
|
53435
|
+
questionKey: round.questionKey,
|
|
53436
|
+
text,
|
|
53437
|
+
answerType: info.answerType,
|
|
53438
|
+
reason: info.reason,
|
|
53439
|
+
providerReason: detail.reason
|
|
53440
|
+
}), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
|
|
53441
|
+
asrResultTimerRef.current = null, setAsrText('');
|
|
53442
|
+
}), 1e3);
|
|
53443
|
+
const reportSendFailure = () => {
|
|
53444
|
+
reportLog('realtime_asr_result_send_fail', 'error', 'fail', {
|
|
53445
|
+
phase: 'business',
|
|
53446
|
+
roundId: round.roundId,
|
|
53447
|
+
questionKey: round.questionKey
|
|
53448
|
+
});
|
|
53449
|
+
};
|
|
53450
|
+
try {
|
|
53451
|
+
Promise.resolve(customer.sendMessage(JSON.stringify(info), 'all')).catch(reportSendFailure);
|
|
53452
|
+
} catch (_) {
|
|
53453
|
+
reportSendFailure();
|
|
53454
|
+
}
|
|
53455
|
+
null === (_round$client2 = round.client) || void 0 === _round$client2 || _round$client2.destroy();
|
|
53456
|
+
}, stopRealtimeAsr = (round, reason) => {
|
|
53457
|
+
if (isCurrentRealtimeRound(round) && ('timeout' === reason && (round.reason = reason,
|
|
53458
|
+
clearTimeout(round.deadlineTimer), clearInterval(asrCountdownTimerRef.current),
|
|
53459
|
+
asrCountdownTimerRef.current = null, setShowWaitView(!1)), !round.stopping)) {
|
|
53460
|
+
if (round.stopping = !0, round.reason = reason, console.log('[ASR] 停止采音', {
|
|
53461
|
+
roundId: round.roundId,
|
|
53462
|
+
questionKey: round.questionKey,
|
|
53463
|
+
text: round.text,
|
|
53464
|
+
reason
|
|
53465
|
+
}), clearTimeout(round.matchTimer), round.matchTimer = null, round.endDetail) {
|
|
53466
|
+
completeRealtimeAsr(round, round.endDetail);
|
|
53467
|
+
} else if (round.client) {
|
|
53468
|
+
'starting' === round.client.state && (round.error = new Error('回答时限内未能连接实时语音识别服务'));
|
|
53469
|
+
try {
|
|
53470
|
+
Promise.resolve(round.client.stop()).catch((error => completeRealtimeAsr(round, {
|
|
53471
|
+
error
|
|
53472
|
+
})));
|
|
53473
|
+
} catch (error) {
|
|
53474
|
+
completeRealtimeAsr(round, {
|
|
53475
|
+
error
|
|
53476
|
+
});
|
|
53477
|
+
}
|
|
53478
|
+
} else {
|
|
53479
|
+
completeRealtimeAsr(round, {
|
|
53480
|
+
error: new Error('回答时限内未能启动实时语音采集')
|
|
53481
|
+
});
|
|
53482
|
+
}
|
|
53483
|
+
}
|
|
53484
|
+
}, scheduleRealtimeAsrMatch = round => {
|
|
53485
|
+
if (!isCurrentRealtimeRound(round) || round.stopping || round.endDetail || null != round.matchTimer) {
|
|
53486
|
+
return;
|
|
53487
|
+
}
|
|
53488
|
+
if (3 === matchAnswerResult(round.text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer)) {
|
|
53489
|
+
return;
|
|
53490
|
+
}
|
|
53491
|
+
const now = Date.now(), delay = Math.max(40, ASR_MATCH_STABLE_MS - (now - round.textChangedAt), ASR_MATCH_SILENCE_MS - (now - round.lastSpeechAt));
|
|
53492
|
+
round.matchTimer = setTimeout((() => {
|
|
53493
|
+
round.matchTimer = null, isCurrentRealtimeRound(round) && !round.stopping && (null == round.lastAudioAt || Date.now() - round.lastAudioAt > 250 || 3 !== matchAnswerResult(round.text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer) && (Date.now() - round.textChangedAt >= ASR_MATCH_STABLE_MS && Date.now() - round.lastSpeechAt >= ASR_MATCH_SILENCE_MS ? stopRealtimeAsr(round, 'matched') : scheduleRealtimeAsrMatch(round)));
|
|
53494
|
+
}), delay);
|
|
53495
|
+
}, startRealtimeAsr = (data, view) => {
|
|
53496
|
+
const duration = getRealtimeAsrDuration(data.durationSeconds || asrWaitTimesRef.current);
|
|
53497
|
+
asrDebug('round.start', {
|
|
53498
|
+
roundId: data.roundId,
|
|
53499
|
+
questionKey: data.questionKey,
|
|
53500
|
+
duration,
|
|
53501
|
+
recordId: realtimeAsrConfigRecordIdRef.current,
|
|
53502
|
+
hasConfigPromise: Boolean(realtimeAsrCredentialsRef.current)
|
|
53503
|
+
});
|
|
53504
|
+
const round = {
|
|
53505
|
+
roundId: data.roundId,
|
|
53506
|
+
questionKey: data.questionKey,
|
|
53507
|
+
correctAnswer: 'string' == typeof data.correctAnswer ? data.correctAnswer : void 0,
|
|
53508
|
+
errorAnswer: 'string' == typeof data.errorAnswer ? data.errorAnswer : void 0,
|
|
53509
|
+
active: !0,
|
|
53510
|
+
submitted: !1,
|
|
53511
|
+
stopping: !1,
|
|
53512
|
+
text: '',
|
|
53513
|
+
textChangedAt: Date.now(),
|
|
53514
|
+
lastSpeechAt: Date.now(),
|
|
53515
|
+
lastAudioAt: null,
|
|
53516
|
+
matchTimer: null,
|
|
53517
|
+
deadlineAt: Date.now() + 1e3 * duration
|
|
53518
|
+
};
|
|
53519
|
+
let config;
|
|
53520
|
+
realtimeAsrRoundRef.current = round;
|
|
53521
|
+
try {
|
|
53522
|
+
var _customer$localStream;
|
|
53523
|
+
if (config = getAsrConfig(asrConfig, !0), 1 !== config.type) {
|
|
53524
|
+
throw new Error('坐席已启用实时识别,但客户端 asrConfig.type 未设为 1');
|
|
53525
|
+
}
|
|
53526
|
+
if (!data.roundId || null == data.questionKey || '' === data.questionKey) {
|
|
53527
|
+
throw new Error('实时识别消息缺少 roundId 或 questionKey');
|
|
53528
|
+
}
|
|
53529
|
+
const stream = null === (_customer$localStream = customer.localStream) || void 0 === _customer$localStream ? void 0 : _customer$localStream.mediaStream;
|
|
53530
|
+
if (null == stream || !stream.getAudioTracks().some((track => 'live' === track.readyState))) {
|
|
53531
|
+
throw new Error('实时识别需要可用的 iRTC 本地麦克风音轨');
|
|
53532
|
+
}
|
|
53533
|
+
setShowWaitView(!0), renderCir(duration, view, (() => stopRealtimeAsr(round, 'timeout')), round.deadlineAt),
|
|
53534
|
+
round.deadlineTimer = setTimeout((() => stopRealtimeAsr(round, 'timeout')), 1e3 * duration),
|
|
53535
|
+
Promise.resolve(updateAnswerAudio(!0)).then(_asyncToGenerator((function*() {
|
|
53536
|
+
if (!isCurrentRealtimeRound(round)) {
|
|
53537
|
+
return;
|
|
53538
|
+
}
|
|
53539
|
+
const result = yield realtimeAsrCredentialsRef.current;
|
|
53540
|
+
if (!isCurrentRealtimeRound(round)) {
|
|
53541
|
+
return;
|
|
53542
|
+
}
|
|
53543
|
+
if (null != result && result.error) {
|
|
53544
|
+
throw result.error;
|
|
53545
|
+
}
|
|
53546
|
+
const credentials = null == result ? void 0 : result.credentials;
|
|
53547
|
+
if (asrDebug('round.config', {
|
|
53548
|
+
roundId: round.roundId,
|
|
53549
|
+
appId: null == credentials ? void 0 : credentials.appId,
|
|
53550
|
+
remainingMs: round.deadlineAt - Date.now()
|
|
53551
|
+
}), !credentials) {
|
|
53552
|
+
throw new Error('尚未收到开始录制通知,未获取实时 ASR 配置');
|
|
53553
|
+
}
|
|
53554
|
+
if (Date.now() >= round.deadlineAt) {
|
|
53555
|
+
return void stopRealtimeAsr(round, 'timeout');
|
|
53556
|
+
}
|
|
53557
|
+
const client = new RealtimeAsrClient({
|
|
53558
|
+
wsUrl: credentials.wsUrl,
|
|
53559
|
+
appId: credentials.appId,
|
|
53560
|
+
mediaStream: stream,
|
|
53561
|
+
business: getRealtimeAsrBusiness(config, duration)
|
|
53562
|
+
});
|
|
53563
|
+
round.client = client, client.addEventListener('result', (({detail}) => {
|
|
53564
|
+
if (!isCurrentRealtimeRound(round)) {
|
|
53565
|
+
return;
|
|
53566
|
+
}
|
|
53567
|
+
const text = 'string' == typeof (null == detail ? void 0 : detail.text) ? detail.text : '';
|
|
53568
|
+
text !== round.text && (round.textChangedAt = Date.now(), clearTimeout(round.matchTimer),
|
|
53569
|
+
round.matchTimer = null), round.text = text, setAsrText(round.text), scheduleRealtimeAsrMatch(round);
|
|
53570
|
+
})), client.addEventListener('volume', (({detail}) => {
|
|
53571
|
+
isCurrentRealtimeRound(round) && Number.isFinite(null == detail ? void 0 : detail.level) && (round.lastAudioAt = Date.now(),
|
|
53572
|
+
detail.level >= ASR_SPEECH_LEVEL && (round.lastSpeechAt = Date.now()), scheduleRealtimeAsrMatch(round));
|
|
53573
|
+
})), client.addEventListener('capturestop', (() => {
|
|
53574
|
+
isCurrentRealtimeRound(round) && updateAnswerAudio(!1);
|
|
53575
|
+
})), client.addEventListener('error', (({detail}) => {
|
|
53576
|
+
isCurrentRealtimeRound(round) && (round.error = detail);
|
|
53577
|
+
})), client.addEventListener('end', (({detail}) => ((round, detail = {}) => {
|
|
53578
|
+
if (isCurrentRealtimeRound(round)) {
|
|
53579
|
+
if (clearTimeout(round.matchTimer), round.matchTimer = null, round.text = 'string' == typeof detail.text ? detail.text : round.text,
|
|
53580
|
+
!detail.error && !round.error && 'final' === detail.reason && 3 === matchAnswerResult(round.text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer) && Date.now() < round.deadlineAt) {
|
|
53581
|
+
return round.endDetail = detail, round.stopping = !1, round.reason = null, setAsrText(round.text),
|
|
53582
|
+
void console.log('[ASR] 服务最终结果未命中,等待倒计时结束', {
|
|
53583
|
+
roundId: round.roundId,
|
|
53584
|
+
questionKey: round.questionKey,
|
|
53585
|
+
text: round.text
|
|
53586
|
+
});
|
|
53587
|
+
}
|
|
53588
|
+
completeRealtimeAsr(round, detail);
|
|
53589
|
+
}
|
|
53590
|
+
})(round, detail))), Promise.resolve(client.start()).catch((error => completeRealtimeAsr(round, {
|
|
53591
|
+
error
|
|
53592
|
+
})));
|
|
53593
|
+
}))).catch((error => completeRealtimeAsr(round, {
|
|
53594
|
+
error
|
|
53595
|
+
})));
|
|
53596
|
+
} catch (error) {
|
|
53597
|
+
completeRealtimeAsr(round, {
|
|
53598
|
+
error
|
|
53599
|
+
});
|
|
53600
|
+
}
|
|
52689
53601
|
}, resetAsrDisplay = () => {
|
|
52690
|
-
clearAsrTimers(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1),
|
|
52691
|
-
setShowWaitView(!1);
|
|
53602
|
+
cancelRealtimeAsr(), clearAsrTimers(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1),
|
|
53603
|
+
setAsrText(''), setShowWaitView(!1);
|
|
52692
53604
|
}, updatePlaybackSubtitle = text => {
|
|
52693
53605
|
resetAsrDisplay(), setSubtitle(text);
|
|
52694
|
-
}, resetRecordFaceCheckFailState = () => {
|
|
52695
|
-
|
|
52696
|
-
|
|
53606
|
+
}, resetRecordFaceCheckFailState = (preserveAnswerFailure = !1) => {
|
|
53607
|
+
clearTimeout(recordFailureTimerRef.current), recordFaceCheckFailCountRef.current = 0,
|
|
53608
|
+
recordFaceCheckFailReportedRef.current = !1, preserveAnswerFailure && answerFailureShownRef.current || (answerFailureShownRef.current = !1,
|
|
53609
|
+
setRecordFailureType('face'), setShowRecordFaceCheckFailToast(!1));
|
|
52697
53610
|
};
|
|
52698
53611
|
reactExports.useEffect((() => {
|
|
52699
53612
|
isRecordingRef.current = isRecording, isRecording || (isAnsweringRef.current = !1),
|
|
52700
53613
|
syncRecordingAudio();
|
|
52701
53614
|
}), [ isRecording ]);
|
|
52702
53615
|
const subscribeRemoteStream = function() {
|
|
52703
|
-
var
|
|
53616
|
+
var _ref3 = _asyncToGenerator((function*(streamId, streamLabel) {
|
|
52704
53617
|
const startTime = Date.now();
|
|
52705
53618
|
try {
|
|
52706
53619
|
return yield customer.subscribeStream(streamId), subscribeStreamTimes.current = Date.now() - startTime,
|
|
@@ -52720,10 +53633,10 @@ function IndexWidget({customer, options}) {
|
|
|
52720
53633
|
}
|
|
52721
53634
|
}));
|
|
52722
53635
|
return function(_x, _x2) {
|
|
52723
|
-
return
|
|
53636
|
+
return _ref3.apply(this, arguments);
|
|
52724
53637
|
};
|
|
52725
53638
|
}(), joinRoom = function() {
|
|
52726
|
-
var
|
|
53639
|
+
var _ref4 = _asyncToGenerator((function*() {
|
|
52727
53640
|
console.log('joinRoom');
|
|
52728
53641
|
try {
|
|
52729
53642
|
listen();
|
|
@@ -52751,11 +53664,11 @@ function IndexWidget({customer, options}) {
|
|
|
52751
53664
|
}
|
|
52752
53665
|
}));
|
|
52753
53666
|
return function() {
|
|
52754
|
-
return
|
|
53667
|
+
return _ref4.apply(this, arguments);
|
|
52755
53668
|
};
|
|
52756
53669
|
}(), listen = () => {
|
|
52757
53670
|
customer.onStreamAdd(function() {
|
|
52758
|
-
var
|
|
53671
|
+
var _ref5 = _asyncToGenerator((function*(info) {
|
|
52759
53672
|
console.log('onStreamAdd', info);
|
|
52760
53673
|
let streamId = info.id;
|
|
52761
53674
|
reportLog('stream_add', 'info', 'info', {
|
|
@@ -52866,12 +53779,12 @@ function IndexWidget({customer, options}) {
|
|
|
52866
53779
|
}
|
|
52867
53780
|
}));
|
|
52868
53781
|
return function(_x3) {
|
|
52869
|
-
return
|
|
53782
|
+
return _ref5.apply(this, arguments);
|
|
52870
53783
|
};
|
|
52871
53784
|
}()), customer.onMessageReceived((msg => {
|
|
52872
53785
|
console.log('message received', msg), dealWithMessage(msg.message);
|
|
52873
53786
|
})), customer.onPlayingEvent(function() {
|
|
52874
|
-
var
|
|
53787
|
+
var _ref6 = _asyncToGenerator((function*(data) {
|
|
52875
53788
|
let msg = data.data;
|
|
52876
53789
|
if (console.log('playingIndexs', playingIndexsRef.current), msg.streamId === aiAgentStreamIdRef.current) {
|
|
52877
53790
|
if ('started' === msg.playingProgress || 'switched' === msg.playingProgress) {
|
|
@@ -52891,7 +53804,7 @@ function IndexWidget({customer, options}) {
|
|
|
52891
53804
|
}
|
|
52892
53805
|
}));
|
|
52893
53806
|
return function(_x4) {
|
|
52894
|
-
return
|
|
53807
|
+
return _ref6.apply(this, arguments);
|
|
52895
53808
|
};
|
|
52896
53809
|
}()), customer.onParticipantAdded((e => {
|
|
52897
53810
|
console.log('有新用户加入', e);
|
|
@@ -52900,13 +53813,13 @@ function IndexWidget({customer, options}) {
|
|
|
52900
53813
|
phase: 'business',
|
|
52901
53814
|
recordStatus: 'end',
|
|
52902
53815
|
recordId: e.recordId || ''
|
|
52903
|
-
}), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState());
|
|
53816
|
+
}), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState(!0));
|
|
52904
53817
|
})), customer.onRecordAddListener((e => {
|
|
52905
53818
|
console.log('录制开启', e), e.recordId == recordIdRef.current && (reportLog('record_state_change', 'info', 'success', {
|
|
52906
53819
|
phase: 'business',
|
|
52907
53820
|
recordStatus: 'start',
|
|
52908
53821
|
recordId: e.recordId || ''
|
|
52909
|
-
}), resetRecordFaceCheckFailState(), setIsRecording(!0));
|
|
53822
|
+
}), resetRecordFaceCheckFailState(!0), setIsRecording(!0));
|
|
52910
53823
|
})), customer.onRecordErrorListener((e => {
|
|
52911
53824
|
console.log('录制错误', e, recordIdRef.current), e.recordId == recordIdRef.current && (reportLog('record_state_change', 'error', 'fail', {
|
|
52912
53825
|
phase: 'business',
|
|
@@ -52914,7 +53827,7 @@ function IndexWidget({customer, options}) {
|
|
|
52914
53827
|
recordId: e.recordId || '',
|
|
52915
53828
|
errorCode: (null == e ? void 0 : e.code) || '',
|
|
52916
53829
|
errorMessage: (null == e ? void 0 : e.message) || ''
|
|
52917
|
-
}), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState());
|
|
53830
|
+
}), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState(!0));
|
|
52918
53831
|
})), customer.onPublishQualityReport((event => {
|
|
52919
53832
|
var _event$message;
|
|
52920
53833
|
let frameRate = null === (_event$message = event.message) || void 0 === _event$message || null === (_event$message = _event$message.report) || void 0 === _event$message || null === (_event$message = _event$message.info) || void 0 === _event$message ? void 0 : _event$message.frameRate;
|
|
@@ -52931,14 +53844,19 @@ function IndexWidget({customer, options}) {
|
|
|
52931
53844
|
}
|
|
52932
53845
|
}));
|
|
52933
53846
|
}, sessionEnd = (reason, errorInfo) => {
|
|
52934
|
-
|
|
53847
|
+
if (sessionEndingRef.current) {
|
|
53848
|
+
return;
|
|
53849
|
+
}
|
|
53850
|
+
const isCustomerTransfer = reason === FACE_CHECK_TRANSFER_REASON;
|
|
53851
|
+
isCustomerTransfer && (sessionEndingRef.current = !0, customer.sessionEndReason = reason),
|
|
53852
|
+
resetAsrDisplay(), console.log('%c session End', 'color: red; font-size: 20px;');
|
|
52935
53853
|
let info = {
|
|
52936
53854
|
type: 'quit',
|
|
52937
53855
|
extraData: 'auto-quit',
|
|
52938
53856
|
reason,
|
|
52939
53857
|
errorInfo
|
|
52940
53858
|
};
|
|
52941
|
-
reportLog('session_end', 'warn', 'info', {
|
|
53859
|
+
if (reportLog('session_end', 'warn', 'info', {
|
|
52942
53860
|
phase: 'ui',
|
|
52943
53861
|
reason,
|
|
52944
53862
|
errorInfo: errorInfo || '',
|
|
@@ -52947,68 +53865,147 @@ function IndexWidget({customer, options}) {
|
|
|
52947
53865
|
aiAgentStreamId: aiAgentStreamIdRef.current || ''
|
|
52948
53866
|
}, {
|
|
52949
53867
|
keepalive: !0
|
|
52950
|
-
}),
|
|
53868
|
+
}), isCustomerTransfer) {
|
|
53869
|
+
return new Promise((resolve => {
|
|
53870
|
+
let finished = !1;
|
|
53871
|
+
const finish = () => {
|
|
53872
|
+
if (!finished) {
|
|
53873
|
+
finished = !0, clearTimeout(timer);
|
|
53874
|
+
try {
|
|
53875
|
+
customer.sendBusinessData(info);
|
|
53876
|
+
} finally {
|
|
53877
|
+
customer.destroy(), resolve();
|
|
53878
|
+
}
|
|
53879
|
+
}
|
|
53880
|
+
}, timer = setTimeout(finish, 2e3);
|
|
53881
|
+
try {
|
|
53882
|
+
Promise.resolve(customer.sendMessage(JSON.stringify(info), 'all')).then(finish, finish);
|
|
53883
|
+
} catch (error) {
|
|
53884
|
+
finish();
|
|
53885
|
+
}
|
|
53886
|
+
}));
|
|
53887
|
+
}
|
|
53888
|
+
customer.sendMessage(JSON.stringify(info), 'all'), customer.sendBusinessData(info);
|
|
52951
53889
|
}, dealWithMessage = msg => {
|
|
52952
|
-
if (isJsonString$1(msg)) {
|
|
53890
|
+
if (!sessionEndingRef.current && isJsonString$1(msg)) {
|
|
52953
53891
|
let data = JSON.parse(msg);
|
|
52954
|
-
if ('
|
|
52955
|
-
|
|
52956
|
-
} else if ('insert-playing' === data.type) {
|
|
52957
|
-
reviewTextMessageRef.current = '', !isSilentAgentAudioModeRef.current && updatePlaybackSubtitle(data.data);
|
|
52958
|
-
} else if ('ready' === data.type) {
|
|
52959
|
-
console.log('ready data,playList', data.data, data.asrWaitTimes), setPlayingList(data.data),
|
|
52960
|
-
setIsReady(!0), setAsrWaitTimes(data.asrWaitTimes), recordFaceCheckFailThresholdRef.current = Number(data.recordFaceCheckFailThreshold || 0);
|
|
52961
|
-
} else if ('cmd' === data.type) {
|
|
52962
|
-
switch (data.cmd) {
|
|
52963
|
-
case 'transfer':
|
|
52964
|
-
setIsTransferring(!0);
|
|
52965
|
-
break;
|
|
52966
|
-
|
|
52967
|
-
case 'cancel-transfer':
|
|
52968
|
-
setIsTransferring(!1);
|
|
52969
|
-
break;
|
|
52970
|
-
|
|
52971
|
-
case 'audio-call':
|
|
52972
|
-
setShowAudioCallToast(!0);
|
|
52973
|
-
}
|
|
52974
|
-
} else if ('start-asr' === data.type) {
|
|
52975
|
-
console.log('start-asr!');
|
|
52976
|
-
let view = document.getElementById('customer-widget-waitView');
|
|
52977
|
-
reviewTextMessageRef.current = '', resetAsrDisplay(), isAwaitingAnswerRef.current = !0,
|
|
52978
|
-
updateAnswerAudio(!0), setShowWaitView(!0), setSubtitle('请在倒计时结束前用"是"或"否"完成回复'),
|
|
52979
|
-
renderCir(asrWaitTimesRef.current, view);
|
|
52980
|
-
} else if ('answer' === data.type) {
|
|
52981
|
-
if (!isAwaitingAnswerRef.current) {
|
|
53892
|
+
if ('answer-fail' === data.type && 'version3' === data.workflowVersion) {
|
|
53893
|
+
if (answerFailureShownRef.current) {
|
|
52982
53894
|
return;
|
|
52983
53895
|
}
|
|
52984
|
-
|
|
52985
|
-
|
|
52986
|
-
setShowWaitView(!1), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
|
|
52987
|
-
asrResultTimerRef.current = null, setAsrText('');
|
|
52988
|
-
}), 1e3);
|
|
53896
|
+
answerFailureShownRef.current = !0, clearTimeout(recordFailureTimerRef.current),
|
|
53897
|
+
resetAsrDisplay(), setRecordFailureType('answer'), setShowRecordFaceCheckFailToast(!0);
|
|
52989
53898
|
} else {
|
|
52990
|
-
|
|
52991
|
-
|
|
52992
|
-
|
|
52993
|
-
|
|
52994
|
-
|
|
52995
|
-
|
|
52996
|
-
|
|
52997
|
-
}
|
|
52998
|
-
|
|
52999
|
-
|
|
53000
|
-
|
|
53001
|
-
|
|
53002
|
-
|
|
53899
|
+
if (answerFailureShownRef.current) {
|
|
53900
|
+
return;
|
|
53901
|
+
}
|
|
53902
|
+
if ('text' === data.type) {
|
|
53903
|
+
reviewTextMessageRef.current = data.message || '', setSubtitle(data.message);
|
|
53904
|
+
} else if ('insert-playing' === data.type) {
|
|
53905
|
+
reviewTextMessageRef.current = '', !isSilentAgentAudioModeRef.current && updatePlaybackSubtitle(data.data);
|
|
53906
|
+
} else if ('ready' === data.type) {
|
|
53907
|
+
console.log('ready data,playList', data.data, data.asrWaitTimes), setPlayingList(data.data),
|
|
53908
|
+
setIsReady(!0), setAsrWaitTimes(data.asrWaitTimes), recordFaceCheckFailThresholdRef.current = Number(data.recordFaceCheckFailThreshold || 0);
|
|
53909
|
+
} else if ('cmd' === data.type) {
|
|
53910
|
+
switch (data.cmd) {
|
|
53911
|
+
case 'transfer':
|
|
53912
|
+
realtimeAsrRoundRef.current && resetAsrDisplay(), setIsTransferring(!0);
|
|
53913
|
+
break;
|
|
53914
|
+
|
|
53915
|
+
case 'cancel-transfer':
|
|
53916
|
+
setIsTransferring(!1);
|
|
53917
|
+
break;
|
|
53918
|
+
|
|
53919
|
+
case 'audio-call':
|
|
53920
|
+
setShowAudioCallToast(!0);
|
|
53921
|
+
}
|
|
53922
|
+
} else if ('start-asr' === data.type) {
|
|
53923
|
+
var _data$correctAnswer, _data$errorAnswer;
|
|
53924
|
+
if (console.log('start-asr!'), !0 === data.realtimeAsr && data.roundId) {
|
|
53925
|
+
if (seenRealtimeAsrRoundsRef.current.has(data.roundId)) {
|
|
53926
|
+
return;
|
|
53927
|
+
}
|
|
53928
|
+
if (seenRealtimeAsrRoundsRef.current.add(data.roundId), seenRealtimeAsrRoundsRef.current.size > 100) {
|
|
53929
|
+
const oldest = seenRealtimeAsrRoundsRef.current.values().next().value;
|
|
53930
|
+
seenRealtimeAsrRoundsRef.current.delete(oldest);
|
|
53931
|
+
}
|
|
53932
|
+
}
|
|
53933
|
+
let view = document.getElementById('customer-widget-waitView');
|
|
53934
|
+
reviewTextMessageRef.current = '', resetAsrDisplay();
|
|
53935
|
+
const answerMaterial = playingIndexsRef.current.reduce(((last, index) => {
|
|
53936
|
+
const material = playingListRef.current[index];
|
|
53937
|
+
return !0 === (null == material ? void 0 : material.isSound) ? material : last;
|
|
53938
|
+
}), null), answerLists = getAnswerLists(null !== (_data$correctAnswer = data.correctAnswer) && void 0 !== _data$correctAnswer ? _data$correctAnswer : null == answerMaterial ? void 0 : answerMaterial.correct_answer, null !== (_data$errorAnswer = data.errorAnswer) && void 0 !== _data$errorAnswer ? _data$errorAnswer : null == answerMaterial ? void 0 : answerMaterial.error_answer);
|
|
53939
|
+
console.log('[ASR] 本轮话术与答案名单', {
|
|
53940
|
+
roundId: data.roundId || '',
|
|
53941
|
+
questionKey: data.questionKey || (null == answerMaterial ? void 0 : answerMaterial.index) || '',
|
|
53942
|
+
question: (null == answerMaterial ? void 0 : answerMaterial.words_content) || '',
|
|
53943
|
+
whiteList: answerLists.whiteList,
|
|
53944
|
+
blackList: answerLists.blackList,
|
|
53945
|
+
matchRule: '完整答案相等'
|
|
53946
|
+
}), isAwaitingAnswerRef.current = !0, setSubtitle('请在倒计时结束前用"是"或"否"完成回复'), !0 === data.realtimeAsr ? startRealtimeAsr(data, view) : (1 === (null == asrConfig ? void 0 : asrConfig.type) && reportLog('realtime_asr_mode_mismatch', 'warn', 'info', {
|
|
53947
|
+
phase: 'business',
|
|
53948
|
+
message: '客户端配置了实时识别,坐席本轮使用离线识别'
|
|
53949
|
+
}), updateAnswerAudio(!0), setShowWaitView(!0), renderCir(asrWaitTimesRef.current, view));
|
|
53950
|
+
} else if ('cancel-realtime-asr' === data.type) {
|
|
53951
|
+
const round = realtimeAsrRoundRef.current;
|
|
53952
|
+
round && round.roundId === data.roundId && round.questionKey === data.questionKey && resetAsrDisplay();
|
|
53953
|
+
} else if ('answer' === data.type) {
|
|
53954
|
+
const round = realtimeAsrRoundRef.current;
|
|
53955
|
+
if ((round || data.roundId) && (!round || data.roundId !== round.roundId || data.questionKey !== round.questionKey)) {
|
|
53956
|
+
return;
|
|
53957
|
+
}
|
|
53958
|
+
if (!isAwaitingAnswerRef.current) {
|
|
53959
|
+
return;
|
|
53960
|
+
}
|
|
53961
|
+
cancelRealtimeAsr(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1), clearAsrTimers();
|
|
53962
|
+
let text = data.text || '';
|
|
53963
|
+
setShowWaitView(!1), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
|
|
53964
|
+
asrResultTimerRef.current = null, setAsrText('');
|
|
53965
|
+
}), 1e3);
|
|
53966
|
+
} else if ('update-playingIndex' === data.type) {
|
|
53967
|
+
realtimeAsrRoundRef.current && resetAsrDisplay(), Array.isArray(data.playingAiList) && (playingListRef.current = data.playingAiList,
|
|
53968
|
+
setPlayingList(data.playingAiList)), playingIndexsRef.current = data.data, setPlayingIndexs(data.data);
|
|
53969
|
+
} else if ('agent-info' === data.type) {
|
|
53970
|
+
console.log('agent-info', data), setAgentInfo(data.message), setFrameRateThreshold(data.frameRateThreshold),
|
|
53971
|
+
setMaxFrameRateCheckCount(data.maxFrameRateCheckCount);
|
|
53972
|
+
} else if ('h5-link' === data.type) {
|
|
53973
|
+
setH5ExtraData(data.extraData);
|
|
53974
|
+
} else if ('system-recordId' === data.type) {
|
|
53975
|
+
var _asrConfig$type;
|
|
53976
|
+
asrDebug('record.start', {
|
|
53977
|
+
recordId: data.recordId,
|
|
53978
|
+
asrType: null !== (_asrConfig$type = null == asrConfig ? void 0 : asrConfig.type) && void 0 !== _asrConfig$type ? _asrConfig$type : 0,
|
|
53979
|
+
duplicate: realtimeAsrConfigRecordIdRef.current === data.recordId
|
|
53980
|
+
}), 1 === getAsrConfig(asrConfig).type && data.recordId && realtimeAsrConfigRecordIdRef.current !== data.recordId && (cancelRealtimeAsr(),
|
|
53981
|
+
realtimeAsrConfigRecordIdRef.current = data.recordId, realtimeAsrCredentialsRef.current = queryRealtimeAsrConfig(aiServerUrl, asrConfig).then((credentials => ({
|
|
53982
|
+
credentials
|
|
53983
|
+
})), (error => ({
|
|
53984
|
+
error
|
|
53985
|
+
})))), console.log('data.recordId', data.recordId), setRecordId(data.recordId),
|
|
53986
|
+
setIsRecording(!0), recordIdRef.current = data.recordId, resetRecordFaceCheckFailState(),
|
|
53987
|
+
reportLog('record_state_change', 'info', 'success', {
|
|
53988
|
+
phase: 'business',
|
|
53989
|
+
recordStatus: 'start',
|
|
53990
|
+
recordId: data.recordId || ''
|
|
53991
|
+
});
|
|
53992
|
+
} else {
|
|
53993
|
+
'playing-audio-message' === data.type ? (reviewTextMessageRef.current = '', updatePlaybackSubtitle(data.message)) : 'hangup-audio-call' === data.type && (setIsSilentAgentAudioMode(!1),
|
|
53994
|
+
setShowAudioCallToast(!1));
|
|
53995
|
+
}
|
|
53996
|
+
}
|
|
53997
|
+
}
|
|
53998
|
+
}, renderCir = (time = 5, cirDom, onExpired, deadlineAt) => {
|
|
53003
53999
|
console.log('renderCir', time, cirDom);
|
|
53004
54000
|
let totalTime = 1e3 * time;
|
|
53005
54001
|
const svgHtml = `\n <div class="progress-wrapper">\n <svg width="60" height="60" viewBox="0 0 60 60">\n <circle cx="30" cy="30" r="24" stroke-width="4" stroke="#FFA100" fill="none" style="opacity: 0.5"></circle>\n <circle id="progressCircle" cx="30" cy="30" r="24" stroke-width="4" stroke="#FFA100" fill="none" transform="matrix(0,-1,1,0,0,60)" stroke-dasharray="0 151"></circle>\n </svg>\n <span class="remainingTime" id="remainingTime">${String(time).padStart(2, '0')}</span>\n </div>\n `;
|
|
53006
54002
|
cirDom.innerHTML = svgHtml;
|
|
53007
54003
|
const remainingTimeElement = document.getElementById('remainingTime'), progressCircle = document.getElementById('progressCircle'), perimeter = 2 * Math.PI * 24;
|
|
53008
54004
|
asrCountdownTimerRef.current = setInterval((() => {
|
|
53009
|
-
if (totalTime
|
|
53010
|
-
return updateAnswerAudio(!1), cirDom.innerHTML = '', setShowWaitView(!1),
|
|
53011
|
-
|
|
54005
|
+
if (totalTime = deadlineAt ? deadlineAt - Date.now() : totalTime - 100, totalTime <= 0) {
|
|
54006
|
+
return onExpired || updateAnswerAudio(!1), cirDom.innerHTML = '', setShowWaitView(!1),
|
|
54007
|
+
clearInterval(asrCountdownTimerRef.current), asrCountdownTimerRef.current = null,
|
|
54008
|
+
void (null == onExpired || onExpired());
|
|
53012
54009
|
}
|
|
53013
54010
|
const remainingSeconds = Math.ceil(totalTime / 1e3);
|
|
53014
54011
|
remainingTimeElement.textContent = String(remainingSeconds).padStart(2, '0');
|
|
@@ -53022,7 +54019,7 @@ function IndexWidget({customer, options}) {
|
|
|
53022
54019
|
var _s$data2, _s$data3;
|
|
53023
54020
|
(() => {
|
|
53024
54021
|
const threshold = Number(recordFaceCheckFailThresholdRef.current || 0);
|
|
53025
|
-
if (!isRecordingRef.current || !recordIdRef.current || !threshold || threshold <= 0 || recordFaceCheckFailReportedRef.current) {
|
|
54022
|
+
if (!isRecordingRef.current || !recordIdRef.current || !threshold || threshold <= 0 || recordFaceCheckFailReportedRef.current || answerFailureShownRef.current) {
|
|
53026
54023
|
return;
|
|
53027
54024
|
}
|
|
53028
54025
|
if (recordFaceCheckFailCountRef.current += 1, recordFaceCheckFailCountRef.current < threshold) {
|
|
@@ -53038,8 +54035,9 @@ function IndexWidget({customer, options}) {
|
|
|
53038
54035
|
}
|
|
53039
54036
|
};
|
|
53040
54037
|
customer.sendMessage(JSON.stringify(info), 'all'), recordFaceCheckFailReportedRef.current = !0,
|
|
53041
|
-
setTimeout((() => {
|
|
53042
|
-
|
|
54038
|
+
recordFailureTimerRef.current = setTimeout((() => {
|
|
54039
|
+
answerFailureShownRef.current || sessionEndingRef.current || (setRecordFailureType('face'),
|
|
54040
|
+
setShowRecordFaceCheckFailToast(!0));
|
|
53043
54041
|
}), 1e3);
|
|
53044
54042
|
})();
|
|
53045
54043
|
const score = null === (_s$data2 = s.data) || void 0 === _s$data2 ? void 0 : _s$data2.score;
|
|
@@ -53072,7 +54070,7 @@ function IndexWidget({customer, options}) {
|
|
|
53072
54070
|
})), faceCheckTimer || 2e3), checkFaceAndCaptureOnce = () => {
|
|
53073
54071
|
let timer = null, isChecking = !1;
|
|
53074
54072
|
const runCheck = function() {
|
|
53075
|
-
var
|
|
54073
|
+
var _ref8 = _asyncToGenerator((function*() {
|
|
53076
54074
|
if (!isChecking) {
|
|
53077
54075
|
isChecking = !0;
|
|
53078
54076
|
try {
|
|
@@ -53088,12 +54086,12 @@ function IndexWidget({customer, options}) {
|
|
|
53088
54086
|
}
|
|
53089
54087
|
}));
|
|
53090
54088
|
return function() {
|
|
53091
|
-
return
|
|
54089
|
+
return _ref8.apply(this, arguments);
|
|
53092
54090
|
};
|
|
53093
54091
|
}();
|
|
53094
54092
|
return timer = setInterval(runCheck, faceCheckTimer || 2e3), timer;
|
|
53095
54093
|
}, publishStream = function() {
|
|
53096
|
-
var
|
|
54094
|
+
var _ref9 = _asyncToGenerator((function*(stream) {
|
|
53097
54095
|
try {
|
|
53098
54096
|
let startTime = Date.now(), publish = yield customer.publish(stream);
|
|
53099
54097
|
setCustomerStreamId(publish.id);
|
|
@@ -53128,14 +54126,14 @@ function IndexWidget({customer, options}) {
|
|
|
53128
54126
|
}
|
|
53129
54127
|
}));
|
|
53130
54128
|
return function(_x5) {
|
|
53131
|
-
return
|
|
54129
|
+
return _ref9.apply(this, arguments);
|
|
53132
54130
|
};
|
|
53133
54131
|
}();
|
|
53134
54132
|
reactExports.useEffect((() => (isUnmountedRef.current = !1, reportLog('component_mount', 'info', 'info', {
|
|
53135
54133
|
phase: 'init'
|
|
53136
54134
|
}), joinRoom(), () => {
|
|
53137
|
-
isUnmountedRef.current = !0,
|
|
53138
|
-
isAnsweringRef.current = !1;
|
|
54135
|
+
isUnmountedRef.current = !0, clearTimeout(recordFailureTimerRef.current), cancelRealtimeAsr(),
|
|
54136
|
+
clearAsrTimers(), isAwaitingAnswerRef.current = !1, isAnsweringRef.current = !1;
|
|
53139
54137
|
})), []), reactExports.useEffect((() => {
|
|
53140
54138
|
frameRateThresholdRef.current = frameRateThreshold;
|
|
53141
54139
|
}), [ frameRateThreshold ]), reactExports.useEffect((() => {
|
|
@@ -53207,18 +54205,6 @@ function IndexWidget({customer, options}) {
|
|
|
53207
54205
|
setShowExitDialog(!1), sessionEnd(reason, errorInfo);
|
|
53208
54206
|
};
|
|
53209
54207
|
return reactExports.useEffect((() => {
|
|
53210
|
-
function adjustSVGSize() {
|
|
53211
|
-
const svgOverlay = svgOverlayRef.current;
|
|
53212
|
-
if (!svgOverlay) {
|
|
53213
|
-
return;
|
|
53214
|
-
}
|
|
53215
|
-
const screenWidth = window.innerWidth, screenHeight = window.innerHeight;
|
|
53216
|
-
screenWidth / screenHeight < .4602510460251046 ? (svgOverlay.style.width = .4602510460251046 * screenHeight + 'px',
|
|
53217
|
-
svgOverlay.style.height = '100vh', svgOverlay.style.left = '50%', svgOverlay.style.transform = 'translateX(-50%)') : (svgOverlay.style.width = '100%',
|
|
53218
|
-
svgOverlay.style.height = 'auto', svgOverlay.style.left = '0', svgOverlay.style.transform = 'none');
|
|
53219
|
-
}
|
|
53220
|
-
return adjustSVGSize(), window.addEventListener('resize', adjustSVGSize), () => window.removeEventListener('resize', adjustSVGSize);
|
|
53221
|
-
}), []), reactExports.useEffect((() => {
|
|
53222
54208
|
console.log('h5ExtraData', h5ExtraData, authorization, apiUrl);
|
|
53223
54209
|
let sdk = new CpeProductsCicSDK;
|
|
53224
54210
|
h5ExtraData && sdk.init({
|
|
@@ -53480,8 +54466,12 @@ function IndexWidget({customer, options}) {
|
|
|
53480
54466
|
}
|
|
53481
54467
|
}), React.createElement(RecordFaceCheckFailToast, {
|
|
53482
54468
|
visible: showRecordFaceCheckFailToast,
|
|
54469
|
+
failureType: recordFailureType,
|
|
54470
|
+
onTransfer: () => {
|
|
54471
|
+
setShowRecordFaceCheckFailToast(!1), sessionEnd(FACE_CHECK_TRANSFER_REASON);
|
|
54472
|
+
},
|
|
53483
54473
|
onConfirm: () => {
|
|
53484
|
-
setShowRecordFaceCheckFailToast(!1), sessionEnd('face-check-fail');
|
|
54474
|
+
setShowRecordFaceCheckFailToast(!1), sessionEnd('answer' === recordFailureType ? 'answer-fail' : 'face-check-fail');
|
|
53485
54475
|
}
|
|
53486
54476
|
}), React.createElement('video', {
|
|
53487
54477
|
controls: !1,
|
|
@@ -53501,10 +54491,9 @@ function IndexWidget({customer, options}) {
|
|
|
53501
54491
|
}
|
|
53502
54492
|
}), React.createElement('svg', {
|
|
53503
54493
|
id: 'svgOverlay',
|
|
53504
|
-
ref: svgOverlayRef,
|
|
53505
54494
|
className: 'svg-overlay',
|
|
53506
54495
|
viewBox: '0 0 440 956',
|
|
53507
|
-
preserveAspectRatio: '
|
|
54496
|
+
preserveAspectRatio: 'xMidYMin slice',
|
|
53508
54497
|
fill: 'none',
|
|
53509
54498
|
xmlns: 'http://www.w3.org/2000/svg'
|
|
53510
54499
|
}, React.createElement('g', {
|
|
@@ -53581,7 +54570,7 @@ function IndexWidget({customer, options}) {
|
|
|
53581
54570
|
showCompareResultTip: hasCompareResultFailed,
|
|
53582
54571
|
isNoFace
|
|
53583
54572
|
}), React.createElement('div', {
|
|
53584
|
-
className: 'customer-widget-bottom-container'
|
|
54573
|
+
className: 'customer-widget-bottom-container' + (asrText || showWaitView ? ' customer-widget-bottom-container-asr' : '')
|
|
53585
54574
|
}, React.createElement('div', {
|
|
53586
54575
|
className: 'customer-widget-bottom-content'
|
|
53587
54576
|
}, subtitle && React.createElement('div', {
|
|
@@ -53662,7 +54651,8 @@ class CustomerComponent extends EventTarget {
|
|
|
53662
54651
|
this.disconnectedParticipantId = null;
|
|
53663
54652
|
}
|
|
53664
54653
|
init(id, options) {
|
|
53665
|
-
console.log('init', id, options),
|
|
54654
|
+
getAsrConfig(null == options ? void 0 : options.asrConfig, !0), console.log('init', id, redactRealtimeAsrOptions(options)),
|
|
54655
|
+
this.traceReporter = createBusinessTraceReporter({
|
|
53666
54656
|
logServiceUrl: null == options ? void 0 : options.logServiceUrl,
|
|
53667
54657
|
requestNo: null == options ? void 0 : options.request_no,
|
|
53668
54658
|
roomToken: null == options ? void 0 : options.roomToken,
|
|
@@ -53691,7 +54681,10 @@ class CustomerComponent extends EventTarget {
|
|
|
53691
54681
|
}
|
|
53692
54682
|
}
|
|
53693
54683
|
destroy() {
|
|
53694
|
-
|
|
54684
|
+
if (this.destroyed) {
|
|
54685
|
+
return;
|
|
54686
|
+
}
|
|
54687
|
+
this.destroyed = !0, this.participantReconnectTimer && (clearTimeout(this.participantReconnectTimer),
|
|
53695
54688
|
this.participantReconnectTimer = null), this.Customer.destroy(), ReactDOM.unmountComponentAtNode(this.container);
|
|
53696
54689
|
const customerDiv = document.getElementById('customer-component-container-id');
|
|
53697
54690
|
customerDiv && customerDiv.parentNode && customerDiv.parentNode.removeChild(customerDiv);
|
|
@@ -53752,10 +54745,11 @@ class CustomerComponent extends EventTarget {
|
|
|
53752
54745
|
handleEvent(customEvent);
|
|
53753
54746
|
}), 1e3 * this.reconnectWaitTime));
|
|
53754
54747
|
}, handleEvent = (event, isForceQuit = !1) => {
|
|
53755
|
-
isForceQuit && !this.callbackCalled && callback && (clearReconnectWaitTimer(),
|
|
53756
|
-
|
|
54748
|
+
(this.Customer.sessionEndReason !== FACE_CHECK_TRANSFER_REASON || isForceQuit) && (isForceQuit && !this.callbackCalled && callback && (clearReconnectWaitTimer(),
|
|
54749
|
+
reportOnEndCallback(event, isForceQuit), this.callbackCalled = !0, callback(event),
|
|
54750
|
+
callback = null), this.callbackCalled || !callback || this.isTransfer || (clearReconnectWaitTimer(),
|
|
53757
54751
|
reportOnEndCallback(event, isForceQuit), this.callbackCalled = !0, callback(event),
|
|
53758
|
-
callback = null);
|
|
54752
|
+
callback = null));
|
|
53759
54753
|
};
|
|
53760
54754
|
handleEvent.bind(this), this.Customer.onJoinRoomError(handleEvent), this.Customer.onPublishEndCallback(handleEvent);
|
|
53761
54755
|
const handleAgentEvent = event => {
|
|
@@ -53775,7 +54769,7 @@ class CustomerComponent extends EventTarget {
|
|
|
53775
54769
|
isCurrentActiveParticipant(e) ? (console.log('当前活跃对方重连,清除重连等待:', e), clearReconnectWaitTimer()) : console.log('非当前活跃对方重连,忽略:', e);
|
|
53776
54770
|
})), this.Customer.onSubscribeEnd(handleAgentEvent), this.Customer.onSystemError(handleAgentEvent),
|
|
53777
54771
|
this.Customer.onParticipantLeft(handleAgentEvent), this.Customer.onCreateStreamError(handleEvent),
|
|
53778
|
-
this.Customer.onPublishStreamError(handleEvent), this.Customer.onSubscribeStreamError(
|
|
54772
|
+
this.Customer.onPublishStreamError(handleEvent), this.Customer.onSubscribeStreamError(handleEvent),
|
|
53779
54773
|
this.Customer.onBusinessData((data => {
|
|
53780
54774
|
if ('waitTimeout' === data.type) {
|
|
53781
54775
|
handleEvent({
|
|
@@ -53791,12 +54785,18 @@ class CustomerComponent extends EventTarget {
|
|
|
53791
54785
|
});
|
|
53792
54786
|
} else if ('quit' === data.type) {
|
|
53793
54787
|
let reason = data.reason;
|
|
53794
|
-
|
|
53795
|
-
|
|
54788
|
+
const isCustomerTransfer = reason === FACE_CHECK_TRANSFER_REASON;
|
|
54789
|
+
let customEvent = {
|
|
54790
|
+
code: isCustomerTransfer ? CUSTOMER_FACE_CHECK_TRANSFER_CODE : 'self-help-video' === reason ? '401' : '400',
|
|
53796
54791
|
type: 'quit',
|
|
53797
|
-
message: '用户主动离开',
|
|
54792
|
+
message: isCustomerTransfer ? '客户点击转接专属客服(转人工)' : '用户主动离开',
|
|
53798
54793
|
reason
|
|
53799
|
-
}
|
|
54794
|
+
};
|
|
54795
|
+
try {
|
|
54796
|
+
handleEvent(customEvent, !0);
|
|
54797
|
+
} finally {
|
|
54798
|
+
isCustomerTransfer && this.destroy();
|
|
54799
|
+
}
|
|
53800
54800
|
}
|
|
53801
54801
|
})), this.Customer.onMessageReceived((e => {
|
|
53802
54802
|
if (e.message) {
|