@crh-fe/oava-customer-sdk 1.0.56 → 1.0.58

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.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  /*
3
- * Version: 1.0.56
4
- * Build Time: 2026/11/02 16:20:40
3
+ * Version: 1.0.58
4
+ * Build Time: 2026/11/25 16:18:14
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), this.client.destroy(),
21999
- this.localStream && this.client.stopStream(this.localStream), this.client.leaveRoom();
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,561 @@ 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:100vh;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-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}.svg-overlay{height:100vh;left:0;pointer-events:none;position:absolute;top:0;width:100vw;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}';
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//85244IFjn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udvKAcR+hmTIFBW0VWl21WQVRlD7RemI4nwmJl+wTKop4Dmb8DLQCaOKnb6sfQK6ZfToqwILQWAnWd+q2WSc3vi5hD0ecKQQjBLsGPf/xjWb91/NaE4eHhkIXw0Ucf0dzcXHe7DRVq3Vimp5RowF41Rdb1dfUSaxiz6XgxKpPtvBsNxMZtEUClrw+2BrjVgIOFth7H4tz584G/2u7uLj1YWJDfKrOzs/TTn/6U3n//fbp06RIBAPINCwBXfO5DxC5BrQGJ/w+MiQFWh1rnOgAAAABJRU5ErkJggg==';
22018
22033
 
22034
+ class Pcm16Encoder {
22035
+ constructor(inputRate, outputRate = 16e3) {
22036
+ if (!(inputRate > 0 && outputRate > 0)) {
22037
+ throw new Error('无效的采样率');
22038
+ }
22039
+ this.ratio = inputRate / outputRate, this.remaining = this.ratio, this.sum = 0;
22040
+ }
22041
+ push(samples) {
22042
+ const output = [];
22043
+ for (const value of samples) {
22044
+ let available = 1;
22045
+ const sample = Number.isFinite(value) ? Math.max(-1, Math.min(1, value)) : 0;
22046
+ for (;available > 1e-9; ) {
22047
+ const weight = Math.min(available, this.remaining);
22048
+ this.sum += sample * weight, this.remaining -= weight, available -= weight, this.remaining < 1e-9 && (output.push(this.sum / this.ratio),
22049
+ this.sum = 0, this.remaining = this.ratio);
22050
+ }
22051
+ }
22052
+ return this.encode(output);
22053
+ }
22054
+ flush() {
22055
+ const weight = this.ratio - this.remaining, bytes = weight > 1e-9 ? this.encode([ this.sum / weight ]) : new Uint8Array;
22056
+ return this.sum = 0, this.remaining = this.ratio, bytes;
22057
+ }
22058
+ encode(samples) {
22059
+ const bytes = new Uint8Array(2 * samples.length), view = new DataView(bytes.buffer);
22060
+ return samples.forEach(((sample, index) => {
22061
+ view.setInt16(2 * index, Math.round(sample * (sample < 0 ? 32768 : 32767)), !0);
22062
+ })), bytes;
22063
+ }
22064
+ }
22065
+
22066
+ class ByteQueue {
22067
+ constructor() {
22068
+ this.chunks = [], this.length = 0, this.offset = 0;
22069
+ }
22070
+ push(bytes) {
22071
+ bytes.length && (this.chunks.push(bytes), this.length += bytes.length);
22072
+ }
22073
+ take(size) {
22074
+ size = Math.min(size, this.length);
22075
+ const bytes = new Uint8Array(size);
22076
+ let written = 0;
22077
+ for (;written < size; ) {
22078
+ const chunk = this.chunks[0], count = Math.min(chunk.length - this.offset, size - written);
22079
+ bytes.set(chunk.subarray(this.offset, this.offset + count), written), written += count,
22080
+ this.offset += count, this.offset === chunk.length && (this.chunks.shift(), this.offset = 0);
22081
+ }
22082
+ return this.length -= size, bytes;
22083
+ }
22084
+ clear() {
22085
+ this.chunks = [], this.length = 0, this.offset = 0;
22086
+ }
22087
+ }
22088
+
22089
+ function toBase64(bytes) {
22090
+ let binary = '';
22091
+ for (const byte of bytes) {
22092
+ binary += String.fromCharCode(byte);
22093
+ }
22094
+ return globalThis.btoa(binary);
22095
+ }
22096
+
22097
+ class Transcript {
22098
+ constructor() {
22099
+ this.segments = new Map, this.sequence = 0;
22100
+ }
22101
+ update(data) {
22102
+ const id = Number(null == data.sn ? this.sequence++ : data.sn);
22103
+ if (!Number.isFinite(id)) {
22104
+ throw new Error('无效的 IAT 结果序号');
22105
+ }
22106
+ if ('rpl' === data.pgs && Array.isArray(data.rg)) {
22107
+ for (const key of this.segments.keys()) {
22108
+ key >= Number(data.rg[0]) && key <= Number(data.rg[1]) && this.segments.delete(key);
22109
+ }
22110
+ }
22111
+ const text = (data.ws || []).map((item => {
22112
+ var _item$cw;
22113
+ 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) || '';
22114
+ })).join('');
22115
+ return this.segments.set(id, {
22116
+ id,
22117
+ text,
22118
+ final: !1
22119
+ }), this.snapshot();
22120
+ }
22121
+ snapshot() {
22122
+ const segments = [ ...this.segments.values() ].sort(((a, b) => a.id - b.id));
22123
+ return {
22124
+ text: segments.map((item => item.text)).join(''),
22125
+ finalText: segments.filter((item => item.final)).map((item => item.text)).join(''),
22126
+ interimText: segments.filter((item => !item.final)).map((item => item.text)).join(''),
22127
+ segments
22128
+ };
22129
+ }
22130
+ finalize() {
22131
+ for (const segment of this.segments.values()) {
22132
+ segment.final = !0;
22133
+ }
22134
+ return this.snapshot();
22135
+ }
22136
+ }
22137
+
22138
+ 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', XFYUN_IAT_BUSINESS = Object.freeze({
22139
+ language: 'zh_cn',
22140
+ domain: 'iat',
22141
+ ltc: 2,
22142
+ ptt: 0,
22143
+ pcm: 0,
22144
+ accent: 'mandarin',
22145
+ vad_eos: 5e3,
22146
+ dwa: 'wpgs'
22147
+ });
22148
+
22149
+ function getRealtimeAsrDuration(seconds) {
22150
+ const value = Number(seconds);
22151
+ return !Number.isFinite(value) || value <= 0 ? 5 : Math.max(1, Math.round(1e3 * Math.min(value, 10))) / 1e3;
22152
+ }
22153
+
22154
+ function getRealtimeAsrConfig(config) {
22155
+ if (null == config || !1 === config) {
22156
+ return null;
22157
+ }
22158
+ if ('object' != typeof config || Array.isArray(config)) {
22159
+ throw new Error('realtimeAsrConfig 必须是配置对象');
22160
+ }
22161
+ const type = String(config.type || '').toLowerCase();
22162
+ if ('xfyun' !== type) {
22163
+ throw new Error('realtimeAsrConfig.type 目前仅支持 xfyun');
22164
+ }
22165
+ const wsUrl = String(config.ws_url || config.wsUrl || '').trim(), appId = String(config.token || config.appId || '').trim();
22166
+ let validUrl = !1;
22167
+ try {
22168
+ const url = new URL(wsUrl);
22169
+ validUrl = [ 'wss:', 'ws:' ].includes(url.protocol) && Boolean(url.hostname);
22170
+ } catch (_) {}
22171
+ if (!validUrl) {
22172
+ throw new Error('realtimeAsrConfig.ws_url 必须是完整 WebSocket 地址');
22173
+ }
22174
+ if (!appId) {
22175
+ throw new Error('realtimeAsrConfig.token 必须填写讯飞 APPID');
22176
+ }
22177
+ return {
22178
+ type,
22179
+ wsUrl,
22180
+ appId
22181
+ };
22182
+ }
22183
+
22184
+ function getRealtimeAsrBusiness(_config, seconds) {
22185
+ return _objectSpread2(_objectSpread2({}, XFYUN_IAT_BUSINESS), {}, {
22186
+ vad_eos: 1e3 * getRealtimeAsrDuration(seconds)
22187
+ });
22188
+ }
22189
+
22190
+ function redactRealtimeAsrOptions(options) {
22191
+ return null != options && options.realtimeAsrConfig ? _objectSpread2(_objectSpread2({}, options), {}, {
22192
+ realtimeAsrConfig: _objectSpread2(_objectSpread2(_objectSpread2({}, options.realtimeAsrConfig), {}, {
22193
+ ws_url: '[redacted]',
22194
+ token: '[redacted]'
22195
+ }, options.realtimeAsrConfig.wsUrl ? {
22196
+ wsUrl: '[redacted]'
22197
+ } : {}), options.realtimeAsrConfig.appId ? {
22198
+ appId: '[redacted]'
22199
+ } : {})
22200
+ }) : options;
22201
+ }
22202
+
22203
+ const FRAME_BYTES = 1280, MAX_QUEUE_BYTES = 16e4, aborted = () => Object.assign(new Error('已取消语音识别'), {
22204
+ name: 'AbortError'
22205
+ });
22206
+
22207
+ class CompatibleEventTarget {
22208
+ constructor() {
22209
+ this.listeners = new Map;
22210
+ }
22211
+ addEventListener(type, callback, options = {}) {
22212
+ if (!callback) {
22213
+ return;
22214
+ }
22215
+ const listeners = this.listeners.get(type) || [];
22216
+ listeners.some((item => item.callback === callback)) || listeners.push({
22217
+ callback,
22218
+ once: !(!options || !options.once)
22219
+ }), this.listeners.set(type, listeners);
22220
+ }
22221
+ removeEventListener(type, callback) {
22222
+ this.listeners.set(type, (this.listeners.get(type) || []).filter((item => item.callback !== callback)));
22223
+ }
22224
+ dispatchEvent(event) {
22225
+ for (const item of [ ...this.listeners.get(event.type) || [] ]) {
22226
+ item.once && this.removeEventListener(event.type, item.callback), 'function' == typeof item.callback ? item.callback.call(this, event) : item.callback.handleEvent(event);
22227
+ }
22228
+ return !event.defaultPrevented;
22229
+ }
22230
+ }
22231
+
22232
+ const hasNativeEvents = 'function' == typeof globalThis.EventTarget && 'function' == typeof globalThis.Event, EventTargetBase = hasNativeEvents ? globalThis.EventTarget : CompatibleEventTarget;
22233
+
22234
+ class RealtimeAsrClient extends EventTargetBase {
22235
+ constructor({wsUrl, appId, mediaStream, business = {}} = {}) {
22236
+ super(), this.wsUrl = wsUrl, this.appId = appId, this.mediaStream = mediaStream,
22237
+ this.business = _objectSpread2(_objectSpread2({}, XFYUN_IAT_BUSINESS), business),
22238
+ this.state = 'idle', this.text = '', this._session = null, this._lastEnd = null;
22239
+ }
22240
+ _emit(type, detail) {
22241
+ const event = hasNativeEvents ? new globalThis.Event(type) : {
22242
+ type
22243
+ };
22244
+ Object.defineProperty(event, 'detail', {
22245
+ value: detail
22246
+ }), this.dispatchEvent(event);
22247
+ }
22248
+ _state(state) {
22249
+ this.state = state, this._emit('statechange', {
22250
+ state
22251
+ });
22252
+ }
22253
+ _check(session) {
22254
+ if (!session.active) {
22255
+ throw aborted();
22256
+ }
22257
+ }
22258
+ start() {
22259
+ var _this = this;
22260
+ return _asyncToGenerator((function*() {
22261
+ if (_this._session) {
22262
+ throw new Error('语音识别会话正在进行');
22263
+ }
22264
+ const session = {
22265
+ active: !0,
22266
+ queue: new ByteQueue,
22267
+ transcript: new Transcript,
22268
+ capturing: !1,
22269
+ draining: !1,
22270
+ endSent: !1,
22271
+ ownsStream: !_this.mediaStream,
22272
+ sentBytes: 0,
22273
+ sentFrames: 0
22274
+ };
22275
+ _this._session = session, _this._lastEnd = null, _this.text = '', _this._state('starting');
22276
+ try {
22277
+ var _globalThis$location, _globalThis$navigator;
22278
+ let url;
22279
+ _this._check(session);
22280
+ try {
22281
+ url = new URL(_this.wsUrl);
22282
+ } catch (_unused) {
22283
+ throw new Error('缺少有效的完整 ASR WebSocket 地址');
22284
+ }
22285
+ if (![ 'wss:', 'ws:' ].includes(url.protocol)) {
22286
+ throw new Error('ASR 地址必须使用 wss:// 或 ws://');
22287
+ }
22288
+ if ('https:' === (null === (_globalThis$location = globalThis.location) || void 0 === _globalThis$location ? void 0 : _globalThis$location.protocol) && 'wss:' !== url.protocol) {
22289
+ throw new Error('HTTPS 页面必须使用 wss://');
22290
+ }
22291
+ if ('string' != typeof _this.appId || !_this.appId.trim()) {
22292
+ throw new Error('缺少 ASR AppID');
22293
+ }
22294
+ const AudioContextClass = globalThis.AudioContext || globalThis.webkitAudioContext;
22295
+ if (!AudioContextClass || !globalThis.WebSocket) {
22296
+ throw new Error('浏览器不支持 Web Audio 或 WebSocket');
22297
+ }
22298
+ 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)) {
22299
+ throw new Error('无法访问麦克风,请使用 HTTPS 并检查浏览器权限');
22300
+ }
22301
+ session.context = new AudioContextClass;
22302
+ const resume = session.context.resume(), request = _this.mediaStream ? Promise.resolve(_this.mediaStream) : globalThis.navigator.mediaDevices.getUserMedia({
22303
+ audio: {
22304
+ channelCount: 1,
22305
+ echoCancellation: !0,
22306
+ noiseSuppression: !0,
22307
+ autoGainControl: !0
22308
+ },
22309
+ video: !1
22310
+ });
22311
+ yield Promise.all([ request.then((stream => {
22312
+ if (!session.active) {
22313
+ throw session.ownsStream && stream.getTracks().forEach((track => track.stop())),
22314
+ aborted();
22315
+ }
22316
+ session.stream = stream;
22317
+ })), resume ]), _this._check(session);
22318
+ const tracks = session.stream.getAudioTracks().filter((track => 'live' === track.readyState));
22319
+ if (!tracks.length) {
22320
+ throw new Error('没有可用的麦克风音轨');
22321
+ }
22322
+ return session.onTrackEnded = () => _this._fail(session, new Error('麦克风音轨已断开')),
22323
+ tracks.forEach((track => track.addEventListener('ended', session.onTrackEnded))),
22324
+ session.encoder = new Pcm16Encoder(session.context.sampleRate), yield _this._prepareCapture(session),
22325
+ _this._check(session), yield _this._connect(session, url.href, _this.appId.trim()),
22326
+ _this._check(session), session.capturing = !0, session.source = session.context.createMediaStreamSource(session.stream),
22327
+ session.silentGain = session.context.createGain(), session.silentGain.gain.value = 0,
22328
+ session.source.connect(session.processor), session.processor.connect(session.silentGain),
22329
+ session.silentGain.connect(session.context.destination), session.context.onstatechange = () => {
22330
+ session.active && 'recording' === _this.state && 'suspended' === session.context.state && _this._fail(session, new Error('音频采样已暂停,请保持页面在前台'));
22331
+ }, _this._state('recording'), _this._check(session), session.sendTimer = setInterval((() => _this._tick(session)), 40),
22332
+ !0;
22333
+ } catch (error) {
22334
+ if (!session.active) {
22335
+ if ('error' === session.reason) {
22336
+ throw session.errorCause || error;
22337
+ }
22338
+ return !1;
22339
+ }
22340
+ throw _this._fail(session, error), error;
22341
+ }
22342
+ }))();
22343
+ }
22344
+ _prepareCapture(session) {
22345
+ var _this2 = this;
22346
+ return _asyncToGenerator((function*() {
22347
+ const context = session.context, URLClass = globalThis.URL;
22348
+ if (context.audioWorklet && globalThis.AudioWorkletNode && globalThis.Blob && null != URLClass && URLClass.createObjectURL) {
22349
+ let objectUrl;
22350
+ try {
22351
+ return objectUrl = URLClass.createObjectURL(new Blob([ pcmWorkletSource ], {
22352
+ type: 'application/javascript'
22353
+ })), yield context.audioWorklet.addModule(objectUrl), _this2._check(session), session.processor = new globalThis.AudioWorkletNode(context, 'sdk-iat-pcm-capture'),
22354
+ session.worklet = !0, session.processor.port.onmessage = ({data}) => {
22355
+ var _session$captureStopp;
22356
+ 'samples' === data.type && _this2._samples(session, data.samples), 'stopped' === data.type && (null === (_session$captureStopp = session.captureStopped) || void 0 === _session$captureStopp || _session$captureStopp.call(session));
22357
+ }, void (session.processor.onprocessorerror = () => _this2._fail(session, new Error('音频处理器异常')));
22358
+ } catch (error) {
22359
+ _this2._check(session);
22360
+ } finally {
22361
+ objectUrl && URLClass.revokeObjectURL(objectUrl);
22362
+ }
22363
+ }
22364
+ if (!context.createScriptProcessor) {
22365
+ throw new Error('浏览器不支持音频采样');
22366
+ }
22367
+ session.processor = context.createScriptProcessor(1024, 1, 1), session.processor.onaudioprocess = ({inputBuffer}) => _this2._samples(session, inputBuffer.getChannelData(0));
22368
+ }))();
22369
+ }
22370
+ _samples(session, samples) {
22371
+ if (!session.active || !session.capturing || null == samples || !samples.length) {
22372
+ return;
22373
+ }
22374
+ if (session.queue.push(session.encoder.push(samples)), session.queue.length > MAX_QUEUE_BYTES) {
22375
+ return void this._fail(session, new Error('语音发送积压超过 5 秒'));
22376
+ }
22377
+ let squares = 0;
22378
+ for (let index = 0; index < samples.length; index++) {
22379
+ const sample = Number.isFinite(samples[index]) ? Math.max(-1, Math.min(1, samples[index])) : 0;
22380
+ squares += sample * sample;
22381
+ }
22382
+ const level = Math.max(0, Math.min(1, Math.sqrt(squares / samples.length)));
22383
+ this._emit('volume', {
22384
+ level
22385
+ });
22386
+ }
22387
+ _connect(session, url, appId) {
22388
+ return new Promise(((resolve, reject) => {
22389
+ let settled = !1;
22390
+ const settle = error => {
22391
+ settled || (settled = !0, clearTimeout(session.connectTimer), session.cancelConnect = null,
22392
+ error ? reject(error) : resolve());
22393
+ };
22394
+ let socket;
22395
+ session.cancelConnect = () => settle(aborted()), session.connectTimer = setTimeout((() => {
22396
+ const error = new Error('ASR WebSocket 连接超时');
22397
+ settle(error), this._fail(session, error);
22398
+ }), 1e4);
22399
+ try {
22400
+ socket = new globalThis.WebSocket(url);
22401
+ } catch (_unused2) {
22402
+ return void settle(new Error('无法创建 ASR WebSocket'));
22403
+ }
22404
+ session.socket = socket, socket.onopen = () => {
22405
+ if (session.active) {
22406
+ try {
22407
+ socket.send(JSON.stringify({
22408
+ common: {
22409
+ app_id: appId
22410
+ },
22411
+ business: _objectSpread2({}, this.business),
22412
+ data: {
22413
+ status: 0,
22414
+ format: 'audio/L16;rate=16000',
22415
+ encoding: 'raw',
22416
+ audio: ''
22417
+ }
22418
+ })), settle();
22419
+ } catch (_unused3) {
22420
+ settle(new Error('ASR 参数帧发送失败'));
22421
+ }
22422
+ }
22423
+ }, socket.onmessage = event => {
22424
+ if (session.active) {
22425
+ try {
22426
+ var _message$data, _message$data2;
22427
+ const message = JSON.parse(event.data);
22428
+ if (message.sid && (session.sid = message.sid), null != message.code && '0' !== String(message.code)) {
22429
+ const error = Object.assign(new Error(message.message || message.desc || 'ASR 服务返回错误'), {
22430
+ code: message.code,
22431
+ sid: message.sid
22432
+ });
22433
+ return settle(error), void this._fail(session, error);
22434
+ }
22435
+ null !== (_message$data = message.data) && void 0 !== _message$data && _message$data.result && this._result(session, session.transcript.update(message.data.result)),
22436
+ 2 === Number(null === (_message$data2 = message.data) || void 0 === _message$data2 ? void 0 : _message$data2.status) && (this._result(session, session.transcript.finalize()),
22437
+ settle(), this._finish(session, 'final'));
22438
+ } catch (_unused4) {
22439
+ const error = new Error('无法解析 ASR 服务消息');
22440
+ settle(error), this._fail(session, error);
22441
+ }
22442
+ }
22443
+ }, socket.onerror = () => {
22444
+ const error = new Error('ASR WebSocket 连接异常,请检查签名、网络和服务授权');
22445
+ settle(error), this._fail(session, error);
22446
+ }, socket.onclose = event => {
22447
+ if (!session.active) {
22448
+ return;
22449
+ }
22450
+ const error = new Error(`ASR WebSocket 已断开,未收到最终结果(${event.code})`);
22451
+ settle(error), this._finish(session, 'closed', error);
22452
+ };
22453
+ }));
22454
+ }
22455
+ _result(session, result) {
22456
+ session.active && result && (this.text = result.text, this._emit('result', result));
22457
+ }
22458
+ _tick(session) {
22459
+ if (!session.active || session.endSent) {
22460
+ return;
22461
+ }
22462
+ const socket = session.socket;
22463
+ if (1 === (null == socket ? void 0 : socket.readyState)) {
22464
+ if (socket.bufferedAmount > MAX_QUEUE_BYTES) {
22465
+ this._fail(session, new Error('ASR 网络发送缓冲积压超过 5 秒'));
22466
+ } else if (!(socket.bufferedAmount > 4 * FRAME_BYTES)) {
22467
+ try {
22468
+ if (session.queue.length >= FRAME_BYTES || session.draining && session.queue.length) {
22469
+ const bytes = session.queue.take(FRAME_BYTES);
22470
+ socket.send(JSON.stringify({
22471
+ data: {
22472
+ status: 1,
22473
+ format: 'audio/L16;rate=16000',
22474
+ encoding: 'raw',
22475
+ audio: toBase64(bytes)
22476
+ }
22477
+ })), session.sentFrames++, session.sentBytes += bytes.length;
22478
+ } else {
22479
+ session.draining && (socket.send(JSON.stringify({
22480
+ data: {
22481
+ status: 2,
22482
+ format: 'audio/L16;rate=16000',
22483
+ encoding: 'raw',
22484
+ audio: ''
22485
+ }
22486
+ })), session.endSent = !0, clearInterval(session.sendTimer), session.finalTimer = setTimeout((() => this._fail(session, new Error('等待 ASR 最终结果超时'))), 1e4));
22487
+ }
22488
+ } catch (_unused5) {
22489
+ this._fail(session, new Error('ASR 音频发送失败'));
22490
+ }
22491
+ }
22492
+ }
22493
+ }
22494
+ stop() {
22495
+ const session = this._session;
22496
+ return session ? session.stopPromise ? session.stopPromise : 'starting' === this.state ? Promise.resolve(this._finish(session, 'cancelled')) : (session.stopPromise = new Promise((resolve => {
22497
+ session.resolveStop = resolve;
22498
+ })), this._state('stopping'), session.active && this._stopCapture(session).catch((error => this._fail(session, error))),
22499
+ session.stopPromise) : Promise.resolve(this._lastEnd);
22500
+ }
22501
+ _stopCapture(session) {
22502
+ var _this3 = this;
22503
+ return _asyncToGenerator((function*() {
22504
+ var _session$source;
22505
+ null === (_session$source = session.source) || void 0 === _session$source || _session$source.disconnect(),
22506
+ session.worklet && (yield new Promise(((resolve, reject) => {
22507
+ session.captureStopped = resolve, session.captureStopTimer = setTimeout((() => reject(new Error('ASR 音频处理器收尾超时'))), 1e3),
22508
+ session.processor.port.postMessage('stop');
22509
+ })), clearTimeout(session.captureStopTimer)), session.active && (session.capturing = !1,
22510
+ session.queue.push(session.encoder.flush()), _this3._releaseAudio(session), _this3._emit('capturestop', {
22511
+ text: _this3.text
22512
+ }), session.active && (session.draining = !0, session.drainTimer = setTimeout((() => {
22513
+ session.endSent || _this3._fail(session, new Error('ASR 结束音频发送超时'));
22514
+ }), 7e3)));
22515
+ }))();
22516
+ }
22517
+ _releaseAudio(session) {
22518
+ if (session.audioReleased) {
22519
+ return;
22520
+ }
22521
+ session.audioReleased = !0;
22522
+ const disconnect = node => {
22523
+ try {
22524
+ null == node || node.disconnect();
22525
+ } catch (_unused6) {}
22526
+ };
22527
+ if (disconnect(session.source), disconnect(session.processor), disconnect(session.silentGain),
22528
+ session.processor && (session.processor.onaudioprocess = null, session.processor.onprocessorerror = null,
22529
+ session.worklet && (session.processor.port.onmessage = null, session.processor.port.close())),
22530
+ session.stream && (session.stream.getAudioTracks().forEach((track => track.removeEventListener('ended', session.onTrackEnded))),
22531
+ session.ownsStream && session.stream.getTracks().forEach((track => track.stop()))),
22532
+ session.context && 'closed' !== session.context.state) {
22533
+ session.context.onstatechange = null;
22534
+ try {
22535
+ Promise.resolve(session.context.close()).catch((() => {}));
22536
+ } catch (_unused7) {}
22537
+ }
22538
+ }
22539
+ _finish(session, reason, error) {
22540
+ var _session$cancelConnec, _session$captureStopp2, _session$resolveStop;
22541
+ if (!session.active) {
22542
+ return session.endDetail;
22543
+ }
22544
+ if (session.active = !1, session.capturing = !1, session.reason = reason, session.errorCause = error,
22545
+ null === (_session$cancelConnec = session.cancelConnect) || void 0 === _session$cancelConnec || _session$cancelConnec.call(session),
22546
+ clearInterval(session.sendTimer), [ 'connectTimer', 'finalTimer', 'drainTimer', 'captureStopTimer' ].forEach((key => clearTimeout(session[key]))),
22547
+ null === (_session$captureStopp2 = session.captureStopped) || void 0 === _session$captureStopp2 || _session$captureStopp2.call(session),
22548
+ this._releaseAudio(session), session.queue.clear(), session.socket && (session.socket.onopen = session.socket.onmessage = session.socket.onerror = session.socket.onclose = null,
22549
+ session.socket.readyState < 2)) {
22550
+ try {
22551
+ session.socket.close();
22552
+ } catch (_unused8) {}
22553
+ }
22554
+ this._session === session && (this._session = null);
22555
+ const detail = {
22556
+ text: this.text,
22557
+ reason
22558
+ };
22559
+ if (error) {
22560
+ const messages = {
22561
+ NotAllowedError: '麦克风权限被拒绝',
22562
+ NotFoundError: '未找到麦克风',
22563
+ NotReadableError: '麦克风无法读取'
22564
+ };
22565
+ detail.error = {
22566
+ message: messages[error.name] || error.message || '语音识别失败',
22567
+ code: error.code,
22568
+ sid: error.sid || session.sid
22569
+ };
22570
+ }
22571
+ return session.endDetail = detail, this._lastEnd = detail, this._state(error ? 'error' : 'idle'),
22572
+ 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),
22573
+ detail;
22574
+ }
22575
+ _fail(session, error) {
22576
+ session.active && this._finish(session, 'error', error);
22577
+ }
22578
+ destroy() {
22579
+ return this._session ? this._finish(this._session, 'cancelled') : this._lastEnd;
22580
+ }
22581
+ }
22582
+
22019
22583
  const isJsonString = str => {
22020
22584
  try {
22021
22585
  const toObj = JSON.parse(str);
@@ -22266,7 +22830,7 @@ const faceCheckRequest = (url, faceBase64, userFaceBase64) => new Promise(functi
22266
22830
  };
22267
22831
  }());
22268
22832
 
22269
- var name = '@crh-fe/oava-customer-sdk', version = '1.0.56', description = 'Customer JS SDK package for oava-widget', type = 'module', main = './dist/customerComponent.js', files = [ 'dist', 'README.md' ], publishConfig = {
22833
+ var name = '@crh-fe/oava-customer-sdk', version = '1.0.58', description = 'Customer JS SDK package for oava-widget', type = 'module', main = './dist/customerComponent.js', files = [ 'dist', 'README.md' ], publishConfig = {
22270
22834
  access: 'public'
22271
22835
  }, pkg = {
22272
22836
  name,
@@ -22306,6 +22870,7 @@ const formatDateTime = date => `${date.getFullYear()}-${String(date.getMonth() +
22306
22870
  sdkVersion: pkg.version,
22307
22871
  extra: _objectSpread2({
22308
22872
  roomTokenPresent: Boolean(roomToken),
22873
+ roomToken,
22309
22874
  maxWaitTime,
22310
22875
  faceCheckTimer: faceCheckTimer || 2e3,
22311
22876
  hasUserFaceBase64: Boolean(hasUserFaceBase64),
@@ -22479,35 +23044,32 @@ propTypes.exports = factoryWithThrowingShims();
22479
23044
 
22480
23045
  var propTypesExports = propTypes.exports, PropTypes = getDefaultExportFromCjs(propTypesExports);
22481
23046
 
22482
- const dialogStyles = '\n :host {\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 }\n *, *::before, *::after {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n }\n .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 .dialog {\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 .dialog > * {\n flex: 0 0 auto;\n }\n .dialog-content {\n margin-bottom: 24px;\n font-size: 18px;\n font-weight: 500;\n line-height: 28px;\n overflow-wrap: break-word;\n }\n .dialog-content-small {\n font-size: 15px;\n }\n 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 .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 .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', CustomerDialog = ({children, confirmText, onConfirm, cancelText, onCancel, smallText = !1}) => {
22483
- const [shadowRoot, setShadowRoot] = reactExports.useState(null), contentId = reactExports.useId();
23047
+ 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}) => {
23048
+ const [portalContainer, setPortalContainer] = reactExports.useState(null), contentId = reactExports.useId();
22484
23049
  return reactExports.useLayoutEffect((() => {
22485
23050
  const host = document.createElement('div');
22486
- host.setAttribute('data-oava-customer-dialog', '');
22487
- const root = host.attachShadow({
22488
- mode: 'open'
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'
23051
+ return host.setAttribute('data-oava-customer-dialog', ''), document.body.appendChild(host),
23052
+ setPortalContainer(host), () => host.remove();
23053
+ }), []), portalContainer ? reactDomExports.createPortal(React.createElement(React.Fragment, null, React.createElement('style', null, dialogStyles), React.createElement('div', {
23054
+ className: 'oava-customer-dialog-mask' + ('face-check-fail' === variant ? ' oava-customer-dialog-mask-face-check-fail' : '')
22493
23055
  }, React.createElement('div', {
22494
- className: 'dialog',
23056
+ className: 'oava-customer-dialog-panel' + ('face-check-fail' === variant ? ' oava-customer-dialog-face-check-fail' : ''),
22495
23057
  role: 'alertdialog',
22496
23058
  'aria-modal': 'true',
22497
23059
  'aria-label': '视频见证提示',
22498
23060
  'aria-describedby': contentId
22499
23061
  }, React.createElement('div', {
22500
23062
  id: contentId,
22501
- className: 'dialog-content' + (smallText ? ' dialog-content-small' : '')
23063
+ className: 'oava-customer-dialog-content' + (smallText ? ' oava-customer-dialog-content-small' : '')
22502
23064
  }, children), React.createElement('button', {
22503
23065
  type: 'button',
22504
- className: 'dialog-confirm',
23066
+ className: 'oava-customer-dialog-button oava-customer-dialog-confirm',
22505
23067
  onClick: onConfirm
22506
23068
  }, confirmText), cancelText && React.createElement('button', {
22507
23069
  type: 'button',
22508
- className: 'dialog-cancel',
23070
+ className: 'oava-customer-dialog-button oava-customer-dialog-cancel',
22509
23071
  onClick: onCancel
22510
- }, cancelText)))), shadowRoot) : null;
23072
+ }, cancelText)))), portalContainer) : null;
22511
23073
  }, AudioCallToast = ({onAccept, onReject, visible}) => visible ? React.createElement(CustomerDialog, {
22512
23074
  confirmText: '立即接听',
22513
23075
  onConfirm: onAccept,
@@ -22553,15 +23115,20 @@ ErrorToast.propTypes = {
22553
23115
  visible: !1
22554
23116
  };
22555
23117
 
22556
- const RecordFaceCheckFailToast = ({onConfirm, visible}) => visible ? React.createElement(CustomerDialog, {
22557
- confirmText: '确定',
22558
- onConfirm,
23118
+ const RecordFaceCheckFailToast = ({onConfirm, onTransfer, visible, failureType = 'face'}) => visible ? React.createElement(CustomerDialog, {
23119
+ confirmText: '转接专属客服',
23120
+ onConfirm: onTransfer,
23121
+ cancelText: '退出,稍后重试',
23122
+ onCancel: onConfirm,
23123
+ variant: 'face-check-fail',
22559
23124
  smallText: !0
22560
- }, '因多次未检测到人脸,视频录制失败') : null;
23125
+ }, 'answer' === failureType ? '检测到多次回答失败,是遇到问题了吗?您也可以选择专属客服服务完成视频录制' : React.createElement(React.Fragment, null, '因多次未检测到人脸,视频录制失败。', React.createElement('br', null), '可以为你转接专属客服完成视频录制')) : null;
22561
23126
 
22562
23127
  RecordFaceCheckFailToast.propTypes = {
22563
23128
  onConfirm: PropTypes.func.isRequired,
22564
- visible: PropTypes.bool.isRequired
23129
+ onTransfer: PropTypes.func.isRequired,
23130
+ visible: PropTypes.bool.isRequired,
23131
+ failureType: PropTypes.oneOf([ 'face', 'answer' ])
22565
23132
  }, RecordFaceCheckFailToast.defaultProps = {
22566
23133
  visible: !1
22567
23134
  };
@@ -52650,10 +53217,10 @@ CpeProductsCicSDK_umd.exports, function(module, exports) {
52650
53217
 
52651
53218
  var CpeProductsCicSDK_umdExports = CpeProductsCicSDK_umd.exports, CpeProductsCicSDK = getDefaultExportFromCjs(CpeProductsCicSDK_umdExports);
52652
53219
 
52653
- const SUBTITLE_REVIEW = '正在审核您的开户资料,请稍等…';
53220
+ 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
53221
 
52655
53222
  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), svgOverlayRef = reactExports.useRef(), [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);
53223
+ const {roomToken, aiServerUrl, faceCheckTimer, userFaceBase64, maxWaitTime = 180, authorization, apiUrl, logServiceUrl, request_no, isBrowserEnv = !0, showBackButton = !1, recordAnswerOnly = !1, realtimeAsrConfig} = 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), 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
53224
  reactExports.useRef(isHumanSilentAgent);
52658
53225
  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
53226
  logServiceUrl,
@@ -52684,16 +53251,187 @@ function IndexWidget({customer, options}) {
52684
53251
  }
52685
53252
  }))), audioOperationRef.current;
52686
53253
  }
52687
- }, updateAnswerAudio = answering => {
52688
- isAnsweringRef.current = answering, syncRecordingAudio();
53254
+ }, updateAnswerAudio = answering => (isAnsweringRef.current = answering, syncRecordingAudio()), getRealtimeAsrError = error => _objectSpread2({
53255
+ message: String((null == error ? void 0 : error.message) || error || '实时语音识别失败').replace(/wss?:\/\/[^\s"'<>]+/gi, '[WebSocket 地址已隐藏]').slice(0, 500)
53256
+ }, null != (null == error ? void 0 : error.code) ? {
53257
+ code: error.code
53258
+ } : {}), isCurrentRealtimeRound = round => !isUnmountedRef.current && round.active && realtimeAsrRoundRef.current === round, cancelRealtimeAsr = () => {
53259
+ var _round$client;
53260
+ const round = realtimeAsrRoundRef.current;
53261
+ round && (realtimeAsrRoundRef.current = null, round.active = !1, clearTimeout(round.deadlineTimer),
53262
+ clearTimeout(round.matchTimer), null === (_round$client = round.client) || void 0 === _round$client || _round$client.destroy());
53263
+ }, completeRealtimeAsr = (round, detail = {}) => {
53264
+ var _round$client2;
53265
+ if (!isCurrentRealtimeRound(round) || round.submitted) {
53266
+ return;
53267
+ }
53268
+ round.submitted = !0, round.active = !1, realtimeAsrRoundRef.current = null, clearTimeout(round.deadlineTimer),
53269
+ clearTimeout(round.matchTimer), clearAsrTimers(), isAwaitingAnswerRef.current = !1,
53270
+ updateAnswerAudio(!1), setShowWaitView(!1);
53271
+ const text = 'string' == typeof detail.text ? detail.text : round.text, error = detail.error || round.error, info = _objectSpread2({
53272
+ type: 'realtime-asr-result',
53273
+ roundId: round.roundId,
53274
+ questionKey: round.questionKey,
53275
+ text,
53276
+ reason: error ? 'error' : round.reason || detail.reason || 'final',
53277
+ answerType: matchAnswerResult(text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer)
53278
+ }, error ? {
53279
+ error: getRealtimeAsrError(error)
53280
+ } : {});
53281
+ console.log('[ASR] 本轮识别结束', {
53282
+ roundId: round.roundId,
53283
+ questionKey: round.questionKey,
53284
+ text,
53285
+ answerType: info.answerType,
53286
+ reason: info.reason,
53287
+ providerReason: detail.reason
53288
+ }), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
53289
+ asrResultTimerRef.current = null, setAsrText('');
53290
+ }), 1e3);
53291
+ const reportSendFailure = () => {
53292
+ reportLog('realtime_asr_result_send_fail', 'error', 'fail', {
53293
+ phase: 'business',
53294
+ roundId: round.roundId,
53295
+ questionKey: round.questionKey
53296
+ });
53297
+ };
53298
+ try {
53299
+ Promise.resolve(customer.sendMessage(JSON.stringify(info), 'all')).catch(reportSendFailure);
53300
+ } catch (_) {
53301
+ reportSendFailure();
53302
+ }
53303
+ null === (_round$client2 = round.client) || void 0 === _round$client2 || _round$client2.destroy();
53304
+ }, stopRealtimeAsr = (round, reason) => {
53305
+ if (isCurrentRealtimeRound(round) && ('timeout' === reason && (round.reason = reason,
53306
+ clearTimeout(round.deadlineTimer), clearInterval(asrCountdownTimerRef.current),
53307
+ asrCountdownTimerRef.current = null, setShowWaitView(!1)), !round.stopping)) {
53308
+ if (round.stopping = !0, round.reason = reason, console.log('[ASR] 停止采音', {
53309
+ roundId: round.roundId,
53310
+ questionKey: round.questionKey,
53311
+ text: round.text,
53312
+ reason
53313
+ }), clearTimeout(round.matchTimer), round.matchTimer = null, round.endDetail) {
53314
+ completeRealtimeAsr(round, round.endDetail);
53315
+ } else if (round.client) {
53316
+ 'starting' === round.client.state && (round.error = new Error('回答时限内未能连接实时语音识别服务'));
53317
+ try {
53318
+ Promise.resolve(round.client.stop()).catch((error => completeRealtimeAsr(round, {
53319
+ error
53320
+ })));
53321
+ } catch (error) {
53322
+ completeRealtimeAsr(round, {
53323
+ error
53324
+ });
53325
+ }
53326
+ } else {
53327
+ completeRealtimeAsr(round, {
53328
+ error: new Error('回答时限内未能启动实时语音采集')
53329
+ });
53330
+ }
53331
+ }
53332
+ }, scheduleRealtimeAsrMatch = round => {
53333
+ if (!isCurrentRealtimeRound(round) || round.stopping || round.endDetail || null != round.matchTimer) {
53334
+ return;
53335
+ }
53336
+ if (3 === matchAnswerResult(round.text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer)) {
53337
+ return;
53338
+ }
53339
+ const now = Date.now(), delay = Math.max(40, ASR_MATCH_STABLE_MS - (now - round.textChangedAt), ASR_MATCH_SILENCE_MS - (now - round.lastSpeechAt));
53340
+ round.matchTimer = setTimeout((() => {
53341
+ 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)));
53342
+ }), delay);
53343
+ }, startRealtimeAsr = (data, view) => {
53344
+ const duration = getRealtimeAsrDuration(data.durationSeconds || asrWaitTimesRef.current), round = {
53345
+ roundId: data.roundId,
53346
+ questionKey: data.questionKey,
53347
+ correctAnswer: 'string' == typeof data.correctAnswer ? data.correctAnswer : void 0,
53348
+ errorAnswer: 'string' == typeof data.errorAnswer ? data.errorAnswer : void 0,
53349
+ active: !0,
53350
+ submitted: !1,
53351
+ stopping: !1,
53352
+ text: '',
53353
+ textChangedAt: Date.now(),
53354
+ lastSpeechAt: Date.now(),
53355
+ lastAudioAt: null,
53356
+ matchTimer: null,
53357
+ deadlineAt: Date.now() + 1e3 * duration
53358
+ };
53359
+ let config;
53360
+ realtimeAsrRoundRef.current = round;
53361
+ try {
53362
+ var _customer$localStream;
53363
+ if (config = getRealtimeAsrConfig(realtimeAsrConfig), !config) {
53364
+ throw new Error('坐席已启用实时识别,但客户端未配置 realtimeAsrConfig');
53365
+ }
53366
+ if (!data.roundId || null == data.questionKey || '' === data.questionKey) {
53367
+ throw new Error('实时识别消息缺少 roundId 或 questionKey');
53368
+ }
53369
+ const stream = null === (_customer$localStream = customer.localStream) || void 0 === _customer$localStream ? void 0 : _customer$localStream.mediaStream;
53370
+ if (null == stream || !stream.getAudioTracks().some((track => 'live' === track.readyState))) {
53371
+ throw new Error('实时识别需要可用的 iRTC 本地麦克风音轨');
53372
+ }
53373
+ setShowWaitView(!0), renderCir(duration, view, (() => stopRealtimeAsr(round, 'timeout')), round.deadlineAt),
53374
+ round.deadlineTimer = setTimeout((() => stopRealtimeAsr(round, 'timeout')), 1e3 * duration),
53375
+ Promise.resolve(updateAnswerAudio(!0)).then((() => {
53376
+ if (!isCurrentRealtimeRound(round)) {
53377
+ return;
53378
+ }
53379
+ if (Date.now() >= round.deadlineAt) {
53380
+ return void stopRealtimeAsr(round, 'timeout');
53381
+ }
53382
+ const client = new RealtimeAsrClient({
53383
+ wsUrl: config.wsUrl,
53384
+ appId: config.appId,
53385
+ mediaStream: stream,
53386
+ business: getRealtimeAsrBusiness(config, duration)
53387
+ });
53388
+ round.client = client, client.addEventListener('result', (({detail}) => {
53389
+ if (!isCurrentRealtimeRound(round)) {
53390
+ return;
53391
+ }
53392
+ const text = 'string' == typeof (null == detail ? void 0 : detail.text) ? detail.text : '';
53393
+ text !== round.text && (round.textChangedAt = Date.now(), clearTimeout(round.matchTimer),
53394
+ round.matchTimer = null), round.text = text, setAsrText(round.text), scheduleRealtimeAsrMatch(round);
53395
+ })), client.addEventListener('volume', (({detail}) => {
53396
+ isCurrentRealtimeRound(round) && Number.isFinite(null == detail ? void 0 : detail.level) && (round.lastAudioAt = Date.now(),
53397
+ detail.level >= ASR_SPEECH_LEVEL && (round.lastSpeechAt = Date.now()), scheduleRealtimeAsrMatch(round));
53398
+ })), client.addEventListener('capturestop', (() => {
53399
+ isCurrentRealtimeRound(round) && updateAnswerAudio(!1);
53400
+ })), client.addEventListener('error', (({detail}) => {
53401
+ isCurrentRealtimeRound(round) && (round.error = detail);
53402
+ })), client.addEventListener('end', (({detail}) => ((round, detail = {}) => {
53403
+ if (isCurrentRealtimeRound(round)) {
53404
+ if (clearTimeout(round.matchTimer), round.matchTimer = null, round.text = 'string' == typeof detail.text ? detail.text : round.text,
53405
+ !detail.error && !round.error && 'final' === detail.reason && 3 === matchAnswerResult(round.text.replace(/[,,]/g, ''), round.correctAnswer, round.errorAnswer) && Date.now() < round.deadlineAt) {
53406
+ return round.endDetail = detail, round.stopping = !1, round.reason = null, setAsrText(round.text),
53407
+ void console.log('[ASR] 服务最终结果未命中,等待倒计时结束', {
53408
+ roundId: round.roundId,
53409
+ questionKey: round.questionKey,
53410
+ text: round.text
53411
+ });
53412
+ }
53413
+ completeRealtimeAsr(round, detail);
53414
+ }
53415
+ })(round, detail))), Promise.resolve(client.start()).catch((error => completeRealtimeAsr(round, {
53416
+ error
53417
+ })));
53418
+ })).catch((error => completeRealtimeAsr(round, {
53419
+ error
53420
+ })));
53421
+ } catch (error) {
53422
+ completeRealtimeAsr(round, {
53423
+ error
53424
+ });
53425
+ }
52689
53426
  }, resetAsrDisplay = () => {
52690
- clearAsrTimers(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1), setAsrText(''),
52691
- setShowWaitView(!1);
53427
+ cancelRealtimeAsr(), clearAsrTimers(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1),
53428
+ setAsrText(''), setShowWaitView(!1);
52692
53429
  }, updatePlaybackSubtitle = text => {
52693
53430
  resetAsrDisplay(), setSubtitle(text);
52694
- }, resetRecordFaceCheckFailState = () => {
52695
- recordFaceCheckFailCountRef.current = 0, recordFaceCheckFailReportedRef.current = !1,
52696
- setShowRecordFaceCheckFailToast(!1);
53431
+ }, resetRecordFaceCheckFailState = (preserveAnswerFailure = !1) => {
53432
+ clearTimeout(recordFailureTimerRef.current), recordFaceCheckFailCountRef.current = 0,
53433
+ recordFaceCheckFailReportedRef.current = !1, preserveAnswerFailure && answerFailureShownRef.current || (answerFailureShownRef.current = !1,
53434
+ setRecordFailureType('face'), setShowRecordFaceCheckFailToast(!1));
52697
53435
  };
52698
53436
  reactExports.useEffect((() => {
52699
53437
  isRecordingRef.current = isRecording, isRecording || (isAnsweringRef.current = !1),
@@ -52900,13 +53638,13 @@ function IndexWidget({customer, options}) {
52900
53638
  phase: 'business',
52901
53639
  recordStatus: 'end',
52902
53640
  recordId: e.recordId || ''
52903
- }), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState());
53641
+ }), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState(!0));
52904
53642
  })), customer.onRecordAddListener((e => {
52905
53643
  console.log('录制开启', e), e.recordId == recordIdRef.current && (reportLog('record_state_change', 'info', 'success', {
52906
53644
  phase: 'business',
52907
53645
  recordStatus: 'start',
52908
53646
  recordId: e.recordId || ''
52909
- }), resetRecordFaceCheckFailState(), setIsRecording(!0));
53647
+ }), resetRecordFaceCheckFailState(!0), setIsRecording(!0));
52910
53648
  })), customer.onRecordErrorListener((e => {
52911
53649
  console.log('录制错误', e, recordIdRef.current), e.recordId == recordIdRef.current && (reportLog('record_state_change', 'error', 'fail', {
52912
53650
  phase: 'business',
@@ -52914,7 +53652,7 @@ function IndexWidget({customer, options}) {
52914
53652
  recordId: e.recordId || '',
52915
53653
  errorCode: (null == e ? void 0 : e.code) || '',
52916
53654
  errorMessage: (null == e ? void 0 : e.message) || ''
52917
- }), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState());
53655
+ }), setRecordId(''), setIsRecording(!1), resetRecordFaceCheckFailState(!0));
52918
53656
  })), customer.onPublishQualityReport((event => {
52919
53657
  var _event$message;
52920
53658
  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 +53669,19 @@ function IndexWidget({customer, options}) {
52931
53669
  }
52932
53670
  }));
52933
53671
  }, sessionEnd = (reason, errorInfo) => {
52934
- console.log('%c session End', 'color: red; font-size: 20px;');
53672
+ if (sessionEndingRef.current) {
53673
+ return;
53674
+ }
53675
+ const isCustomerTransfer = reason === FACE_CHECK_TRANSFER_REASON;
53676
+ isCustomerTransfer && (sessionEndingRef.current = !0, customer.sessionEndReason = reason),
53677
+ resetAsrDisplay(), console.log('%c session End', 'color: red; font-size: 20px;');
52935
53678
  let info = {
52936
53679
  type: 'quit',
52937
53680
  extraData: 'auto-quit',
52938
53681
  reason,
52939
53682
  errorInfo
52940
53683
  };
52941
- reportLog('session_end', 'warn', 'info', {
53684
+ if (reportLog('session_end', 'warn', 'info', {
52942
53685
  phase: 'ui',
52943
53686
  reason,
52944
53687
  errorInfo: errorInfo || '',
@@ -52947,68 +53690,131 @@ function IndexWidget({customer, options}) {
52947
53690
  aiAgentStreamId: aiAgentStreamIdRef.current || ''
52948
53691
  }, {
52949
53692
  keepalive: !0
52950
- }), customer.sendMessage(JSON.stringify(info), 'all'), customer.sendBusinessData(info);
53693
+ }), isCustomerTransfer) {
53694
+ return new Promise((resolve => {
53695
+ let finished = !1;
53696
+ const finish = () => {
53697
+ if (!finished) {
53698
+ finished = !0, clearTimeout(timer);
53699
+ try {
53700
+ customer.sendBusinessData(info);
53701
+ } finally {
53702
+ customer.destroy(), resolve();
53703
+ }
53704
+ }
53705
+ }, timer = setTimeout(finish, 2e3);
53706
+ try {
53707
+ Promise.resolve(customer.sendMessage(JSON.stringify(info), 'all')).then(finish, finish);
53708
+ } catch (error) {
53709
+ finish();
53710
+ }
53711
+ }));
53712
+ }
53713
+ customer.sendMessage(JSON.stringify(info), 'all'), customer.sendBusinessData(info);
52951
53714
  }, dealWithMessage = msg => {
52952
- if (isJsonString$1(msg)) {
53715
+ if (!sessionEndingRef.current && isJsonString$1(msg)) {
52953
53716
  let data = JSON.parse(msg);
52954
- if ('text' === data.type) {
52955
- reviewTextMessageRef.current = data.message || '', setSubtitle(data.message);
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) {
53717
+ if ('answer-fail' === data.type && 'version3' === data.workflowVersion) {
53718
+ if (answerFailureShownRef.current) {
52982
53719
  return;
52983
53720
  }
52984
- isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1), clearAsrTimers();
52985
- let text = data.text || '';
52986
- setShowWaitView(!1), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
52987
- asrResultTimerRef.current = null, setAsrText('');
52988
- }), 1e3);
53721
+ answerFailureShownRef.current = !0, clearTimeout(recordFailureTimerRef.current),
53722
+ resetAsrDisplay(), setRecordFailureType('answer'), setShowRecordFaceCheckFailToast(!0);
52989
53723
  } else {
52990
- 'update-playingIndex' === data.type ? setPlayingIndexs(data.data) : 'agent-info' === data.type ? (console.log('agent-info', data),
52991
- setAgentInfo(data.message), setFrameRateThreshold(data.frameRateThreshold), setMaxFrameRateCheckCount(data.maxFrameRateCheckCount)) : 'h5-link' === data.type ? setH5ExtraData(data.extraData) : 'system-recordId' === data.type ? (console.log('data.recordId', data.recordId),
52992
- setRecordId(data.recordId), setIsRecording(!0), recordIdRef.current = data.recordId,
52993
- resetRecordFaceCheckFailState(), reportLog('record_state_change', 'info', 'success', {
52994
- phase: 'business',
52995
- recordStatus: 'start',
52996
- recordId: data.recordId || ''
52997
- })) : 'playing-audio-message' === data.type ? (reviewTextMessageRef.current = '',
52998
- updatePlaybackSubtitle(data.message)) : 'hangup-audio-call' === data.type && (setIsSilentAgentAudioMode(!1),
52999
- setShowAudioCallToast(!1));
53000
- }
53001
- }
53002
- }, renderCir = (time = 5, cirDom) => {
53724
+ if (answerFailureShownRef.current) {
53725
+ return;
53726
+ }
53727
+ if ('text' === data.type) {
53728
+ reviewTextMessageRef.current = data.message || '', setSubtitle(data.message);
53729
+ } else if ('insert-playing' === data.type) {
53730
+ reviewTextMessageRef.current = '', !isSilentAgentAudioModeRef.current && updatePlaybackSubtitle(data.data);
53731
+ } else if ('ready' === data.type) {
53732
+ console.log('ready data,playList', data.data, data.asrWaitTimes), setPlayingList(data.data),
53733
+ setIsReady(!0), setAsrWaitTimes(data.asrWaitTimes), recordFaceCheckFailThresholdRef.current = Number(data.recordFaceCheckFailThreshold || 0);
53734
+ } else if ('cmd' === data.type) {
53735
+ switch (data.cmd) {
53736
+ case 'transfer':
53737
+ realtimeAsrRoundRef.current && resetAsrDisplay(), setIsTransferring(!0);
53738
+ break;
53739
+
53740
+ case 'cancel-transfer':
53741
+ setIsTransferring(!1);
53742
+ break;
53743
+
53744
+ case 'audio-call':
53745
+ setShowAudioCallToast(!0);
53746
+ }
53747
+ } else if ('start-asr' === data.type) {
53748
+ var _data$correctAnswer, _data$errorAnswer;
53749
+ if (console.log('start-asr!'), !0 === data.realtimeAsr && data.roundId) {
53750
+ if (seenRealtimeAsrRoundsRef.current.has(data.roundId)) {
53751
+ return;
53752
+ }
53753
+ if (seenRealtimeAsrRoundsRef.current.add(data.roundId), seenRealtimeAsrRoundsRef.current.size > 100) {
53754
+ const oldest = seenRealtimeAsrRoundsRef.current.values().next().value;
53755
+ seenRealtimeAsrRoundsRef.current.delete(oldest);
53756
+ }
53757
+ }
53758
+ let view = document.getElementById('customer-widget-waitView');
53759
+ reviewTextMessageRef.current = '', resetAsrDisplay();
53760
+ const answerMaterial = playingIndexsRef.current.reduce(((last, index) => {
53761
+ const material = playingListRef.current[index];
53762
+ return !0 === (null == material ? void 0 : material.isSound) ? material : last;
53763
+ }), 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);
53764
+ console.log('[ASR] 本轮话术与答案名单', {
53765
+ roundId: data.roundId || '',
53766
+ questionKey: data.questionKey || (null == answerMaterial ? void 0 : answerMaterial.index) || '',
53767
+ question: (null == answerMaterial ? void 0 : answerMaterial.words_content) || '',
53768
+ whiteList: answerLists.whiteList,
53769
+ blackList: answerLists.blackList,
53770
+ matchRule: '完整答案相等'
53771
+ }), isAwaitingAnswerRef.current = !0, setSubtitle('请在倒计时结束前用"是"或"否"完成回复'), !0 === data.realtimeAsr ? startRealtimeAsr(data, view) : (realtimeAsrConfig && reportLog('realtime_asr_mode_mismatch', 'warn', 'info', {
53772
+ phase: 'business',
53773
+ message: '客户端配置了实时识别,坐席本轮使用离线识别'
53774
+ }), updateAnswerAudio(!0), setShowWaitView(!0), renderCir(asrWaitTimesRef.current, view));
53775
+ } else if ('cancel-realtime-asr' === data.type) {
53776
+ const round = realtimeAsrRoundRef.current;
53777
+ round && round.roundId === data.roundId && round.questionKey === data.questionKey && resetAsrDisplay();
53778
+ } else if ('answer' === data.type) {
53779
+ const round = realtimeAsrRoundRef.current;
53780
+ if ((round || data.roundId) && (!round || data.roundId !== round.roundId || data.questionKey !== round.questionKey)) {
53781
+ return;
53782
+ }
53783
+ if (!isAwaitingAnswerRef.current) {
53784
+ return;
53785
+ }
53786
+ cancelRealtimeAsr(), isAwaitingAnswerRef.current = !1, updateAnswerAudio(!1), clearAsrTimers();
53787
+ let text = data.text || '';
53788
+ setShowWaitView(!1), setAsrText(text), asrResultTimerRef.current = setTimeout((() => {
53789
+ asrResultTimerRef.current = null, setAsrText('');
53790
+ }), 1e3);
53791
+ } else {
53792
+ 'update-playingIndex' === data.type ? (realtimeAsrRoundRef.current && resetAsrDisplay(),
53793
+ Array.isArray(data.playingAiList) && (playingListRef.current = data.playingAiList,
53794
+ setPlayingList(data.playingAiList)), playingIndexsRef.current = data.data, setPlayingIndexs(data.data)) : 'agent-info' === data.type ? (console.log('agent-info', data),
53795
+ setAgentInfo(data.message), setFrameRateThreshold(data.frameRateThreshold), setMaxFrameRateCheckCount(data.maxFrameRateCheckCount)) : 'h5-link' === data.type ? setH5ExtraData(data.extraData) : 'system-recordId' === data.type ? (console.log('data.recordId', data.recordId),
53796
+ setRecordId(data.recordId), setIsRecording(!0), recordIdRef.current = data.recordId,
53797
+ resetRecordFaceCheckFailState(), reportLog('record_state_change', 'info', 'success', {
53798
+ phase: 'business',
53799
+ recordStatus: 'start',
53800
+ recordId: data.recordId || ''
53801
+ })) : 'playing-audio-message' === data.type ? (reviewTextMessageRef.current = '',
53802
+ updatePlaybackSubtitle(data.message)) : 'hangup-audio-call' === data.type && (setIsSilentAgentAudioMode(!1),
53803
+ setShowAudioCallToast(!1));
53804
+ }
53805
+ }
53806
+ }
53807
+ }, renderCir = (time = 5, cirDom, onExpired, deadlineAt) => {
53003
53808
  console.log('renderCir', time, cirDom);
53004
53809
  let totalTime = 1e3 * time;
53005
53810
  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
53811
  cirDom.innerHTML = svgHtml;
53007
53812
  const remainingTimeElement = document.getElementById('remainingTime'), progressCircle = document.getElementById('progressCircle'), perimeter = 2 * Math.PI * 24;
53008
53813
  asrCountdownTimerRef.current = setInterval((() => {
53009
- if (totalTime -= 100, totalTime <= 0) {
53010
- return updateAnswerAudio(!1), cirDom.innerHTML = '', setShowWaitView(!1), clearInterval(asrCountdownTimerRef.current),
53011
- void (asrCountdownTimerRef.current = null);
53814
+ if (totalTime = deadlineAt ? deadlineAt - Date.now() : totalTime - 100, totalTime <= 0) {
53815
+ return onExpired || updateAnswerAudio(!1), cirDom.innerHTML = '', setShowWaitView(!1),
53816
+ clearInterval(asrCountdownTimerRef.current), asrCountdownTimerRef.current = null,
53817
+ void (null == onExpired || onExpired());
53012
53818
  }
53013
53819
  const remainingSeconds = Math.ceil(totalTime / 1e3);
53014
53820
  remainingTimeElement.textContent = String(remainingSeconds).padStart(2, '0');
@@ -53022,7 +53828,7 @@ function IndexWidget({customer, options}) {
53022
53828
  var _s$data2, _s$data3;
53023
53829
  (() => {
53024
53830
  const threshold = Number(recordFaceCheckFailThresholdRef.current || 0);
53025
- if (!isRecordingRef.current || !recordIdRef.current || !threshold || threshold <= 0 || recordFaceCheckFailReportedRef.current) {
53831
+ if (!isRecordingRef.current || !recordIdRef.current || !threshold || threshold <= 0 || recordFaceCheckFailReportedRef.current || answerFailureShownRef.current) {
53026
53832
  return;
53027
53833
  }
53028
53834
  if (recordFaceCheckFailCountRef.current += 1, recordFaceCheckFailCountRef.current < threshold) {
@@ -53038,8 +53844,9 @@ function IndexWidget({customer, options}) {
53038
53844
  }
53039
53845
  };
53040
53846
  customer.sendMessage(JSON.stringify(info), 'all'), recordFaceCheckFailReportedRef.current = !0,
53041
- setTimeout((() => {
53042
- setShowRecordFaceCheckFailToast(!0);
53847
+ recordFailureTimerRef.current = setTimeout((() => {
53848
+ answerFailureShownRef.current || sessionEndingRef.current || (setRecordFailureType('face'),
53849
+ setShowRecordFaceCheckFailToast(!0));
53043
53850
  }), 1e3);
53044
53851
  })();
53045
53852
  const score = null === (_s$data2 = s.data) || void 0 === _s$data2 ? void 0 : _s$data2.score;
@@ -53134,8 +53941,8 @@ function IndexWidget({customer, options}) {
53134
53941
  reactExports.useEffect((() => (isUnmountedRef.current = !1, reportLog('component_mount', 'info', 'info', {
53135
53942
  phase: 'init'
53136
53943
  }), joinRoom(), () => {
53137
- isUnmountedRef.current = !0, clearAsrTimers(), isAwaitingAnswerRef.current = !1,
53138
- isAnsweringRef.current = !1;
53944
+ isUnmountedRef.current = !0, clearTimeout(recordFailureTimerRef.current), cancelRealtimeAsr(),
53945
+ clearAsrTimers(), isAwaitingAnswerRef.current = !1, isAnsweringRef.current = !1;
53139
53946
  })), []), reactExports.useEffect((() => {
53140
53947
  frameRateThresholdRef.current = frameRateThreshold;
53141
53948
  }), [ frameRateThreshold ]), reactExports.useEffect((() => {
@@ -53207,18 +54014,6 @@ function IndexWidget({customer, options}) {
53207
54014
  setShowExitDialog(!1), sessionEnd(reason, errorInfo);
53208
54015
  };
53209
54016
  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
54017
  console.log('h5ExtraData', h5ExtraData, authorization, apiUrl);
53223
54018
  let sdk = new CpeProductsCicSDK;
53224
54019
  h5ExtraData && sdk.init({
@@ -53480,8 +54275,12 @@ function IndexWidget({customer, options}) {
53480
54275
  }
53481
54276
  }), React.createElement(RecordFaceCheckFailToast, {
53482
54277
  visible: showRecordFaceCheckFailToast,
54278
+ failureType: recordFailureType,
54279
+ onTransfer: () => {
54280
+ setShowRecordFaceCheckFailToast(!1), sessionEnd(FACE_CHECK_TRANSFER_REASON);
54281
+ },
53483
54282
  onConfirm: () => {
53484
- setShowRecordFaceCheckFailToast(!1), sessionEnd('face-check-fail');
54283
+ setShowRecordFaceCheckFailToast(!1), sessionEnd('answer' === recordFailureType ? 'answer-fail' : 'face-check-fail');
53485
54284
  }
53486
54285
  }), React.createElement('video', {
53487
54286
  controls: !1,
@@ -53501,10 +54300,9 @@ function IndexWidget({customer, options}) {
53501
54300
  }
53502
54301
  }), React.createElement('svg', {
53503
54302
  id: 'svgOverlay',
53504
- ref: svgOverlayRef,
53505
54303
  className: 'svg-overlay',
53506
54304
  viewBox: '0 0 440 956',
53507
- preserveAspectRatio: 'xMidYMid meet',
54305
+ preserveAspectRatio: 'xMidYMin slice',
53508
54306
  fill: 'none',
53509
54307
  xmlns: 'http://www.w3.org/2000/svg'
53510
54308
  }, React.createElement('g', {
@@ -53581,7 +54379,7 @@ function IndexWidget({customer, options}) {
53581
54379
  showCompareResultTip: hasCompareResultFailed,
53582
54380
  isNoFace
53583
54381
  }), React.createElement('div', {
53584
- className: 'customer-widget-bottom-container'
54382
+ className: 'customer-widget-bottom-container' + (asrText || showWaitView ? ' customer-widget-bottom-container-asr' : '')
53585
54383
  }, React.createElement('div', {
53586
54384
  className: 'customer-widget-bottom-content'
53587
54385
  }, subtitle && React.createElement('div', {
@@ -53662,7 +54460,8 @@ class CustomerComponent extends EventTarget {
53662
54460
  this.disconnectedParticipantId = null;
53663
54461
  }
53664
54462
  init(id, options) {
53665
- console.log('init', id, options), this.traceReporter = createBusinessTraceReporter({
54463
+ getRealtimeAsrConfig(null == options ? void 0 : options.realtimeAsrConfig), console.log('init', id, redactRealtimeAsrOptions(options)),
54464
+ this.traceReporter = createBusinessTraceReporter({
53666
54465
  logServiceUrl: null == options ? void 0 : options.logServiceUrl,
53667
54466
  requestNo: null == options ? void 0 : options.request_no,
53668
54467
  roomToken: null == options ? void 0 : options.roomToken,
@@ -53691,7 +54490,10 @@ class CustomerComponent extends EventTarget {
53691
54490
  }
53692
54491
  }
53693
54492
  destroy() {
53694
- this.participantReconnectTimer && (clearTimeout(this.participantReconnectTimer),
54493
+ if (this.destroyed) {
54494
+ return;
54495
+ }
54496
+ this.destroyed = !0, this.participantReconnectTimer && (clearTimeout(this.participantReconnectTimer),
53695
54497
  this.participantReconnectTimer = null), this.Customer.destroy(), ReactDOM.unmountComponentAtNode(this.container);
53696
54498
  const customerDiv = document.getElementById('customer-component-container-id');
53697
54499
  customerDiv && customerDiv.parentNode && customerDiv.parentNode.removeChild(customerDiv);
@@ -53752,10 +54554,11 @@ class CustomerComponent extends EventTarget {
53752
54554
  handleEvent(customEvent);
53753
54555
  }), 1e3 * this.reconnectWaitTime));
53754
54556
  }, handleEvent = (event, isForceQuit = !1) => {
53755
- isForceQuit && !this.callbackCalled && callback && (clearReconnectWaitTimer(), reportOnEndCallback(event, isForceQuit),
53756
- this.callbackCalled = !0, callback(event), callback = null), this.callbackCalled || !callback || this.isTransfer || (clearReconnectWaitTimer(),
54557
+ (this.Customer.sessionEndReason !== FACE_CHECK_TRANSFER_REASON || isForceQuit) && (isForceQuit && !this.callbackCalled && callback && (clearReconnectWaitTimer(),
53757
54558
  reportOnEndCallback(event, isForceQuit), this.callbackCalled = !0, callback(event),
53758
- callback = null);
54559
+ callback = null), this.callbackCalled || !callback || this.isTransfer || (clearReconnectWaitTimer(),
54560
+ reportOnEndCallback(event, isForceQuit), this.callbackCalled = !0, callback(event),
54561
+ callback = null));
53759
54562
  };
53760
54563
  handleEvent.bind(this), this.Customer.onJoinRoomError(handleEvent), this.Customer.onPublishEndCallback(handleEvent);
53761
54564
  const handleAgentEvent = event => {
@@ -53775,7 +54578,7 @@ class CustomerComponent extends EventTarget {
53775
54578
  isCurrentActiveParticipant(e) ? (console.log('当前活跃对方重连,清除重连等待:', e), clearReconnectWaitTimer()) : console.log('非当前活跃对方重连,忽略:', e);
53776
54579
  })), this.Customer.onSubscribeEnd(handleAgentEvent), this.Customer.onSystemError(handleAgentEvent),
53777
54580
  this.Customer.onParticipantLeft(handleAgentEvent), this.Customer.onCreateStreamError(handleEvent),
53778
- this.Customer.onPublishStreamError(handleEvent), this.Customer.onSubscribeStreamError(handleAgentEvent),
54581
+ this.Customer.onPublishStreamError(handleEvent), this.Customer.onSubscribeStreamError(handleEvent),
53779
54582
  this.Customer.onBusinessData((data => {
53780
54583
  if ('waitTimeout' === data.type) {
53781
54584
  handleEvent({
@@ -53791,12 +54594,18 @@ class CustomerComponent extends EventTarget {
53791
54594
  });
53792
54595
  } else if ('quit' === data.type) {
53793
54596
  let reason = data.reason;
53794
- handleEvent({
53795
- code: 'self-help-video' === reason ? '401' : '400',
54597
+ const isCustomerTransfer = reason === FACE_CHECK_TRANSFER_REASON;
54598
+ let customEvent = {
54599
+ code: isCustomerTransfer ? CUSTOMER_FACE_CHECK_TRANSFER_CODE : 'self-help-video' === reason ? '401' : '400',
53796
54600
  type: 'quit',
53797
- message: '用户主动离开',
54601
+ message: isCustomerTransfer ? '客户点击转接专属客服(转人工)' : '用户主动离开',
53798
54602
  reason
53799
- }, !0);
54603
+ };
54604
+ try {
54605
+ handleEvent(customEvent, !0);
54606
+ } finally {
54607
+ isCustomerTransfer && this.destroy();
54608
+ }
53800
54609
  }
53801
54610
  })), this.Customer.onMessageReceived((e => {
53802
54611
  if (e.message) {