ysyt-agent-sdk 1.0.74 → 1.0.75

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.
@@ -28,6 +28,34 @@ export declare class SIPClient {
28
28
  private handleOnline;
29
29
  /**
30
30
  * 启动 SIP 客户端(创建 userAgent 实例、注册)
31
+ * 字段 说明
32
+ * allowLegacyNotifications 是否允许接收 会话外的 NOTIFY 请求。RFC 6665 废弃了这种用法,默认 false。
33
+ * authorizationHa1 直接提供 Digest 认证的 HA1 值(用户名、域、密码的哈希)。
34
+ * authorizationPassword 认证密码(常用)。
35
+ * authorizationUsername 认证用户名(常用)。
36
+ * contactName Contact URI 里 user 部分(如果不填会随机生成)。
37
+ * contactParams Contact URI 的参数,默认 { transport: "ws" }。
38
+ * delegate 事件回调接口,例如处理来电、消息等。
39
+ * displayName From 头里的显示名称(对方看到的主叫名称)。
40
+ * forceRport 是否强制在 Via 头加 rport 参数。
41
+ * gracefulShutdown stop() 时是否优雅断开,结束所有注册和对话。
42
+ * hackIpInContact 过时参数,用来强行修改 Contact 里的 IP。
43
+ * instanceId "+sip.instance" Contact 参数值,默认随机 UUID。
44
+ * instanceIdAlwaysAdded 是否强制在所有请求 Contact 里加 "+sip.instance" 参数。
45
+ * logBuiltinEnabled 是否允许写日志到控制台。
46
+ * logConfiguration 是否打印 UA 配置。
47
+ * logLevel 日志级别(log/debug/warn/error)。
48
+ * noAnswerTimeout 呼叫未接听的超时时间(秒)。
49
+ * preloadedRouteSet 给所有请求预先加上 Route 头(数组)。
50
+ * sendInitialProvisionalResponse 对于呼入 INVITE,是否自动发送 180 Ringing 等临时响应。
51
+ * sipExtension100rel 是否支持 100rel(可靠临时响应)。
52
+ * sipExtensionReplaces 是否支持 Replaces 头(呼叫替换)。
53
+ * sipExtensionExtraSupported 手动添加 Supported 头里的额外扩展标签。
54
+ * transportConstructor 自定义 Transport 构造函数,默认 WebSocketTransport。
55
+ * transportOptions 传给 transport 的参数(如 ws/wss URL)。
56
+ * uri UA 的地址(通常是 sip:xxx@domain)。
57
+ * userAgentString User-Agent 头部的值。
58
+ * viaHost Via 头里的 host 值,默认随机生成。
31
59
  */
32
60
  start(): Promise<void>;
33
61
  /**
@@ -9,7 +9,7 @@
9
9
  * @copyright Chen, Yi-Cyuan 2014-2023
10
10
  * @license MIT
11
11
  */
12
- Ze=Oe,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var r=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Ke:r&&(i=self);var n,a=!i.JS_MD5_NO_COMMON_JS&&Ze.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],l=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var p=new ArrayBuffer(68);n=new Uint8Array(p),d=new Uint32Array(p)}var u=Array.isArray;!i.JS_MD5_NO_NODE_JS&&u||(u=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!u(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var r,o=A,n=e.Buffer;return r=n.from&&!i.JS_MD5_NO_BUFFER_FROM?n.from:function(A){return new n(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),u(A)||m(A)||A.constructor===n?o.createHash("md5").update(r(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=n;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,r=[],o=A.length,n=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?r[n++]=i:i<2048?(r[n++]=192|i>>>6,r[n++]=128|63&i):i<55296||i>=57344?(r[n++]=224|i>>>12,r[n++]=128|i>>>6&63,r[n++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[n++]=240|i>>>18,r[n++]=128|i>>>12&63,r[n++]=128|i>>>6&63,r[n++]=128|63&i);A=r}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],r=0,o=A.length,n=this.blocks,a=this.buffer8;r<o;){if(this.hashed&&(this.hashed=!1,n[0]=n[16],n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),i)if(V)for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?n[s>>>2]|=t<<l[3&s++]:t<2048?(n[s>>>2]|=(192|t>>>6)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):t<55296||t>=57344?(n[s>>>2]|=(224|t>>>12)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),n[s>>>2]|=(240|t>>>18)<<l[3&s++],n[s>>>2]|=(128|t>>>12&63)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]);else if(V)for(s=this.start;r<o&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<o&&s<64;++r)n[s>>>2]|=A[r]<<l[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,r,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[r],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?Ze.exports=B:i.md5=B}();var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return ve.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends $A{updateRttObject(A){this.setState({rttObject:A}),ae.emit(exports.EventName.WEBSITE_DELAY,A)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=_A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:Ve.logBuiltinEnabled};this.userAgent=new _A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(A=>{let e;switch(A){case AA.Connecting:e=exports.WebRtcCallSipEventEnum.WEB_RTC_CONNECTING;break;case AA.Connected:e=exports.WebRtcCallSipEventEnum.WEB_RTC_CONNECTED,this.reconnectAttempts=0,Ve.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case AA.Disconnecting:e=exports.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTING;break;case AA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");e=exports.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTED;const A=he.get("answerDevice");if(!Ve.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===A){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:e="unknown"}this.eventCallback?.({type:e})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new rA(this.userAgent),this.registerer?.stateChange.addListener(A=>{let e;switch(A){case _.Initial:e="initial";break;case _.Registered:e=exports.WebRtcCallSipEventEnum.WEB_RTC_REGISTERED;break;case _.Unregistered:e=exports.WebRtcCallSipEventEnum.WEB_RTC_UNREGISTERED;break;case _.Terminated:e=exports.WebRtcCallSipEventEnum.WEB_RTC_TERMINATED;break;default:e="unknown"}this.eventCallback?.({type:e})});try{await this.registerer.register()}catch(A){this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_REGISTER_FAILED,data:A})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case j.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case j.Terminating:break;case j.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case j.Establishing:}})}handleIncomingCall(A){this.incomingInvitation=A,this.handleSessionState(A,!1);const{soft_device_auto_answer:e,auto_answer_time:t}=Ve.agentInfo,s=he.get("direction"),i=1===e;if(s===exports.DirectionEnum.OUTGOING)this.answerCall();else if(i&&s===exports.DirectionEnum.INCOMING){const A=Number(t)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(A){this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_ANSWER_FAILED,data:{detail:A}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,he.updateDirection(null),he.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(A){if(!this.activeSession)throw new Error("当前没有活跃的通话");const e=this.activeSession.sessionDescriptionHandler;e&&"function"==typeof e.sendDtmf?(e.sendDtmf(A),this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_SEND_DTMF,data:{tone:A}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===j.Established?await A.bye():e===j.Establishing&&(A instanceof X?await A.cancel():A instanceof z&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof z&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!Ve.isRtcReconnecting){Ve.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{Ve.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
12
+ Ze=Oe,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var r=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Ke:r&&(i=self);var n,a=!i.JS_MD5_NO_COMMON_JS&&Ze.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],l=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var p=new ArrayBuffer(68);n=new Uint8Array(p),d=new Uint32Array(p)}var u=Array.isArray;!i.JS_MD5_NO_NODE_JS&&u||(u=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!u(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var r,o=A,n=e.Buffer;return r=n.from&&!i.JS_MD5_NO_BUFFER_FROM?n.from:function(A){return new n(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),u(A)||m(A)||A.constructor===n?o.createHash("md5").update(r(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=n;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,r=[],o=A.length,n=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?r[n++]=i:i<2048?(r[n++]=192|i>>>6,r[n++]=128|63&i):i<55296||i>=57344?(r[n++]=224|i>>>12,r[n++]=128|i>>>6&63,r[n++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[n++]=240|i>>>18,r[n++]=128|i>>>12&63,r[n++]=128|i>>>6&63,r[n++]=128|63&i);A=r}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],r=0,o=A.length,n=this.blocks,a=this.buffer8;r<o;){if(this.hashed&&(this.hashed=!1,n[0]=n[16],n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),i)if(V)for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?n[s>>>2]|=t<<l[3&s++]:t<2048?(n[s>>>2]|=(192|t>>>6)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):t<55296||t>=57344?(n[s>>>2]|=(224|t>>>12)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),n[s>>>2]|=(240|t>>>18)<<l[3&s++],n[s>>>2]|=(128|t>>>12&63)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]);else if(V)for(s=this.start;r<o&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<o&&s<64;++r)n[s>>>2]|=A[r]<<l[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,r,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[r],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?Ze.exports=B:i.md5=B}();var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return ve.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends $A{updateRttObject(A){this.setState({rttObject:A}),ae.emit(exports.EventName.WEBSITE_DELAY,A)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=_A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},contactName:this.config.user,contactParams:{transport:"wss"},userAgentString:"SwiftSIP/1.0.74",sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:Ve.logBuiltinEnabled};this.userAgent=new _A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(A=>{let e;switch(A){case AA.Connecting:e=exports.WebRtcCallSipEventEnum.WEB_RTC_CONNECTING;break;case AA.Connected:e=exports.WebRtcCallSipEventEnum.WEB_RTC_CONNECTED,this.reconnectAttempts=0,Ve.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case AA.Disconnecting:e=exports.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTING;break;case AA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");e=exports.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTED;const A=he.get("answerDevice");if(!Ve.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===A){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:e="unknown"}this.eventCallback?.({type:e})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new rA(this.userAgent),this.registerer?.stateChange.addListener(A=>{let e;switch(A){case _.Initial:e="initial";break;case _.Registered:e=exports.WebRtcCallSipEventEnum.WEB_RTC_REGISTERED;break;case _.Unregistered:e=exports.WebRtcCallSipEventEnum.WEB_RTC_UNREGISTERED;break;case _.Terminated:e=exports.WebRtcCallSipEventEnum.WEB_RTC_TERMINATED;break;default:e="unknown"}this.eventCallback?.({type:e})});try{await this.registerer.register()}catch(A){this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_REGISTER_FAILED,data:A})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case j.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case j.Terminating:break;case j.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case j.Establishing:}})}handleIncomingCall(A){this.incomingInvitation=A,this.handleSessionState(A,!1);const{soft_device_auto_answer:e,auto_answer_time:t}=Ve.agentInfo,s=he.get("direction"),i=1===e;if(s===exports.DirectionEnum.OUTGOING)this.answerCall();else if(i&&s===exports.DirectionEnum.INCOMING){const A=Number(t)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(A){this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_ANSWER_FAILED,data:{detail:A}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,he.updateDirection(null),he.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(A){if(!this.activeSession)throw new Error("当前没有活跃的通话");const e=this.activeSession.sessionDescriptionHandler;e&&"function"==typeof e.sendDtmf?(e.sendDtmf(A),this.eventCallback?.({type:exports.WebRtcCallSipEventEnum.WEB_RTC_SEND_DTMF,data:{tone:A}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===j.Established?await A.bye():e===j.Establishing&&(A instanceof X?await A.cancel():A instanceof z&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof z&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!Ve.isRtcReconnecting){Ve.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{Ve.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
13
13
  /**
14
14
  * @license
15
15
  * Copyright 2019 Google LLC
@@ -9,7 +9,7 @@ import A from"crypto";import e from"buffer";class t extends Error{constructor(A)
9
9
  * @copyright Chen, Yi-Cyuan 2014-2023
10
10
  * @license MIT
11
11
  */
12
- ve=Oe,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var r=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Ke:r&&(i=self);var n,a=!i.JS_MD5_NO_COMMON_JS&&ve.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],l=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var u=new ArrayBuffer(68);n=new Uint8Array(u),d=new Uint32Array(u)}var p=Array.isArray;!i.JS_MD5_NO_NODE_JS&&p||(p=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!p(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var r,o=A,n=e.Buffer;return r=n.from&&!i.JS_MD5_NO_BUFFER_FROM?n.from:function(A){return new n(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),p(A)||m(A)||A.constructor===n?o.createHash("md5").update(r(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=n;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,r=[],o=A.length,n=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?r[n++]=i:i<2048?(r[n++]=192|i>>>6,r[n++]=128|63&i):i<55296||i>=57344?(r[n++]=224|i>>>12,r[n++]=128|i>>>6&63,r[n++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[n++]=240|i>>>18,r[n++]=128|i>>>12&63,r[n++]=128|i>>>6&63,r[n++]=128|63&i);A=r}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],r=0,o=A.length,n=this.blocks,a=this.buffer8;r<o;){if(this.hashed&&(this.hashed=!1,n[0]=n[16],n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),i)if(V)for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?n[s>>>2]|=t<<l[3&s++]:t<2048?(n[s>>>2]|=(192|t>>>6)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):t<55296||t>=57344?(n[s>>>2]|=(224|t>>>12)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),n[s>>>2]|=(240|t>>>18)<<l[3&s++],n[s>>>2]|=(128|t>>>12&63)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]);else if(V)for(s=this.start;r<o&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<o&&s<64;++r)n[s>>>2]|=A[r]<<l[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,r,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[r],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?ve.exports=B:i.md5=B}();var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return xe.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends $A{updateRttObject(A){this.setState({rttObject:A}),ae.emit(re.WEBSITE_DELAY,A)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=_A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:Ve.logBuiltinEnabled};this.userAgent=new _A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(A=>{let e;switch(A){case AA.Connecting:e=te.WEB_RTC_CONNECTING;break;case AA.Connected:e=te.WEB_RTC_CONNECTED,this.reconnectAttempts=0,Ve.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case AA.Disconnecting:e=te.WEB_RTC_DISCONNECTING;break;case AA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");e=te.WEB_RTC_DISCONNECTED;const A=he.get("answerDevice");if(!Ve.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===A){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:e="unknown"}this.eventCallback?.({type:e})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new rA(this.userAgent),this.registerer?.stateChange.addListener(A=>{let e;switch(A){case _.Initial:e="initial";break;case _.Registered:e=te.WEB_RTC_REGISTERED;break;case _.Unregistered:e=te.WEB_RTC_UNREGISTERED;break;case _.Terminated:e=te.WEB_RTC_TERMINATED;break;default:e="unknown"}this.eventCallback?.({type:e})});try{await this.registerer.register()}catch(A){this.eventCallback?.({type:te.WEB_RTC_REGISTER_FAILED,data:A})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case j.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case j.Terminating:break;case j.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case j.Establishing:}})}handleIncomingCall(A){this.incomingInvitation=A,this.handleSessionState(A,!1);const{soft_device_auto_answer:e,auto_answer_time:t}=Ve.agentInfo,s=he.get("direction"),i=1===e;if(s===ee.OUTGOING)this.answerCall();else if(i&&s===ee.INCOMING){const A=Number(t)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(A){this.eventCallback?.({type:te.WEB_RTC_ANSWER_FAILED,data:{detail:A}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,he.updateDirection(null),he.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(A){if(!this.activeSession)throw new Error("当前没有活跃的通话");const e=this.activeSession.sessionDescriptionHandler;e&&"function"==typeof e.sendDtmf?(e.sendDtmf(A),this.eventCallback?.({type:te.WEB_RTC_SEND_DTMF,data:{tone:A}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===j.Established?await A.bye():e===j.Establishing&&(A instanceof X?await A.cancel():A instanceof z&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof z&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!Ve.isRtcReconnecting){Ve.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{Ve.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
12
+ ve=Oe,function(){var t="input is invalid type",s="object"==typeof window,i=s?window:{};i.JS_MD5_NO_WINDOW&&(s=!1);var r=!s&&"object"==typeof self,o=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?i=Ke:r&&(i=self);var n,a=!i.JS_MD5_NO_COMMON_JS&&ve.exports,V=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),h=[128,32768,8388608,-2147483648],l=[0,8,16,24],g=["hex","array","digest","buffer","arrayBuffer","base64"],q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[];if(V){var u=new ArrayBuffer(68);n=new Uint8Array(u),d=new Uint32Array(u)}var p=Array.isArray;!i.JS_MD5_NO_NODE_JS&&p||(p=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var m=ArrayBuffer.isView;!V||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&m||(m=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var C=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(t);if(V&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!p(A)&&!m(A))throw new Error(t);return[A,!1]},E=function(A){return function(e){return new w(!0).update(e)[A]()}},I=function(s){var r,o=A,n=e.Buffer;return r=n.from&&!i.JS_MD5_NO_BUFFER_FROM?n.from:function(A){return new n(A)},function(A){if("string"==typeof A)return o.createHash("md5").update(A,"utf8").digest("hex");if(null==A)throw new Error(t);return A.constructor===ArrayBuffer&&(A=new Uint8Array(A)),p(A)||m(A)||A.constructor===n?o.createHash("md5").update(r(A)).digest("hex"):s(A)}},M=function(A){return function(e,t){return new f(e,!0).update(t)[A]()}};function w(A){if(A)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=n;else if(V){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function f(A,e){var t,s=C(A);if(A=s[0],s[1]){var i,r=[],o=A.length,n=0;for(t=0;t<o;++t)(i=A.charCodeAt(t))<128?r[n++]=i:i<2048?(r[n++]=192|i>>>6,r[n++]=128|63&i):i<55296||i>=57344?(r[n++]=224|i>>>12,r[n++]=128|i>>>6&63,r[n++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[n++]=240|i>>>18,r[n++]=128|i>>>12&63,r[n++]=128|i>>>6&63,r[n++]=128|63&i);A=r}A.length>64&&(A=new w(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}w.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}w.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=C(A);A=e[0];for(var t,s,i=e[1],r=0,o=A.length,n=this.blocks,a=this.buffer8;r<o;){if(this.hashed&&(this.hashed=!1,n[0]=n[16],n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),i)if(V)for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<o&&s<64;++r)(t=A.charCodeAt(r))<128?n[s>>>2]|=t<<l[3&s++]:t<2048?(n[s>>>2]|=(192|t>>>6)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):t<55296||t>=57344?(n[s>>>2]|=(224|t>>>12)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),n[s>>>2]|=(240|t>>>18)<<l[3&s++],n[s>>>2]|=(128|t>>>12&63)<<l[3&s++],n[s>>>2]|=(128|t>>>6&63)<<l[3&s++],n[s>>>2]|=(128|63&t)<<l[3&s++]);else if(V)for(s=this.start;r<o&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<o&&s<64;++r)n[s>>>2]|=A[r]<<l[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},w.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=h[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},w.prototype.hash=function(){var A,e,t,s,i,r,o=this.blocks;this.first?e=((e=((A=((A=o[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+o[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+o[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+o[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+o[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+o[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+o[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+o[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+o[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+o[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+o[10]-42063)<<17|t>>>15)+s|0)&(s^A))+o[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+o[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+o[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+o[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+o[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[1]-165796510)<<5|A>>>27)+e|0)^e))+o[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[11]+643717713)<<14|t>>>18)+s|0)^s))+o[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[5]-701558691)<<5|A>>>27)+e|0)^e))+o[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[15]-660478335)<<14|t>>>18)+s|0)^s))+o[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[9]+568446438)<<5|A>>>27)+e|0)^e))+o[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[3]-187363961)<<14|t>>>18)+s|0)^s))+o[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+o[13]-1444681467)<<5|A>>>27)+e|0)^e))+o[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+o[7]+1735328473)<<14|t>>>18)+s|0)^s))+o[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[5]-378558)<<4|A>>>28)+e|0))+o[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[11]+1839030562)<<16|t>>>16)+s|0))+o[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[1]-1530992060)<<4|A>>>28)+e|0))+o[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[7]-155497632)<<16|t>>>16)+s|0))+o[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[13]+681279174)<<4|A>>>28)+e|0))+o[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[3]-722521979)<<16|t>>>16)+s|0))+o[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+o[9]-640364487)<<4|A>>>28)+e|0))+o[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+o[15]+530742520)<<16|t>>>16)+s|0))+o[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[0]-198630844)<<6|A>>>26)+e|0)|~t))+o[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[14]-1416354905)<<15|t>>>17)+s|0)|~A))+o[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[12]+1700485571)<<6|A>>>26)+e|0)|~t))+o[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[10]-1051523)<<15|t>>>17)+s|0)|~A))+o[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[8]+1873313359)<<6|A>>>26)+e|0)|~t))+o[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[6]-1560198380)<<15|t>>>17)+s|0)|~A))+o[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+o[4]-145523070)<<6|A>>>26)+e|0)|~t))+o[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+o[2]+718787259)<<15|t>>>17)+s|0)|~A))+o[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},w.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return c[A>>>4&15]+c[15&A]+c[A>>>12&15]+c[A>>>8&15]+c[A>>>20&15]+c[A>>>16&15]+c[A>>>28&15]+c[A>>>24&15]+c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[s>>>4&15]+c[15&s]+c[s>>>12&15]+c[s>>>8&15]+c[s>>>20&15]+c[s>>>16&15]+c[s>>>28&15]+c[s>>>24&15]},w.prototype.toString=w.prototype.hex,w.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},w.prototype.array=w.prototype.digest,w.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},w.prototype.buffer=w.prototype.arrayBuffer,w.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=q[A>>>2]+q[63&(A<<4|e>>>4)]+q[63&(e<<2|t>>>6)]+q[63&t];return A=i[r],s+=q[A>>>2]+q[A<<4&63]+"=="},f.prototype=new w,f.prototype.finalize=function(){if(w.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();w.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),w.prototype.finalize.call(this)}};var B=function(){var A=E("hex");o&&(A=I(A)),A.create=function(){return new w},A.update=function(e){return A.create().update(e)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=E(t)}return A}();B.md5=B,B.md5.hmac=function(){var A=M("hex");A.create=function(A){return new f(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<g.length;++e){var t=g[e];A[t]=M(t)}return A}(),a?ve.exports=B:i.md5=B}();var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return xe.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends $A{updateRttObject(A){this.setState({rttObject:A}),ae.emit(re.WEBSITE_DELAY,A)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=_A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},contactName:this.config.user,contactParams:{transport:"wss"},userAgentString:"SwiftSIP/1.0.74",sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:Ve.logBuiltinEnabled};this.userAgent=new _A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(A=>{let e;switch(A){case AA.Connecting:e=te.WEB_RTC_CONNECTING;break;case AA.Connected:e=te.WEB_RTC_CONNECTED,this.reconnectAttempts=0,Ve.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case AA.Disconnecting:e=te.WEB_RTC_DISCONNECTING;break;case AA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");e=te.WEB_RTC_DISCONNECTED;const A=he.get("answerDevice");if(!Ve.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===A){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:e="unknown"}this.eventCallback?.({type:e})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new rA(this.userAgent),this.registerer?.stateChange.addListener(A=>{let e;switch(A){case _.Initial:e="initial";break;case _.Registered:e=te.WEB_RTC_REGISTERED;break;case _.Unregistered:e=te.WEB_RTC_UNREGISTERED;break;case _.Terminated:e=te.WEB_RTC_TERMINATED;break;default:e="unknown"}this.eventCallback?.({type:e})});try{await this.registerer.register()}catch(A){this.eventCallback?.({type:te.WEB_RTC_REGISTER_FAILED,data:A})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case j.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case j.Terminating:break;case j.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case j.Establishing:}})}handleIncomingCall(A){this.incomingInvitation=A,this.handleSessionState(A,!1);const{soft_device_auto_answer:e,auto_answer_time:t}=Ve.agentInfo,s=he.get("direction"),i=1===e;if(s===ee.OUTGOING)this.answerCall();else if(i&&s===ee.INCOMING){const A=Number(t)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(A){this.eventCallback?.({type:te.WEB_RTC_ANSWER_FAILED,data:{detail:A}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,he.updateDirection(null),he.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(A){if(!this.activeSession)throw new Error("当前没有活跃的通话");const e=this.activeSession.sessionDescriptionHandler;e&&"function"==typeof e.sendDtmf?(e.sendDtmf(A),this.eventCallback?.({type:te.WEB_RTC_SEND_DTMF,data:{tone:A}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===j.Established?await A.bye():e===j.Establishing&&(A instanceof X?await A.cancel():A instanceof z&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof z&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!Ve.isRtcReconnecting){Ve.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{Ve.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
13
13
  /**
14
14
  * @license
15
15
  * Copyright 2019 Google LLC
@@ -9,7 +9,7 @@
9
9
  * @copyright Chen, Yi-Cyuan 2014-2023
10
10
  * @license MIT
11
11
  */
12
- !function(A){!function(){var s="input is invalid type",i="object"==typeof window,r=i?window:{};r.JS_MD5_NO_WINDOW&&(i=!1);var n=!i&&"object"==typeof self,o=!r.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?r=Ke:n&&(r=self);var a,V=!r.JS_MD5_NO_COMMON_JS&&A.exports,c=!r.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,h="0123456789abcdef".split(""),l=[128,32768,8388608,-2147483648],g=[0,8,16,24],q=["hex","array","digest","buffer","arrayBuffer","base64"],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),u=[];if(c){var p=new ArrayBuffer(68);a=new Uint8Array(p),u=new Uint32Array(p)}var m=Array.isArray;!r.JS_MD5_NO_NODE_JS&&m||(m=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var C=ArrayBuffer.isView;!c||!r.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&C||(C=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var E=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(s);if(c&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!m(A)&&!C(A))throw new Error(s);return[A,!1]},I=function(A){return function(e){return new f(!0).update(e)[A]()}},M=function(A){var i,n=e,o=t.Buffer;i=o.from&&!r.JS_MD5_NO_BUFFER_FROM?o.from:function(A){return new o(A)};return function(e){if("string"==typeof e)return n.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(s);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),m(e)||C(e)||e.constructor===o?n.createHash("md5").update(i(e)).digest("hex"):A(e)}},w=function(A){return function(e,t){return new B(e,!0).update(t)[A]()}};function f(A){if(A)u[0]=u[16]=u[1]=u[2]=u[3]=u[4]=u[5]=u[6]=u[7]=u[8]=u[9]=u[10]=u[11]=u[12]=u[13]=u[14]=u[15]=0,this.blocks=u,this.buffer8=a;else if(c){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function B(A,e){var t,s=E(A);if(A=s[0],s[1]){var i,r=[],n=A.length,o=0;for(t=0;t<n;++t)(i=A.charCodeAt(t))<128?r[o++]=i:i<2048?(r[o++]=192|i>>>6,r[o++]=128|63&i):i<55296||i>=57344?(r[o++]=224|i>>>12,r[o++]=128|i>>>6&63,r[o++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[o++]=240|i>>>18,r[o++]=128|i>>>12&63,r[o++]=128|i>>>6&63,r[o++]=128|63&i);A=r}A.length>64&&(A=new f(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}f.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}f.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=E(A);A=e[0];for(var t,s,i=e[1],r=0,n=A.length,o=this.blocks,a=this.buffer8;r<n;){if(this.hashed&&(this.hashed=!1,o[0]=o[16],o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),i)if(c)for(s=this.start;r<n&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<n&&s<64;++r)(t=A.charCodeAt(r))<128?o[s>>>2]|=t<<g[3&s++]:t<2048?(o[s>>>2]|=(192|t>>>6)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]):t<55296||t>=57344?(o[s>>>2]|=(224|t>>>12)<<g[3&s++],o[s>>>2]|=(128|t>>>6&63)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),o[s>>>2]|=(240|t>>>18)<<g[3&s++],o[s>>>2]|=(128|t>>>12&63)<<g[3&s++],o[s>>>2]|=(128|t>>>6&63)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]);else if(c)for(s=this.start;r<n&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<n&&s<64;++r)o[s>>>2]|=A[r]<<g[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},f.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=l[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},f.prototype.hash=function(){var A,e,t,s,i,r,n=this.blocks;this.first?e=((e=((A=((A=n[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+n[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+n[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+n[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+n[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+n[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+n[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+n[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+n[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+n[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+n[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+n[10]-42063)<<17|t>>>15)+s|0)&(s^A))+n[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+n[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+n[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+n[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[1]-165796510)<<5|A>>>27)+e|0)^e))+n[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[11]+643717713)<<14|t>>>18)+s|0)^s))+n[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[5]-701558691)<<5|A>>>27)+e|0)^e))+n[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[15]-660478335)<<14|t>>>18)+s|0)^s))+n[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[9]+568446438)<<5|A>>>27)+e|0)^e))+n[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[3]-187363961)<<14|t>>>18)+s|0)^s))+n[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[13]-1444681467)<<5|A>>>27)+e|0)^e))+n[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[7]+1735328473)<<14|t>>>18)+s|0)^s))+n[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[5]-378558)<<4|A>>>28)+e|0))+n[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[11]+1839030562)<<16|t>>>16)+s|0))+n[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[1]-1530992060)<<4|A>>>28)+e|0))+n[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[7]-155497632)<<16|t>>>16)+s|0))+n[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[13]+681279174)<<4|A>>>28)+e|0))+n[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[3]-722521979)<<16|t>>>16)+s|0))+n[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[9]-640364487)<<4|A>>>28)+e|0))+n[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[15]+530742520)<<16|t>>>16)+s|0))+n[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[0]-198630844)<<6|A>>>26)+e|0)|~t))+n[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[14]-1416354905)<<15|t>>>17)+s|0)|~A))+n[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[12]+1700485571)<<6|A>>>26)+e|0)|~t))+n[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[10]-1051523)<<15|t>>>17)+s|0)|~A))+n[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[8]+1873313359)<<6|A>>>26)+e|0)|~t))+n[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[6]-1560198380)<<15|t>>>17)+s|0)|~A))+n[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[4]-145523070)<<6|A>>>26)+e|0)|~t))+n[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[2]+718787259)<<15|t>>>17)+s|0)|~A))+n[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},f.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return h[A>>>4&15]+h[15&A]+h[A>>>12&15]+h[A>>>8&15]+h[A>>>20&15]+h[A>>>16&15]+h[A>>>28&15]+h[A>>>24&15]+h[e>>>4&15]+h[15&e]+h[e>>>12&15]+h[e>>>8&15]+h[e>>>20&15]+h[e>>>16&15]+h[e>>>28&15]+h[e>>>24&15]+h[t>>>4&15]+h[15&t]+h[t>>>12&15]+h[t>>>8&15]+h[t>>>20&15]+h[t>>>16&15]+h[t>>>28&15]+h[t>>>24&15]+h[s>>>4&15]+h[15&s]+h[s>>>12&15]+h[s>>>8&15]+h[s>>>20&15]+h[s>>>16&15]+h[s>>>28&15]+h[s>>>24&15]},f.prototype.toString=f.prototype.hex,f.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},f.prototype.array=f.prototype.digest,f.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},f.prototype.buffer=f.prototype.arrayBuffer,f.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=d[A>>>2]+d[63&(A<<4|e>>>4)]+d[63&(e<<2|t>>>6)]+d[63&t];return A=i[r],s+=d[A>>>2]+d[A<<4&63]+"=="},B.prototype=new f,B.prototype.finalize=function(){if(f.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();f.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),f.prototype.finalize.call(this)}};var Q=function(){var A=I("hex");o&&(A=M(A)),A.create=function(){return new f},A.update=function(e){return A.create().update(e)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=I(t)}return A}();Q.md5=Q,Q.md5.hmac=function(){var A=w("hex");A.create=function(A){return new B(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=w(t)}return A}(),V?A.exports=Q:r.md5=Q}()}(Oe);var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return xe.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends Ae{updateRttObject(e){this.setState({rttObject:e}),Ve.emit(A.EventName.WEBSITE_DELAY,e)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=$A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:ce.logBuiltinEnabled};this.userAgent=new $A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case eA.Connecting:t=A.WebRtcCallSipEventEnum.WEB_RTC_CONNECTING;break;case eA.Connected:t=A.WebRtcCallSipEventEnum.WEB_RTC_CONNECTED,this.reconnectAttempts=0,ce.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case eA.Disconnecting:t=A.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTING;break;case eA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=A.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTED;const e=le.get("answerDevice");if(!ce.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new nA(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case $.Initial:t="initial";break;case $.Registered:t=A.WebRtcCallSipEventEnum.WEB_RTC_REGISTERED;break;case $.Unregistered:t=A.WebRtcCallSipEventEnum.WEB_RTC_UNREGISTERED;break;case $.Terminated:t=A.WebRtcCallSipEventEnum.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case L.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case L.Terminating:break;case L.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case L.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=ce.agentInfo,i=le.get("direction"),r=1===t;if(i===A.DirectionEnum.OUTGOING)this.answerCall();else if(r&&i===A.DirectionEnum.INCOMING){const A=Number(s)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(e){this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,le.updateDirection(null),le.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===L.Established?await A.bye():e===L.Establishing&&(A instanceof _?await A.cancel():A instanceof X&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof X&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!ce.isRtcReconnecting){ce.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{ce.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
12
+ !function(A){!function(){var s="input is invalid type",i="object"==typeof window,r=i?window:{};r.JS_MD5_NO_WINDOW&&(i=!1);var n=!i&&"object"==typeof self,o=!r.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;o?r=Ke:n&&(r=self);var a,V=!r.JS_MD5_NO_COMMON_JS&&A.exports,c=!r.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,h="0123456789abcdef".split(""),l=[128,32768,8388608,-2147483648],g=[0,8,16,24],q=["hex","array","digest","buffer","arrayBuffer","base64"],d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),u=[];if(c){var p=new ArrayBuffer(68);a=new Uint8Array(p),u=new Uint32Array(p)}var m=Array.isArray;!r.JS_MD5_NO_NODE_JS&&m||(m=function(A){return"[object Array]"===Object.prototype.toString.call(A)});var C=ArrayBuffer.isView;!c||!r.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&C||(C=function(A){return"object"==typeof A&&A.buffer&&A.buffer.constructor===ArrayBuffer});var E=function(A){var e=typeof A;if("string"===e)return[A,!0];if("object"!==e||null===A)throw new Error(s);if(c&&A.constructor===ArrayBuffer)return[new Uint8Array(A),!1];if(!m(A)&&!C(A))throw new Error(s);return[A,!1]},I=function(A){return function(e){return new f(!0).update(e)[A]()}},M=function(A){var i,n=e,o=t.Buffer;i=o.from&&!r.JS_MD5_NO_BUFFER_FROM?o.from:function(A){return new o(A)};return function(e){if("string"==typeof e)return n.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(s);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),m(e)||C(e)||e.constructor===o?n.createHash("md5").update(i(e)).digest("hex"):A(e)}},w=function(A){return function(e,t){return new B(e,!0).update(t)[A]()}};function f(A){if(A)u[0]=u[16]=u[1]=u[2]=u[3]=u[4]=u[5]=u[6]=u[7]=u[8]=u[9]=u[10]=u[11]=u[12]=u[13]=u[14]=u[15]=0,this.blocks=u,this.buffer8=a;else if(c){var e=new ArrayBuffer(68);this.buffer8=new Uint8Array(e),this.blocks=new Uint32Array(e)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function B(A,e){var t,s=E(A);if(A=s[0],s[1]){var i,r=[],n=A.length,o=0;for(t=0;t<n;++t)(i=A.charCodeAt(t))<128?r[o++]=i:i<2048?(r[o++]=192|i>>>6,r[o++]=128|63&i):i<55296||i>=57344?(r[o++]=224|i>>>12,r[o++]=128|i>>>6&63,r[o++]=128|63&i):(i=65536+((1023&i)<<10|1023&A.charCodeAt(++t)),r[o++]=240|i>>>18,r[o++]=128|i>>>12&63,r[o++]=128|i>>>6&63,r[o++]=128|63&i);A=r}A.length>64&&(A=new f(!0).update(A).array());var a=[],V=[];for(t=0;t<64;++t){var c=A[t]||0;a[t]=92^c,V[t]=54^c}f.call(this,e),this.update(V),this.oKeyPad=a,this.inner=!0,this.sharedMemory=e}f.prototype.update=function(A){if(this.finalized)throw new Error("finalize already called");var e=E(A);A=e[0];for(var t,s,i=e[1],r=0,n=A.length,o=this.blocks,a=this.buffer8;r<n;){if(this.hashed&&(this.hashed=!1,o[0]=o[16],o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),i)if(c)for(s=this.start;r<n&&s<64;++r)(t=A.charCodeAt(r))<128?a[s++]=t:t<2048?(a[s++]=192|t>>>6,a[s++]=128|63&t):t<55296||t>=57344?(a[s++]=224|t>>>12,a[s++]=128|t>>>6&63,a[s++]=128|63&t):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),a[s++]=240|t>>>18,a[s++]=128|t>>>12&63,a[s++]=128|t>>>6&63,a[s++]=128|63&t);else for(s=this.start;r<n&&s<64;++r)(t=A.charCodeAt(r))<128?o[s>>>2]|=t<<g[3&s++]:t<2048?(o[s>>>2]|=(192|t>>>6)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]):t<55296||t>=57344?(o[s>>>2]|=(224|t>>>12)<<g[3&s++],o[s>>>2]|=(128|t>>>6&63)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]):(t=65536+((1023&t)<<10|1023&A.charCodeAt(++r)),o[s>>>2]|=(240|t>>>18)<<g[3&s++],o[s>>>2]|=(128|t>>>12&63)<<g[3&s++],o[s>>>2]|=(128|t>>>6&63)<<g[3&s++],o[s>>>2]|=(128|63&t)<<g[3&s++]);else if(c)for(s=this.start;r<n&&s<64;++r)a[s++]=A[r];else for(s=this.start;r<n&&s<64;++r)o[s>>>2]|=A[r]<<g[3&s++];this.lastByteIndex=s,this.bytes+=s-this.start,s>=64?(this.start=s-64,this.hash(),this.hashed=!0):this.start=s}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},f.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var A=this.blocks,e=this.lastByteIndex;A[e>>>2]|=l[3&e],e>=56&&(this.hashed||this.hash(),A[0]=A[16],A[16]=A[1]=A[2]=A[3]=A[4]=A[5]=A[6]=A[7]=A[8]=A[9]=A[10]=A[11]=A[12]=A[13]=A[14]=A[15]=0),A[14]=this.bytes<<3,A[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},f.prototype.hash=function(){var A,e,t,s,i,r,n=this.blocks;this.first?e=((e=((A=((A=n[0]-680876937)<<7|A>>>25)-271733879|0)^(t=((t=(-271733879^(s=((s=(-1732584194^2004318071&A)+n[1]-117830708)<<12|s>>>20)+A|0)&(-271733879^A))+n[2]-1126478375)<<17|t>>>15)+s|0)&(s^A))+n[3]-1316259209)<<22|e>>>10)+t|0:(A=this.h0,e=this.h1,t=this.h2,e=((e+=((A=((A+=((s=this.h3)^e&(t^s))+n[0]-680876936)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[1]-389564586)<<12|s>>>20)+A|0)&(A^e))+n[2]+606105819)<<17|t>>>15)+s|0)&(s^A))+n[3]-1044525330)<<22|e>>>10)+t|0),e=((e+=((A=((A+=(s^e&(t^s))+n[4]-176418897)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[5]+1200080426)<<12|s>>>20)+A|0)&(A^e))+n[6]-1473231341)<<17|t>>>15)+s|0)&(s^A))+n[7]-45705983)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+n[8]+1770035416)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[9]-1958414417)<<12|s>>>20)+A|0)&(A^e))+n[10]-42063)<<17|t>>>15)+s|0)&(s^A))+n[11]-1990404162)<<22|e>>>10)+t|0,e=((e+=((A=((A+=(s^e&(t^s))+n[12]+1804603682)<<7|A>>>25)+e|0)^(t=((t+=(e^(s=((s+=(t^A&(e^t))+n[13]-40341101)<<12|s>>>20)+A|0)&(A^e))+n[14]-1502002290)<<17|t>>>15)+s|0)&(s^A))+n[15]+1236535329)<<22|e>>>10)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[1]-165796510)<<5|A>>>27)+e|0)^e))+n[6]-1069501632)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[11]+643717713)<<14|t>>>18)+s|0)^s))+n[0]-373897302)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[5]-701558691)<<5|A>>>27)+e|0)^e))+n[10]+38016083)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[15]-660478335)<<14|t>>>18)+s|0)^s))+n[4]-405537848)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[9]+568446438)<<5|A>>>27)+e|0)^e))+n[14]-1019803690)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[3]-187363961)<<14|t>>>18)+s|0)^s))+n[8]+1163531501)<<20|e>>>12)+t|0,e=((e+=((s=((s+=(e^t&((A=((A+=(t^s&(e^t))+n[13]-1444681467)<<5|A>>>27)+e|0)^e))+n[2]-51403784)<<9|s>>>23)+A|0)^A&((t=((t+=(A^e&(s^A))+n[7]+1735328473)<<14|t>>>18)+s|0)^s))+n[12]-1926607734)<<20|e>>>12)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[5]-378558)<<4|A>>>28)+e|0))+n[8]-2022574463)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[11]+1839030562)<<16|t>>>16)+s|0))+n[14]-35309556)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[1]-1530992060)<<4|A>>>28)+e|0))+n[4]+1272893353)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[7]-155497632)<<16|t>>>16)+s|0))+n[10]-1094730640)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[13]+681279174)<<4|A>>>28)+e|0))+n[0]-358537222)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[3]-722521979)<<16|t>>>16)+s|0))+n[6]+76029189)<<23|e>>>9)+t|0,e=((e+=((r=(s=((s+=((i=e^t)^(A=((A+=(i^s)+n[9]-640364487)<<4|A>>>28)+e|0))+n[12]-421815835)<<11|s>>>21)+A|0)^A)^(t=((t+=(r^e)+n[15]+530742520)<<16|t>>>16)+s|0))+n[2]-995338651)<<23|e>>>9)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[0]-198630844)<<6|A>>>26)+e|0)|~t))+n[7]+1126891415)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[14]-1416354905)<<15|t>>>17)+s|0)|~A))+n[5]-57434055)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[12]+1700485571)<<6|A>>>26)+e|0)|~t))+n[3]-1894986606)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[10]-1051523)<<15|t>>>17)+s|0)|~A))+n[1]-2054922799)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[8]+1873313359)<<6|A>>>26)+e|0)|~t))+n[15]-30611744)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[6]-1560198380)<<15|t>>>17)+s|0)|~A))+n[13]+1309151649)<<21|e>>>11)+t|0,e=((e+=((s=((s+=(e^((A=((A+=(t^(e|~s))+n[4]-145523070)<<6|A>>>26)+e|0)|~t))+n[11]-1120210379)<<10|s>>>22)+A|0)^((t=((t+=(A^(s|~e))+n[2]+718787259)<<15|t>>>17)+s|0)|~A))+n[9]-343485551)<<21|e>>>11)+t|0,this.first?(this.h0=A+1732584193|0,this.h1=e-271733879|0,this.h2=t-1732584194|0,this.h3=s+271733878|0,this.first=!1):(this.h0=this.h0+A|0,this.h1=this.h1+e|0,this.h2=this.h2+t|0,this.h3=this.h3+s|0)},f.prototype.hex=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return h[A>>>4&15]+h[15&A]+h[A>>>12&15]+h[A>>>8&15]+h[A>>>20&15]+h[A>>>16&15]+h[A>>>28&15]+h[A>>>24&15]+h[e>>>4&15]+h[15&e]+h[e>>>12&15]+h[e>>>8&15]+h[e>>>20&15]+h[e>>>16&15]+h[e>>>28&15]+h[e>>>24&15]+h[t>>>4&15]+h[15&t]+h[t>>>12&15]+h[t>>>8&15]+h[t>>>20&15]+h[t>>>16&15]+h[t>>>28&15]+h[t>>>24&15]+h[s>>>4&15]+h[15&s]+h[s>>>12&15]+h[s>>>8&15]+h[s>>>20&15]+h[s>>>16&15]+h[s>>>28&15]+h[s>>>24&15]},f.prototype.toString=f.prototype.hex,f.prototype.digest=function(){this.finalize();var A=this.h0,e=this.h1,t=this.h2,s=this.h3;return[255&A,A>>>8&255,A>>>16&255,A>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&s,s>>>8&255,s>>>16&255,s>>>24&255]},f.prototype.array=f.prototype.digest,f.prototype.arrayBuffer=function(){this.finalize();var A=new ArrayBuffer(16),e=new Uint32Array(A);return e[0]=this.h0,e[1]=this.h1,e[2]=this.h2,e[3]=this.h3,A},f.prototype.buffer=f.prototype.arrayBuffer,f.prototype.base64=function(){for(var A,e,t,s="",i=this.array(),r=0;r<15;)A=i[r++],e=i[r++],t=i[r++],s+=d[A>>>2]+d[63&(A<<4|e>>>4)]+d[63&(e<<2|t>>>6)]+d[63&t];return A=i[r],s+=d[A>>>2]+d[A<<4&63]+"=="},B.prototype=new f,B.prototype.finalize=function(){if(f.prototype.finalize.call(this),this.inner){this.inner=!1;var A=this.array();f.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(A),f.prototype.finalize.call(this)}};var Q=function(){var A=I("hex");o&&(A=M(A)),A.create=function(){return new f},A.update=function(e){return A.create().update(e)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=I(t)}return A}();Q.md5=Q,Q.md5.hmac=function(){var A=w("hex");A.create=function(A){return new B(A)},A.update=function(e,t){return A.create(e).update(t)};for(var e=0;e<q.length;++e){var t=q[e];A[t]=w(t)}return A}(),V?A.exports=Q:r.md5=Q}()}(Oe);var Ne=Oe.exports;const be=(A,e)=>{const t=Date.now(),s=`${A}:${t}:${Ne.md5(`${e}${t}`)}`,i=(new TextEncoder).encode(s);return btoa(String.fromCharCode(...i))},Je="/v1/aicc/bmserver",He="/v1/aicc/ccs";let je="",Le="",We="";async function Pe(A,e){const t=function(){const A=be(Le,We);return xe.create({prefixUrl:`${je}/api`,timeout:!1,headers:{Authorization:A},hooks:{afterResponse:[async(A,e,t)=>{const s=await t.clone().json();if(0!==s.code)throw new Error(JSON.stringify(s)||"请求失败");return t.json=async()=>s,t}]}})}(),s=A.replace(/^\/+/,"");return t.post(s,{json:e}).json()}const ze=A=>Pe(`${He}/state/change`,A);const Xe=new class extends Ae{updateRttObject(e){this.setState({rttObject:e}),Ve.emit(A.EventName.WEBSITE_DELAY,e)}}({rttObject:{rtt:null,jitter:null,packetsLost:null,packetsReceived:null,packetsSent:null,sendBitrate:null,recvBitrate:null,codec:null}});class _e{constructor(A,e){this.config=A,this.eventCallback=e,this.userAgent=null,this.registerer=null,this.activeSession=null,this.callTimeoutTimer=null,this.incomingInvitation=null,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.reconnectTimer=null,this.isOffline=!1,this.autoAnswerTimer=null,this.isManuallyStopped=!1,this.handleNetworkInfoChange=A=>{if(A.rttObject?.rtt){0===(A.rttObject?.rtt||0)?this.isOffline||(this.isOffline=!0,this.handleOffline()):this.isOffline&&(this.isOffline=!1,this.handleOnline())}},this.handleOffline=()=>{console.warn("[SIPClient] 网络断开,准备销毁 SIP 客户端",(new Date).toLocaleString()),this.destroy()},this.handleOnline=()=>{console.warn("[SIPClient] 网络恢复,准备重新启动 SIP 客户端",(new Date).toLocaleString()),this.reconnect()},Xe.subscribe(this.handleNetworkInfoChange)}async start(){const A=$A.makeURI(`sip:${this.config.user}@${this.config.server}`);if(!A)throw new Error("无效的SIP配置");const e={uri:A,authorizationUsername:this.config.user,authorizationPassword:this.config.password,transportOptions:{server:this.config.webSocket,connectionTimeout:30,keepAliveInterval:30},contactName:this.config.user,contactParams:{transport:"wss"},userAgentString:"SwiftSIP/1.0.74",sessionDescriptionHandlerFactoryOptions:{alwaysAcquireMediaFirst:!0,peerConnectionConfiguration:{iceServers:[]},iceGatheringTimeout:400},logBuiltinEnabled:ce.logBuiltinEnabled};this.userAgent=new $A(e),this.setupEventListeners(),await this.userAgent.start(),await this.register()}setupEventListeners(){this.userAgent&&(this.userAgent.transport.stateChange.addListener(e=>{let t;switch(e){case eA.Connecting:t=A.WebRtcCallSipEventEnum.WEB_RTC_CONNECTING;break;case eA.Connected:t=A.WebRtcCallSipEventEnum.WEB_RTC_CONNECTED,this.reconnectAttempts=0,ce.isRtcReconnecting=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null);break;case eA.Disconnecting:t=A.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTING;break;case eA.Disconnected:{if(this.isManuallyStopped)return void console.warn("[SIP] 手动断开,不触发重连");t=A.WebRtcCallSipEventEnum.WEB_RTC_DISCONNECTED;const e=le.get("answerDevice");if(!ce.isRtcReconnecting&&this.reconnectAttempts<this.maxReconnectAttempts&&1===e){this.reconnectAttempts++;const A=1e3*this.reconnectAttempts;console.warn(`SIP WebSocket 断开,第 ${this.reconnectAttempts} 次尝试重连,${A}ms 后重试...`),this.reconnectTimer=setTimeout(()=>{this.reconnect()},A)}else this.reconnectAttempts>=this.maxReconnectAttempts&&console.error("SIP 重连失败:已达到最大重试次数");break}default:t="unknown"}this.eventCallback?.({type:t})}),this.userAgent.delegate={onInvite:A=>{this.handleIncomingCall(A)}})}async register(){if(this.userAgent){this.registerer=new nA(this.userAgent),this.registerer?.stateChange.addListener(e=>{let t;switch(e){case $.Initial:t="initial";break;case $.Registered:t=A.WebRtcCallSipEventEnum.WEB_RTC_REGISTERED;break;case $.Unregistered:t=A.WebRtcCallSipEventEnum.WEB_RTC_UNREGISTERED;break;case $.Terminated:t=A.WebRtcCallSipEventEnum.WEB_RTC_TERMINATED;break;default:t="unknown"}this.eventCallback?.({type:t})});try{await this.registerer.register()}catch(e){this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_REGISTER_FAILED,data:e})}}}attachRemoteAudio(A){const e=A.sessionDescriptionHandler;if(e){const A=e.peerConnection;if(!A)return;const t=new MediaStream;A.getReceivers().forEach(A=>{A.track&&"audio"===A.track.kind&&t.addTrack(A.track)});let s=document.getElementById("sip-remote-audio");s||(s=document.createElement("audio"),s.id="sip-remote-audio",s.autoplay=!0,s.style.display="none",document.body.appendChild(s)),s.srcObject=t,s.play().catch(A=>{console.error("音频播放失败,需要用户交互触发",A)})}}handleSessionState(A,e,t){A.stateChange.addListener(e=>{switch(e){case L.Established:clearTimeout(this.callTimeoutTimer),this.activeSession=A,this.attachRemoteAudio(A);break;case L.Terminating:break;case L.Terminated:this.activeSession=null,clearTimeout(this.callTimeoutTimer);case L.Establishing:}})}handleIncomingCall(e){this.incomingInvitation=e,this.handleSessionState(e,!1);const{soft_device_auto_answer:t,auto_answer_time:s}=ce.agentInfo,i=le.get("direction"),r=1===t;if(i===A.DirectionEnum.OUTGOING)this.answerCall();else if(r&&i===A.DirectionEnum.INCOMING){const A=Number(s)||0;A>0?this.autoAnswerTimer=setTimeout(()=>{this.answerCall(),this.autoAnswerTimer=null},A):this.answerCall()}}async answerCall(){if(!this.incomingInvitation)throw new Error("无来电可接听");this.autoAnswerTimer&&(clearTimeout(this.autoAnswerTimer),this.autoAnswerTimer=null);try{this.activeSession=this.incomingInvitation,await this.incomingInvitation.accept(),this.incomingInvitation=null}catch(e){this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_ANSWER_FAILED,data:{detail:e}})}}async rejectInCall(){if(this.incomingInvitation)try{await this.incomingInvitation.reject(),this.incomingInvitation=null,le.updateDirection(null),le.updateIsCalling(!1),clearTimeout(this.callTimeoutTimer)}catch(A){this.eventCallback?.({type:"error",data:{message:"拒接失败",detail:A}})}}sendDTMF(e){if(!this.activeSession)throw new Error("当前没有活跃的通话");const t=this.activeSession.sessionDescriptionHandler;t&&"function"==typeof t.sendDtmf?(t.sendDtmf(e),this.eventCallback?.({type:A.WebRtcCallSipEventEnum.WEB_RTC_SEND_DTMF,data:{tone:e}})):console.warn("DTMF发送不支持或未初始化")}async hangup(){if(this.activeSession,this.activeSession){clearTimeout(this.callTimeoutTimer);const A=this.activeSession;if(!A)return;const e=A.state;try{e===L.Established?await A.bye():e===L.Establishing&&(A instanceof _?await A.cancel():A instanceof X&&await A.reject()),clearTimeout(this.callTimeoutTimer)}catch(A){console.error("挂断失败",A)}finally{this.activeSession=null}}}async rejectOutCall(){this.activeSession instanceof X&&(await this.activeSession.reject(),this.activeSession=null)}async destroy(){if(this.isManuallyStopped=!0,clearTimeout(this.callTimeoutTimer),this.activeSession&&await this.hangup(),this.registerer){try{await this.registerer.unregister()}catch(A){console.warn("注销失败",A)}this.registerer=null}this.userAgent&&(await this.userAgent.stop(),this.userAgent=null)}async reconnect(){if(!ce.isRtcReconnecting){ce.isRtcReconnecting=!0;try{await this.destroy(),await this.start(),this.isOffline=!1}catch(A){console.error("重连失败",A)}finally{ce.isRtcReconnecting=!1}}}async getNetworkStats(){if(this.activeSession){const A=this.activeSession.sessionDescriptionHandler?.peerConnection;if(!A)return null;const e=await A.getStats(),t={};return e.forEach(A=>{"candidate-pair"===A.type&&"succeeded"===A.state&&null!=A.currentRoundTripTime&&(t.rtt=+(1e3*A.currentRoundTripTime).toFixed(2)),"inbound-rtp"===A.type&&"audio"===A.kind&&(t.jitter=+(1e3*A.jitter).toFixed(2),t.packetsLost=A.packetsLost,t.packetsReceived=A.packetsReceived,A.bytesReceived&&A.timestamp&&(t.recvBitrate=+(A.bytesReceived/1024).toFixed(2))),"outbound-rtp"===A.type&&"audio"===A.kind&&(t.packetsSent=A.packetsSent,A.bytesSent&&A.timestamp&&(t.sendBitrate=+(A.bytesSent/1024).toFixed(2))),"codec"===A.type&&A.mimeType&&(t.codec=A.mimeType)}),{...t,rtt:t?.rtt||40}}try{const A=Date.now();await Pe(`${Je}/config/ping`,{});const e=Date.now();return{rtt:e-A||1}}catch(A){}}}
13
13
  /**
14
14
  * @license
15
15
  * Copyright 2019 Google LLC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ysyt-agent-sdk",
3
- "version": "1.0.74",
3
+ "version": "1.0.75",
4
4
  "main": "dist/ysyt-agent-sdk.cjs.js",
5
5
  "module": "dist/ysyt-agent-sdk.esm.js",
6
6
  "types": "dist/src/index.d.ts",