media-av 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  3. 支持软电话,实现音视频呼叫
6
6
  4. 支持音视频全双工半/双工呼叫
7
7
 
8
- 2024/03/07 0.0.18
8
+ 2024/03/07 0.0.19
9
9
  1. 新增广播喊话
10
10
 
11
11
  2024/01/29 0.0.15
package/dist/mediaAV.js CHANGED
@@ -2786,7 +2786,7 @@ class Ft {
2786
2786
  this.localStream.removeTrack(r), r.stop();
2787
2787
  this.localStream = void 0;
2788
2788
  }
2789
- this.remoteStream = void 0, this.desktopSharing = !1;
2789
+ this.remoteStream = void 0, this.desktopSharing && (this.desktopSharing = !1, this.sessionListener.onStopDesktopShare());
2790
2790
  }
2791
2791
  /**
2792
2792
  * 移动端切换前后置摄像头
@@ -6,4 +6,4 @@
6
6
  `+i):n.stack=i}throw n}}_request(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=ie(this.defaults,r);const{transitional:n,paramsSerializer:o,headers:i}=r;n!==void 0&&it.assertOptions(n,{silentJSONParsing:q.transitional(q.boolean),forcedJSONParsing:q.transitional(q.boolean),clarifyTimeoutError:q.transitional(q.boolean)},!1),o!=null&&(u.isFunction(o)?r.paramsSerializer={serialize:o}:it.assertOptions(o,{encode:q.function,serialize:q.function},!0)),r.method=(r.method||this.defaults.method||"get").toLowerCase();let s=i&&u.merge(i.common,i[r.method]);i&&u.forEach(["delete","get","head","post","put","patch","common"],p=>{delete i[p]}),r.headers=V.concat(s,i);const a=[];let c=!0;this.interceptors.request.forEach(function(h){typeof h.runWhen=="function"&&h.runWhen(r)===!1||(c=c&&h.synchronous,a.unshift(h.fulfilled,h.rejected))});const l=[];this.interceptors.response.forEach(function(h){l.push(h.fulfilled,h.rejected)});let d,f=0,y;if(!c){const p=[lr.bind(this),void 0];for(p.unshift.apply(p,a),p.push.apply(p,l),y=p.length,d=Promise.resolve(r);f<y;)d=d.then(p[f++],p[f++]);return d}y=a.length;let w=r;for(f=0;f<y;){const p=a[f++],h=a[f++];try{w=p(w)}catch(E){h.call(this,E);break}}try{d=lr.call(this,w)}catch(p){return Promise.reject(p)}for(f=0,y=l.length;f<y;)d=d.then(l[f++],l[f++]);return d}getUri(e){e=ie(this.defaults,e);const r=ir(e.baseURL,e.url);return Yt(r,e.params,e.paramsSerializer)}}u.forEach(["delete","get","head","options"],function(e){xe.prototype[e]=function(r,n){return this.request(ie(n||{},{method:e,url:r,data:(n||{}).data}))}}),u.forEach(["post","put","patch"],function(e){function r(n){return function(i,s,a){return this.request(ie(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:i,data:s}))}}xe.prototype[e]=r(),xe.prototype[e+"Form"]=r(!0)});const Ue=xe;class st{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(i){r=i});const n=this;this.promise.then(o=>{if(!n._listeners)return;let i=n._listeners.length;for(;i-- >0;)n._listeners[i](o);n._listeners=null}),this.promise.then=o=>{let i;const s=new Promise(a=>{n.subscribe(a),i=a}).then(o);return s.cancel=function(){n.unsubscribe(i)},s},e(function(i,s,a){n.reason||(n.reason=new be(i,s,a),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}static source(){let e;return{token:new st(function(o){e=o}),cancel:e}}}const io=st;function so(t){return function(r){return t.apply(null,r)}}function ao(t){return u.isObject(t)&&t.isAxiosError===!0}const at={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(at).forEach(([t,e])=>{at[e]=t});const co=at;function pr(t){const e=new Ue(t),r=N(Ue.prototype.request,e);return u.extend(r,Ue.prototype,e,{allOwnKeys:!0}),u.extend(r,e,null,{allOwnKeys:!0}),r.create=function(o){return pr(ie(t,o))},r}const O=pr(Ze);O.Axios=Ue,O.CanceledError=be,O.CancelToken=io,O.isCancel=or,O.VERSION=fr,O.toFormData=Fe,O.AxiosError=v,O.Cancel=O.CanceledError,O.all=function(e){return Promise.all(e)},O.spread=so,O.isAxiosError=ao,O.mergeConfig=ie,O.AxiosHeaders=V,O.formToJSON=t=>rr(u.isHTMLForm(t)?new FormData(t):t),O.getAdapter=cr.getAdapter,O.HttpStatusCode=co,O.default=O;function lo(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function uo(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var r=function n(){return this instanceof n?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}),r}var fo=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var e={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var o=42;e[r]=o;for(r in e)return!1;if(typeof Object.keys=="function"&&Object.keys(e).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(e).length!==0)return!1;var i=Object.getOwnPropertySymbols(e);if(i.length!==1||i[0]!==r||!Object.prototype.propertyIsEnumerable.call(e,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var s=Object.getOwnPropertyDescriptor(e,r);if(s.value!==o||s.enumerable!==!0)return!1}return!0},hr=typeof Symbol<"u"&&Symbol,po=fo,ho=function(){return typeof hr!="function"||typeof Symbol!="function"||typeof hr("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:po()},yr={foo:{}},yo=Object,mo=function(){return{__proto__:yr}.foo===yr.foo&&!({__proto__:null}instanceof yo)},go="Function.prototype.bind called on incompatible ",ct=Array.prototype.slice,So=Object.prototype.toString,wo="[object Function]",bo=function(e){var r=this;if(typeof r!="function"||So.call(r)!==wo)throw new TypeError(go+r);for(var n=ct.call(arguments,1),o,i=function(){if(this instanceof o){var d=r.apply(this,n.concat(ct.call(arguments)));return Object(d)===d?d:this}else return r.apply(e,n.concat(ct.call(arguments)))},s=Math.max(0,r.length-n.length),a=[],c=0;c<s;c++)a.push("$"+c);if(o=Function("binder","return function ("+a.join(",")+"){ return binder.apply(this,arguments); }")(i),r.prototype){var l=function(){};l.prototype=r.prototype,o.prototype=new l,l.prototype=null}return o},vo=bo,lt=Function.prototype.bind||vo,Eo=lt,Ao=Eo.call(Function.call,Object.prototype.hasOwnProperty),b,se=SyntaxError,mr=Function,ae=TypeError,ut=function(t){try{return mr('"use strict"; return ('+t+").constructor;")()}catch{}},Y=Object.getOwnPropertyDescriptor;if(Y)try{Y({},"")}catch{Y=null}var ft=function(){throw new ae},Oo=Y?function(){try{return arguments.callee,ft}catch{try{return Y(arguments,"callee").get}catch{return ft}}}():ft,ce=ho(),Ro=mo(),R=Object.getPrototypeOf||(Ro?function(t){return t.__proto__}:null),le={},Co=typeof Uint8Array>"u"||!R?b:R(Uint8Array),Z={"%AggregateError%":typeof AggregateError>"u"?b:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?b:ArrayBuffer,"%ArrayIteratorPrototype%":ce&&R?R([][Symbol.iterator]()):b,"%AsyncFromSyncIteratorPrototype%":b,"%AsyncFunction%":le,"%AsyncGenerator%":le,"%AsyncGeneratorFunction%":le,"%AsyncIteratorPrototype%":le,"%Atomics%":typeof Atomics>"u"?b:Atomics,"%BigInt%":typeof BigInt>"u"?b:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?b:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?b:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?b:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?b:Float32Array,"%Float64Array%":typeof Float64Array>"u"?b:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?b:FinalizationRegistry,"%Function%":mr,"%GeneratorFunction%":le,"%Int8Array%":typeof Int8Array>"u"?b:Int8Array,"%Int16Array%":typeof Int16Array>"u"?b:Int16Array,"%Int32Array%":typeof Int32Array>"u"?b:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":ce&&R?R(R([][Symbol.iterator]())):b,"%JSON%":typeof JSON=="object"?JSON:b,"%Map%":typeof Map>"u"?b:Map,"%MapIteratorPrototype%":typeof Map>"u"||!ce||!R?b:R(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?b:Promise,"%Proxy%":typeof Proxy>"u"?b:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?b:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?b:Set,"%SetIteratorPrototype%":typeof Set>"u"||!ce||!R?b:R(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?b:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":ce&&R?R(""[Symbol.iterator]()):b,"%Symbol%":ce?Symbol:b,"%SyntaxError%":se,"%ThrowTypeError%":Oo,"%TypedArray%":Co,"%TypeError%":ae,"%Uint8Array%":typeof Uint8Array>"u"?b:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?b:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?b:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?b:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?b:WeakMap,"%WeakRef%":typeof WeakRef>"u"?b:WeakRef,"%WeakSet%":typeof WeakSet>"u"?b:WeakSet};if(R)try{null.error}catch(t){var Io=R(R(t));Z["%Error.prototype%"]=Io}var To=function t(e){var r;if(e==="%AsyncFunction%")r=ut("async function () {}");else if(e==="%GeneratorFunction%")r=ut("function* () {}");else if(e==="%AsyncGeneratorFunction%")r=ut("async function* () {}");else if(e==="%AsyncGenerator%"){var n=t("%AsyncGeneratorFunction%");n&&(r=n.prototype)}else if(e==="%AsyncIteratorPrototype%"){var o=t("%AsyncGenerator%");o&&R&&(r=R(o.prototype))}return Z[e]=r,r},gr={"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},ve=lt,ke=Ao,Po=ve.call(Function.call,Array.prototype.concat),Do=ve.call(Function.apply,Array.prototype.splice),Sr=ve.call(Function.call,String.prototype.replace),Be=ve.call(Function.call,String.prototype.slice),Lo=ve.call(Function.call,RegExp.prototype.exec),Fo=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,No=/\\(\\)?/g,_o=function(e){var r=Be(e,0,1),n=Be(e,-1);if(r==="%"&&n!=="%")throw new se("invalid intrinsic syntax, expected closing `%`");if(n==="%"&&r!=="%")throw new se("invalid intrinsic syntax, expected opening `%`");var o=[];return Sr(e,Fo,function(i,s,a,c){o[o.length]=a?Sr(c,No,"$1"):s||i}),o},xo=function(e,r){var n=e,o;if(ke(gr,n)&&(o=gr[n],n="%"+o[0]+"%"),ke(Z,n)){var i=Z[n];if(i===le&&(i=To(n)),typeof i>"u"&&!r)throw new ae("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:o,name:n,value:i}}throw new se("intrinsic "+e+" does not exist!")},dt=function(e,r){if(typeof e!="string"||e.length===0)throw new ae("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof r!="boolean")throw new ae('"allowMissing" argument must be a boolean');if(Lo(/^%?[^%]*%?$/,e)===null)throw new se("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var n=_o(e),o=n.length>0?n[0]:"",i=xo("%"+o+"%",r),s=i.name,a=i.value,c=!1,l=i.alias;l&&(o=l[0],Do(n,Po([0,1],l)));for(var d=1,f=!0;d<n.length;d+=1){var y=n[d],w=Be(y,0,1),p=Be(y,-1);if((w==='"'||w==="'"||w==="`"||p==='"'||p==="'"||p==="`")&&w!==p)throw new se("property names with quotes must have matching quotes");if((y==="constructor"||!f)&&(c=!0),o+="."+y,s="%"+o+"%",ke(Z,s))a=Z[s];else if(a!=null){if(!(y in a)){if(!r)throw new ae("base intrinsic for "+e+" exists, but the property is not available.");return}if(Y&&d+1>=n.length){var h=Y(a,y);f=!!h,f&&"get"in h&&!("originalValue"in h.get)?a=h.get:a=a[y]}else f=ke(a,y),a=a[y];f&&!c&&(Z[s]=a)}}return a},wr={exports:{}};(function(t){var e=lt,r=dt,n=r("%Function.prototype.apply%"),o=r("%Function.prototype.call%"),i=r("%Reflect.apply%",!0)||e.call(o,n),s=r("%Object.getOwnPropertyDescriptor%",!0),a=r("%Object.defineProperty%",!0),c=r("%Math.max%");if(a)try{a({},"a",{value:1})}catch{a=null}t.exports=function(f){var y=i(e,o,arguments);if(s&&a){var w=s(y,"length");w.configurable&&a(y,"length",{value:1+c(0,f.length-(arguments.length-1))})}return y};var l=function(){return i(e,n,arguments)};a?a(t.exports,"apply",{value:l}):t.exports.apply=l})(wr);var Uo=wr.exports,br=dt,vr=Uo,ko=vr(br("String.prototype.indexOf")),Bo=function(e,r){var n=br(e,!!r);return typeof n=="function"&&ko(e,".prototype.")>-1?vr(n):n};const Mo=uo(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var pt=typeof Map=="function"&&Map.prototype,ht=Object.getOwnPropertyDescriptor&&pt?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Me=pt&&ht&&typeof ht.get=="function"?ht.get:null,Er=pt&&Map.prototype.forEach,yt=typeof Set=="function"&&Set.prototype,mt=Object.getOwnPropertyDescriptor&&yt?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,He=yt&&mt&&typeof mt.get=="function"?mt.get:null,Ar=yt&&Set.prototype.forEach,Ho=typeof WeakMap=="function"&&WeakMap.prototype,Ee=Ho?WeakMap.prototype.has:null,$o=typeof WeakSet=="function"&&WeakSet.prototype,Ae=$o?WeakSet.prototype.has:null,Vo=typeof WeakRef=="function"&&WeakRef.prototype,Or=Vo?WeakRef.prototype.deref:null,Go=Boolean.prototype.valueOf,Wo=Object.prototype.toString,qo=Function.prototype.toString,jo=String.prototype.match,gt=String.prototype.slice,j=String.prototype.replace,zo=String.prototype.toUpperCase,Rr=String.prototype.toLowerCase,Cr=RegExp.prototype.test,Ir=Array.prototype.concat,M=Array.prototype.join,Jo=Array.prototype.slice,Tr=Math.floor,St=typeof BigInt=="function"?BigInt.prototype.valueOf:null,wt=Object.getOwnPropertySymbols,bt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,ue=typeof Symbol=="function"&&typeof Symbol.iterator=="object",D=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===ue||!0)?Symbol.toStringTag:null,Pr=Object.prototype.propertyIsEnumerable,Dr=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(t){return t.__proto__}:null);function Lr(t,e){if(t===1/0||t===-1/0||t!==t||t&&t>-1e3&&t<1e3||Cr.call(/e/,e))return e;var r=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof t=="number"){var n=t<0?-Tr(-t):Tr(t);if(n!==t){var o=String(n),i=gt.call(e,o.length+1);return j.call(o,r,"$&_")+"."+j.call(j.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return j.call(e,r,"$&_")}var vt=Mo,Fr=vt.custom,Nr=Ur(Fr)?Fr:null,Ko=function t(e,r,n,o){var i=r||{};if(z(i,"quoteStyle")&&i.quoteStyle!=="single"&&i.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(z(i,"maxStringLength")&&(typeof i.maxStringLength=="number"?i.maxStringLength<0&&i.maxStringLength!==1/0:i.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=z(i,"customInspect")?i.customInspect:!0;if(typeof s!="boolean"&&s!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(z(i,"indent")&&i.indent!==null&&i.indent!==" "&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(z(i,"numericSeparator")&&typeof i.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(typeof e>"u")return"undefined";if(e===null)return"null";if(typeof e=="boolean")return e?"true":"false";if(typeof e=="string")return Br(e,i);if(typeof e=="number"){if(e===0)return 1/0/e>0?"0":"-0";var c=String(e);return a?Lr(e,c):c}if(typeof e=="bigint"){var l=String(e)+"n";return a?Lr(e,l):l}var d=typeof i.depth>"u"?5:i.depth;if(typeof n>"u"&&(n=0),n>=d&&d>0&&typeof e=="object")return Et(e)?"[Array]":"[Object]";var f=pi(i,n);if(typeof o>"u")o=[];else if(kr(o,e)>=0)return"[Circular]";function y(W,ye,je){if(ye&&(o=Jo.call(o),o.push(ye)),je){var me={depth:i.depth};return z(i,"quoteStyle")&&(me.quoteStyle=i.quoteStyle),t(W,me,n+1,o)}return t(W,i,n+1,o)}if(typeof e=="function"&&!xr(e)){var w=oi(e),p=$e(e,y);return"[Function"+(w?": "+w:" (anonymous)")+"]"+(p.length>0?" { "+M.call(p,", ")+" }":"")}if(Ur(e)){var h=ue?j.call(String(e),/^(Symbol\(.*\))_[^)]*$/,"$1"):bt.call(e);return typeof e=="object"&&!ue?Oe(h):h}if(ui(e)){for(var E="<"+Rr.call(String(e.nodeName)),S=e.attributes||[],I=0;I<S.length;I++)E+=" "+S[I].name+"="+_r(Qo(S[I].value),"double",i);return E+=">",e.childNodes&&e.childNodes.length&&(E+="..."),E+="</"+Rr.call(String(e.nodeName))+">",E}if(Et(e)){if(e.length===0)return"[]";var P=$e(e,y);return f&&!di(P)?"["+Ot(P,f)+"]":"[ "+M.call(P,", ")+" ]"}if(Yo(e)){var K=$e(e,y);return!("cause"in Error.prototype)&&"cause"in e&&!Pr.call(e,"cause")?"{ ["+String(e)+"] "+M.call(Ir.call("[cause]: "+y(e.cause),K),", ")+" }":K.length===0?"["+String(e)+"]":"{ ["+String(e)+"] "+M.call(K,", ")+" }"}if(typeof e=="object"&&s){if(Nr&&typeof e[Nr]=="function"&&vt)return vt(e,{depth:d-n});if(s!=="symbol"&&typeof e.inspect=="function")return e.inspect()}if(ii(e)){var Ce=[];return Er&&Er.call(e,function(W,ye){Ce.push(y(ye,e,!0)+" => "+y(W,e))}),Mr("Map",Me.call(e),Ce,f)}if(ci(e)){var qe=[];return Ar&&Ar.call(e,function(W){qe.push(y(W,e))}),Mr("Set",He.call(e),qe,f)}if(si(e))return At("WeakMap");if(li(e))return At("WeakSet");if(ai(e))return At("WeakRef");if(ei(e))return Oe(y(Number(e)));if(ri(e))return Oe(y(St.call(e)));if(ti(e))return Oe(Go.call(e));if(Zo(e))return Oe(y(String(e)));if(!Xo(e)&&!xr(e)){var ne=$e(e,y),Q=Dr?Dr(e)===Object.prototype:e instanceof Object||e.constructor===Object,pe=e instanceof Object?"":"null prototype",he=!Q&&D&&Object(e)===e&&D in e?gt.call(J(e),8,-1):pe?"Object":"",Ie=Q||typeof e.constructor!="function"?"":e.constructor.name?e.constructor.name+" ":"",U=Ie+(he||pe?"["+M.call(Ir.call([],he||[],pe||[]),": ")+"] ":"");return ne.length===0?U+"{}":f?U+"{"+Ot(ne,f)+"}":U+"{ "+M.call(ne,", ")+" }"}return String(e)};function _r(t,e,r){var n=(r.quoteStyle||e)==="double"?'"':"'";return n+t+n}function Qo(t){return j.call(String(t),/"/g,"&quot;")}function Et(t){return J(t)==="[object Array]"&&(!D||!(typeof t=="object"&&D in t))}function Xo(t){return J(t)==="[object Date]"&&(!D||!(typeof t=="object"&&D in t))}function xr(t){return J(t)==="[object RegExp]"&&(!D||!(typeof t=="object"&&D in t))}function Yo(t){return J(t)==="[object Error]"&&(!D||!(typeof t=="object"&&D in t))}function Zo(t){return J(t)==="[object String]"&&(!D||!(typeof t=="object"&&D in t))}function ei(t){return J(t)==="[object Number]"&&(!D||!(typeof t=="object"&&D in t))}function ti(t){return J(t)==="[object Boolean]"&&(!D||!(typeof t=="object"&&D in t))}function Ur(t){if(ue)return t&&typeof t=="object"&&t instanceof Symbol;if(typeof t=="symbol")return!0;if(!t||typeof t!="object"||!bt)return!1;try{return bt.call(t),!0}catch{}return!1}function ri(t){if(!t||typeof t!="object"||!St)return!1;try{return St.call(t),!0}catch{}return!1}var ni=Object.prototype.hasOwnProperty||function(t){return t in this};function z(t,e){return ni.call(t,e)}function J(t){return Wo.call(t)}function oi(t){if(t.name)return t.name;var e=jo.call(qo.call(t),/^function\s*([\w$]+)/);return e?e[1]:null}function kr(t,e){if(t.indexOf)return t.indexOf(e);for(var r=0,n=t.length;r<n;r++)if(t[r]===e)return r;return-1}function ii(t){if(!Me||!t||typeof t!="object")return!1;try{Me.call(t);try{He.call(t)}catch{return!0}return t instanceof Map}catch{}return!1}function si(t){if(!Ee||!t||typeof t!="object")return!1;try{Ee.call(t,Ee);try{Ae.call(t,Ae)}catch{return!0}return t instanceof WeakMap}catch{}return!1}function ai(t){if(!Or||!t||typeof t!="object")return!1;try{return Or.call(t),!0}catch{}return!1}function ci(t){if(!He||!t||typeof t!="object")return!1;try{He.call(t);try{Me.call(t)}catch{return!0}return t instanceof Set}catch{}return!1}function li(t){if(!Ae||!t||typeof t!="object")return!1;try{Ae.call(t,Ae);try{Ee.call(t,Ee)}catch{return!0}return t instanceof WeakSet}catch{}return!1}function ui(t){return!t||typeof t!="object"?!1:typeof HTMLElement<"u"&&t instanceof HTMLElement?!0:typeof t.nodeName=="string"&&typeof t.getAttribute=="function"}function Br(t,e){if(t.length>e.maxStringLength){var r=t.length-e.maxStringLength,n="... "+r+" more character"+(r>1?"s":"");return Br(gt.call(t,0,e.maxStringLength),e)+n}var o=j.call(j.call(t,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,fi);return _r(o,"single",e)}function fi(t){var e=t.charCodeAt(0),r={8:"b",9:"t",10:"n",12:"f",13:"r"}[e];return r?"\\"+r:"\\x"+(e<16?"0":"")+zo.call(e.toString(16))}function Oe(t){return"Object("+t+")"}function At(t){return t+" { ? }"}function Mr(t,e,r,n){var o=n?Ot(r,n):M.call(r,", ");return t+" ("+e+") {"+o+"}"}function di(t){for(var e=0;e<t.length;e++)if(kr(t[e],`
7
7
  `)>=0)return!1;return!0}function pi(t,e){var r;if(t.indent===" ")r=" ";else if(typeof t.indent=="number"&&t.indent>0)r=M.call(Array(t.indent+1)," ");else return null;return{base:r,prev:M.call(Array(e+1),r)}}function Ot(t,e){if(t.length===0)return"";var r=`
8
8
  `+e.prev+e.base;return r+M.call(t,","+r)+`
9
- `+e.prev}function $e(t,e){var r=Et(t),n=[];if(r){n.length=t.length;for(var o=0;o<t.length;o++)n[o]=z(t,o)?e(t[o],t):""}var i=typeof wt=="function"?wt(t):[],s;if(ue){s={};for(var a=0;a<i.length;a++)s["$"+i[a]]=i[a]}for(var c in t)z(t,c)&&(r&&String(Number(c))===c&&c<t.length||ue&&s["$"+c]instanceof Symbol||(Cr.call(/[^\w$]/,c)?n.push(e(c,t)+": "+e(t[c],t)):n.push(c+": "+e(t[c],t))));if(typeof wt=="function")for(var l=0;l<i.length;l++)Pr.call(t,i[l])&&n.push("["+e(i[l])+"]: "+e(t[i[l]],t));return n}var Rt=dt,fe=Bo,hi=Ko,yi=Rt("%TypeError%"),Ve=Rt("%WeakMap%",!0),Ge=Rt("%Map%",!0),mi=fe("WeakMap.prototype.get",!0),gi=fe("WeakMap.prototype.set",!0),Si=fe("WeakMap.prototype.has",!0),wi=fe("Map.prototype.get",!0),bi=fe("Map.prototype.set",!0),vi=fe("Map.prototype.has",!0),Ct=function(t,e){for(var r=t,n;(n=r.next)!==null;r=n)if(n.key===e)return r.next=n.next,n.next=t.next,t.next=n,n},Ei=function(t,e){var r=Ct(t,e);return r&&r.value},Ai=function(t,e,r){var n=Ct(t,e);n?n.value=r:t.next={key:e,next:t.next,value:r}},Oi=function(t,e){return!!Ct(t,e)},Ri=function(){var e,r,n,o={assert:function(i){if(!o.has(i))throw new yi("Side channel does not contain "+hi(i))},get:function(i){if(Ve&&i&&(typeof i=="object"||typeof i=="function")){if(e)return mi(e,i)}else if(Ge){if(r)return wi(r,i)}else if(n)return Ei(n,i)},has:function(i){if(Ve&&i&&(typeof i=="object"||typeof i=="function")){if(e)return Si(e,i)}else if(Ge){if(r)return vi(r,i)}else if(n)return Oi(n,i);return!1},set:function(i,s){Ve&&i&&(typeof i=="object"||typeof i=="function")?(e||(e=new Ve),gi(e,i,s)):Ge?(r||(r=new Ge),bi(r,i,s)):(n||(n={key:{},next:null}),Ai(n,i,s))}};return o},Ci=String.prototype.replace,Ii=/%20/g,It={RFC1738:"RFC1738",RFC3986:"RFC3986"},Tt={default:It.RFC3986,formatters:{RFC1738:function(t){return Ci.call(t,Ii,"+")},RFC3986:function(t){return String(t)}},RFC1738:It.RFC1738,RFC3986:It.RFC3986},Ti=Tt,Pt=Object.prototype.hasOwnProperty,ee=Array.isArray,H=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),Pi=function(e){for(;e.length>1;){var r=e.pop(),n=r.obj[r.prop];if(ee(n)){for(var o=[],i=0;i<n.length;++i)typeof n[i]<"u"&&o.push(n[i]);r.obj[r.prop]=o}}},Hr=function(e,r){for(var n=r&&r.plainObjects?Object.create(null):{},o=0;o<e.length;++o)typeof e[o]<"u"&&(n[o]=e[o]);return n},Di=function t(e,r,n){if(!r)return e;if(typeof r!="object"){if(ee(e))e.push(r);else if(e&&typeof e=="object")(n&&(n.plainObjects||n.allowPrototypes)||!Pt.call(Object.prototype,r))&&(e[r]=!0);else return[e,r];return e}if(!e||typeof e!="object")return[e].concat(r);var o=e;return ee(e)&&!ee(r)&&(o=Hr(e,n)),ee(e)&&ee(r)?(r.forEach(function(i,s){if(Pt.call(e,s)){var a=e[s];a&&typeof a=="object"&&i&&typeof i=="object"?e[s]=t(a,i,n):e.push(i)}else e[s]=i}),e):Object.keys(r).reduce(function(i,s){var a=r[s];return Pt.call(i,s)?i[s]=t(i[s],a,n):i[s]=a,i},o)},Li=function(e,r){return Object.keys(r).reduce(function(n,o){return n[o]=r[o],n},e)},Fi=function(t,e,r){var n=t.replace(/\+/g," ");if(r==="iso-8859-1")return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch{return n}},Ni=function(e,r,n,o,i){if(e.length===0)return e;var s=e;if(typeof e=="symbol"?s=Symbol.prototype.toString.call(e):typeof e!="string"&&(s=String(e)),n==="iso-8859-1")return escape(s).replace(/%u[0-9a-f]{4}/gi,function(d){return"%26%23"+parseInt(d.slice(2),16)+"%3B"});for(var a="",c=0;c<s.length;++c){var l=s.charCodeAt(c);if(l===45||l===46||l===95||l===126||l>=48&&l<=57||l>=65&&l<=90||l>=97&&l<=122||i===Ti.RFC1738&&(l===40||l===41)){a+=s.charAt(c);continue}if(l<128){a=a+H[l];continue}if(l<2048){a=a+(H[192|l>>6]+H[128|l&63]);continue}if(l<55296||l>=57344){a=a+(H[224|l>>12]+H[128|l>>6&63]+H[128|l&63]);continue}c+=1,l=65536+((l&1023)<<10|s.charCodeAt(c)&1023),a+=H[240|l>>18]+H[128|l>>12&63]+H[128|l>>6&63]+H[128|l&63]}return a},_i=function(e){for(var r=[{obj:{o:e},prop:"o"}],n=[],o=0;o<r.length;++o)for(var i=r[o],s=i.obj[i.prop],a=Object.keys(s),c=0;c<a.length;++c){var l=a[c],d=s[l];typeof d=="object"&&d!==null&&n.indexOf(d)===-1&&(r.push({obj:s,prop:l}),n.push(d))}return Pi(r),e},xi=function(e){return Object.prototype.toString.call(e)==="[object RegExp]"},Ui=function(e){return!e||typeof e!="object"?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},ki=function(e,r){return[].concat(e,r)},Bi=function(e,r){if(ee(e)){for(var n=[],o=0;o<e.length;o+=1)n.push(r(e[o]));return n}return r(e)},$r={arrayToObject:Hr,assign:Li,combine:ki,compact:_i,decode:Fi,encode:Ni,isBuffer:Ui,isRegExp:xi,maybeMap:Bi,merge:Di},Vr=Ri,We=$r,Re=Tt,Mi=Object.prototype.hasOwnProperty,Gr={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},G=Array.isArray,Hi=Array.prototype.push,Wr=function(t,e){Hi.apply(t,G(e)?e:[e])},$i=Date.prototype.toISOString,qr=Re.default,L={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:We.encode,encodeValuesOnly:!1,format:qr,formatter:Re.formatters[qr],indices:!1,serializeDate:function(e){return $i.call(e)},skipNulls:!1,strictNullHandling:!1},Vi=function(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="symbol"||typeof e=="bigint"},Dt={},Gi=function t(e,r,n,o,i,s,a,c,l,d,f,y,w,p,h,E){for(var S=e,I=E,P=0,K=!1;(I=I.get(Dt))!==void 0&&!K;){var Ce=I.get(e);if(P+=1,typeof Ce<"u"){if(Ce===P)throw new RangeError("Cyclic object value");K=!0}typeof I.get(Dt)>"u"&&(P=0)}if(typeof c=="function"?S=c(r,S):S instanceof Date?S=f(S):n==="comma"&&G(S)&&(S=We.maybeMap(S,function(me){return me instanceof Date?f(me):me})),S===null){if(i)return a&&!p?a(r,L.encoder,h,"key",y):r;S=""}if(Vi(S)||We.isBuffer(S)){if(a){var qe=p?r:a(r,L.encoder,h,"key",y);return[w(qe)+"="+w(a(S,L.encoder,h,"value",y))]}return[w(r)+"="+w(String(S))]}var ne=[];if(typeof S>"u")return ne;var Q;if(n==="comma"&&G(S))p&&a&&(S=We.maybeMap(S,a)),Q=[{value:S.length>0?S.join(",")||null:void 0}];else if(G(c))Q=c;else{var pe=Object.keys(S);Q=l?pe.sort(l):pe}for(var he=o&&G(S)&&S.length===1?r+"[]":r,Ie=0;Ie<Q.length;++Ie){var U=Q[Ie],W=typeof U=="object"&&typeof U.value<"u"?U.value:S[U];if(!(s&&W===null)){var ye=G(S)?typeof n=="function"?n(he,U):he:he+(d?"."+U:"["+U+"]");E.set(e,P);var je=Vr();je.set(Dt,E),Wr(ne,t(W,ye,n,o,i,s,n==="comma"&&p&&G(S)?null:a,c,l,d,f,y,w,p,h,je))}}return ne},Wi=function(e){if(!e)return L;if(e.encoder!==null&&typeof e.encoder<"u"&&typeof e.encoder!="function")throw new TypeError("Encoder has to be a function.");var r=e.charset||L.charset;if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Re.default;if(typeof e.format<"u"){if(!Mi.call(Re.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var o=Re.formatters[n],i=L.filter;return(typeof e.filter=="function"||G(e.filter))&&(i=e.filter),{addQueryPrefix:typeof e.addQueryPrefix=="boolean"?e.addQueryPrefix:L.addQueryPrefix,allowDots:typeof e.allowDots>"u"?L.allowDots:!!e.allowDots,charset:r,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:L.charsetSentinel,delimiter:typeof e.delimiter>"u"?L.delimiter:e.delimiter,encode:typeof e.encode=="boolean"?e.encode:L.encode,encoder:typeof e.encoder=="function"?e.encoder:L.encoder,encodeValuesOnly:typeof e.encodeValuesOnly=="boolean"?e.encodeValuesOnly:L.encodeValuesOnly,filter:i,format:n,formatter:o,serializeDate:typeof e.serializeDate=="function"?e.serializeDate:L.serializeDate,skipNulls:typeof e.skipNulls=="boolean"?e.skipNulls:L.skipNulls,sort:typeof e.sort=="function"?e.sort:null,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:L.strictNullHandling}},qi=function(t,e){var r=t,n=Wi(e),o,i;typeof n.filter=="function"?(i=n.filter,r=i("",r)):G(n.filter)&&(i=n.filter,o=i);var s=[];if(typeof r!="object"||r===null)return"";var a;e&&e.arrayFormat in Gr?a=e.arrayFormat:e&&"indices"in e?a=e.indices?"indices":"repeat":a="indices";var c=Gr[a];if(e&&"commaRoundTrip"in e&&typeof e.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var l=c==="comma"&&e&&e.commaRoundTrip;o||(o=Object.keys(r)),n.sort&&o.sort(n.sort);for(var d=Vr(),f=0;f<o.length;++f){var y=o[f];n.skipNulls&&r[y]===null||Wr(s,Gi(r[y],y,c,l,n.strictNullHandling,n.skipNulls,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,d))}var w=s.join(n.delimiter),p=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),w.length>0?p+w:""},de=$r,Lt=Object.prototype.hasOwnProperty,ji=Array.isArray,C={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:de.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},zi=function(t){return t.replace(/&#(\d+);/g,function(e,r){return String.fromCharCode(parseInt(r,10))})},jr=function(t,e){return t&&typeof t=="string"&&e.comma&&t.indexOf(",")>-1?t.split(","):t},Ji="utf8=%26%2310003%3B",Ki="utf8=%E2%9C%93",Qi=function(e,r){var n={__proto__:null},o=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=r.parameterLimit===1/0?void 0:r.parameterLimit,s=o.split(r.delimiter,i),a=-1,c,l=r.charset;if(r.charsetSentinel)for(c=0;c<s.length;++c)s[c].indexOf("utf8=")===0&&(s[c]===Ki?l="utf-8":s[c]===Ji&&(l="iso-8859-1"),a=c,c=s.length);for(c=0;c<s.length;++c)if(c!==a){var d=s[c],f=d.indexOf("]="),y=f===-1?d.indexOf("="):f+1,w,p;y===-1?(w=r.decoder(d,C.decoder,l,"key"),p=r.strictNullHandling?null:""):(w=r.decoder(d.slice(0,y),C.decoder,l,"key"),p=de.maybeMap(jr(d.slice(y+1),r),function(h){return r.decoder(h,C.decoder,l,"value")})),p&&r.interpretNumericEntities&&l==="iso-8859-1"&&(p=zi(p)),d.indexOf("[]=")>-1&&(p=ji(p)?[p]:p),Lt.call(n,w)?n[w]=de.combine(n[w],p):n[w]=p}return n},Xi=function(t,e,r,n){for(var o=n?e:jr(e,r),i=t.length-1;i>=0;--i){var s,a=t[i];if(a==="[]"&&r.parseArrays)s=[].concat(o);else{s=r.plainObjects?Object.create(null):{};var c=a.charAt(0)==="["&&a.charAt(a.length-1)==="]"?a.slice(1,-1):a,l=parseInt(c,10);!r.parseArrays&&c===""?s={0:o}:!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(s=[],s[l]=o):c!=="__proto__"&&(s[c]=o)}o=s}return o},Yi=function(e,r,n,o){if(e){var i=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,s=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,c=n.depth>0&&s.exec(i),l=c?i.slice(0,c.index):i,d=[];if(l){if(!n.plainObjects&&Lt.call(Object.prototype,l)&&!n.allowPrototypes)return;d.push(l)}for(var f=0;n.depth>0&&(c=a.exec(i))!==null&&f<n.depth;){if(f+=1,!n.plainObjects&&Lt.call(Object.prototype,c[1].slice(1,-1))&&!n.allowPrototypes)return;d.push(c[1])}return c&&d.push("["+i.slice(c.index)+"]"),Xi(d,r,n,o)}},Zi=function(e){if(!e)return C;if(e.decoder!==null&&e.decoder!==void 0&&typeof e.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=typeof e.charset>"u"?C.charset:e.charset;return{allowDots:typeof e.allowDots>"u"?C.allowDots:!!e.allowDots,allowPrototypes:typeof e.allowPrototypes=="boolean"?e.allowPrototypes:C.allowPrototypes,allowSparse:typeof e.allowSparse=="boolean"?e.allowSparse:C.allowSparse,arrayLimit:typeof e.arrayLimit=="number"?e.arrayLimit:C.arrayLimit,charset:r,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:C.charsetSentinel,comma:typeof e.comma=="boolean"?e.comma:C.comma,decoder:typeof e.decoder=="function"?e.decoder:C.decoder,delimiter:typeof e.delimiter=="string"||de.isRegExp(e.delimiter)?e.delimiter:C.delimiter,depth:typeof e.depth=="number"||e.depth===!1?+e.depth:C.depth,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities=="boolean"?e.interpretNumericEntities:C.interpretNumericEntities,parameterLimit:typeof e.parameterLimit=="number"?e.parameterLimit:C.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects=="boolean"?e.plainObjects:C.plainObjects,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:C.strictNullHandling}},es=function(t,e){var r=Zi(e);if(t===""||t===null||typeof t>"u")return r.plainObjects?Object.create(null):{};for(var n=typeof t=="string"?Qi(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),s=0;s<i.length;++s){var a=i[s],c=Yi(a,n[a],r,typeof t=="string");o=de.merge(o,c,r)}return r.allowSparse===!0?o:de.compact(o)},ts=qi,rs=es,ns=Tt,os={formats:ns,parse:rs,stringify:ts};const is=lo(os);class zr{constructor(e){m(this,"axiosInstance");this.axiosInstance=O.create({baseURL:e,timeout:12e4})}Request(e){return new Promise((r,n)=>{this.axiosInstance.request(e).then(o=>r(o)).catch(o=>n(o))})}Get(e,r,n){return new Promise((o,i)=>{r&&(n?n.params=r:n={params:r}),n&&(n.paramsSerializer={serialize:(s,a)=>is.stringify(s,{indices:!1})}),this.axiosInstance.get(e,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Post(e,r,n){return new Promise((o,i)=>{this.axiosInstance.post(e,r,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Put(e,r,n){return new Promise((o,i)=>{this.axiosInstance.put(e,r,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Delete(e,r,n){return new Promise((o,i)=>{r&&(n?n.data=r:n={data:r}),this.axiosInstance.delete(e,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}}class ss{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}onStartSuccess(e){console.debug("onStartSuccess:",e)}onDataChannelMessage(e){console.debug("onDataChannelMessage:",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}var g=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.AUDIO=1]="AUDIO",t[t.VIDEO=2]="VIDEO",t[t.RTSP_PULL=3]="RTSP_PULL",t[t.AUDIO_PUSH=4]="AUDIO_PUSH",t[t.VIDEO_PUSH=5]="VIDEO_PUSH",t[t.AUDIO_HALF=6]="AUDIO_HALF",t[t.VIDEO_HALF=7]="VIDEO_HALF",t))(g||{}),te=(t=>(t.FRONT_FACING="user",t.BACK_FACING="environment",t))(te||{});class Ft{constructor(e){m(this,"peerConnection");m(this,"sessionListener",new ss);m(this,"isCallOut",!1);m(this,"sessionType",g.UNKNOWN);m(this,"localStream");m(this,"remoteStream");m(this,"dataChannel");m(this,"hasSetRemoteSdp",!1);m(this,"facingMode",te.FRONT_FACING);m(this,"facingChanging",!1);m(this,"muted",!1);m(this,"openCamera",!1);m(this,"desktopSharing",!1);this.sessionType=e}setListener(e){this.sessionListener=e}start(e,r){if(!e&&!r){this.error(new Error("start failed, remoteSdp is null."));return}switch(this.isCallOut=e,this.hasSetRemoteSdp=!1,this.facingMode=te.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.desktopSharing=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{switch(this.sessionType){case g.AUDIO_PUSH:case g.VIDEO_PUSH:case g.AUDIO_HALF:case g.VIDEO_HALF:this.createDataChannel()}e?(console.debug("webrtc call out"),this.peerConnection.createOffer().then(n=>{console.debug("webrtc createOffer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(o=>{this.error(o)})}).catch(n=>{this.error(n)})):(console.debug("webrtc call in: ",r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{console.debug("webrtc setRemoteDescription success"),this.peerConnection.createAnswer().then(n=>{console.debug("webrtc createAnswer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(o=>{this.error(o)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicegatheringstatechange=()=>{var n;console.debug("webrtc onicegatheringstatechange",(n=this.peerConnection)==null?void 0:n.iceGatheringState),this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{console.debug("webrtc ontrack");for(let o=0;o<n.streams.length;o++)this.remoteStream?n.streams[o].getTracks().forEach(i=>{var s;(s=this.remoteStream)==null||s.addTrack(i)}):this.remoteStream=new MediaStream(n.streams[o]);this.sessionListener.onAddRemoteStream(this.remoteStream)},this.peerConnection.oniceconnectionstatechange=n=>{var o,i,s,a,c;console.debug("oniceconnectionstatechange",(o=this.peerConnection)==null?void 0:o.iceConnectionState),(((i=this.peerConnection)==null?void 0:i.iceConnectionState)=="completed"||((s=this.peerConnection)==null?void 0:s.iceConnectionState)=="disconnected"||((a=this.peerConnection)==null?void 0:a.iceConnectionState)=="failed"||((c=this.peerConnection)==null?void 0:c.iceConnectionState)=="closed")&&(this.stop(),this.sessionListener.onError(new Error("session closed.")))},this.sessionType){case g.RTSP_PULL:this.addTransceivers(),this.createDataChannel();break;case g.AUDIO_PUSH:case g.VIDEO_PUSH:case g.AUDIO_HALF:case g.VIDEO_HALF:case g.VIDEO:case g.AUDIO:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){e&&e!==""&&this.peerConnection&&this.isCallOut&&!this.hasSetRemoteSdp&&(this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{console.debug("webrtc setRemoteDescription success")}).catch(r=>{this.error(r),this.hasSetRemoteSdp=!1}))}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{console.debug("webrtc addIceCandidate success")}).catch(n=>console.log(n))})}sendStringData(e){this.dataChannel&&this.dataChannel.send(e)}stop(){var e;if(console.debug("webrtc stop"),(this.sessionType==g.VIDEO_PUSH||this.sessionType==g.AUDIO_PUSH||this.sessionType==g.RTSP_PULL)&&this.sendStringData("close"),(e=this.peerConnection)==null||e.close(),this.peerConnection=void 0,this.localStream){for(let r of this.localStream.getTracks())this.localStream.removeTrack(r),r.stop();this.localStream=void 0}this.remoteStream=void 0,this.desktopSharing=!1}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==g.VIDEO&&this.sessionType!==g.VIDEO_PUSH){r(new Error("not video call"));return}if(!this.localStream||this.localStream.getVideoTracks().length<=0){r(new Error("not in calling or not video call"));return}if(this.facingChanging){r(new Error("camera switching in progress"));return}if(!/mobile/i.test(navigator.userAgent)){r(new Error("not mobile device"));return}this.facingChanging=!0,this.changeCameraLocalMedia().then(()=>e(this.facingMode)).catch(n=>r(n))})}changeMuted(){return new Promise((e,r)=>{!this.localStream||this.localStream.getAudioTracks().length<=0?r(new Error("not in calling")):(this.localStream.getAudioTracks().forEach(n=>{n.enabled=!n.enabled,this.muted=!n.enabled}),e(this.muted))})}changeCameraOpened(){return new Promise((e,r)=>{!this.localStream||this.localStream.getVideoTracks().length<=0?r(new Error("not in video calling")):(this.localStream.getVideoTracks().forEach(n=>{n.enabled=!n.enabled,this.openCamera=!n.enabled}),e(this.openCamera))})}startDesktopShare(){return new Promise((e,r)=>{if(this.desktopSharing){r(new Error("desktop sharing has opened"));return}if(this.sessionType!=g.VIDEO&&this.sessionType!=g.VIDEO_PUSH){r(new Error("desktop sharing not in video calling"));return}if(!this.localStream){r(new Error("localStream undefined"));return}navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia?(this.desktopSharing=!0,navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0}).then(n=>{let o=this.changeVideoTrack(n,()=>{this.stopDesktopShare(),this.sessionListener.onStopDesktopShare()});o?(this.desktopSharing=!1,r(o)):e()}).catch(n=>{this.desktopSharing=!1,r(n)})):r(new Error("error: browsers unsupported DesktopShare"))})}stopDesktopShare(){if(!(!this.peerConnection||!this.localStream)&&this.desktopSharing){for(let e of this.localStream.getVideoTracks())this.localStream.removeTrack(e),e.stop();navigator.mediaDevices.getUserMedia({audio:!1,video:{height:{exact:720},width:{exact:1280}}}).then(e=>{this.changeVideoTrack(e),this.desktopSharing=!1}).catch(e=>{this.desktopSharing=!1,console.debug("stopDesktopShare getUserMedia failed: ",e)})}}changeVideoTrack(e,r){if(!this.localStream||!this.peerConnection){for(let n of e.getTracks())e.removeTrack(n),n.stop();return new Error("localStream undefined or peerConnection undefined")}for(let n of this.localStream.getVideoTracks())this.localStream.removeTrack(n),n.stop();for(let n of e.getTracks())e.removeTrack(n),n.kind=="video"?(this.localStream.addTrack(n),r&&(n.onended=o=>{r()})):n.stop();for(let n of this.peerConnection.getSenders())n.track&&n.track.kind==="video"&&n.replaceTrack(this.localStream.getVideoTracks()[0]).then(()=>{}).catch(o=>{console.error(o)})}error(e){console.debug("webrtc error: ",e),this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e={audio:{echoCancellation:!0,noiseSuppression:!0}};switch(this.sessionType){case g.VIDEO:case g.VIDEO_PUSH:case g.VIDEO_HALF:e.video={height:{exact:720},width:{exact:1280}};break}navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e).then(r=>{this.getMediaSuccess(r)}).catch(r=>{this.getMediaFailed(r)}):this.error(new Error("Browser does not support WebRTC"))}getMediaSuccess(e){console.debug("webrtc getMediaSuccess"),this.localStream=e,(this.sessionType===g.VIDEO||this.sessionType===g.VIDEO_PUSH||this.sessionType===g.VIDEO_HALF)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case g.AUDIO_PUSH:case g.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break;default:this.peerConnection.addTrack(r,e)}}),this.muted=!1}getMediaFailed(e){if(console.debug("webrtc getMediaFailed failed"),this.sessionType===g.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===g.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO_PUSH,this.gotLocalMedia();return}else if(this.sessionType===g.VIDEO_HALF){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO_HALF,this.gotLocalMedia();return}this.error(e)}createDataChannel(){this.peerConnection&&(this.isCallOut?(this.dataChannel=this.peerConnection.createDataChannel("command_channel"),this.dataChannel.onmessage=e=>{this.onDataChannelReceive(e.data)}):this.peerConnection.ondatachannel=e=>{this.dataChannel=e.channel,this.dataChannel.onmessage=r=>{this.onDataChannelReceive(r.data)}})}onDataChannelReceive(e){if(e==="close"){console.debug("data channel receive from server: close"),this.dataChannel=void 0,this.stop();return}(this.sessionType==g.VIDEO_HALF||this.sessionType==g.AUDIO_HALF)&&this.sessionListener.onDataChannelMessage(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===te.FRONT_FACING?n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:1280},width:{exact:720},facingMode:"environment"}}:n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280},facingMode:"user"}},navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)navigator.mediaDevices.getUserMedia(n).then(o=>{this.changeCameraSuccess(o),e()}).catch(o=>{this.changeCameraFailed(o),r(o)});else{let o=new Error("Browser does not support WebRTC");this.changeCameraFailed(o),r(new Error("Browser does not support WebRTC"))}})}changeCameraSuccess(e){if(!this.localStream){e.getTracks().forEach(r=>{r.stop()}),this.facingChanging=!1;return}this.localStream.getVideoTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),e.getVideoTracks().forEach(r=>{this.localStream.addTrack(r)}),this.peerConnection.getSenders().forEach(r=>{r.track&&r.track.kind==="video"&&r.replaceTrack(e.getVideoTracks()[0]).then(()=>{}).catch(n=>{console.log(n)})}),this.facingMode===te.FRONT_FACING?this.facingMode=te.BACK_FACING:this.facingMode=te.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class as{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Jr{constructor(e,r){m(this,"url");m(this,"offerSdp");this.url=e,this.offerSdp=r}}const cs="/media-server/video-play/webrtc";class ls{constructor(e,r){m(this,"rtspUrl");m(this,"webrtcSession",new Ft(g.RTSP_PULL));m(this,"sessionListener",new as);m(this,"httpClient");this.rtspUrl=e,this.httpClient=r,this.webrtcSession.setListener(this)}setRtspPullSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("rtsp offer:",e.sdp),this.httpClient.Post(cs,new Jr(this.rtspUrl,e.sdp??"")).then(r=>{var n,o,i,s;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("rtsp answer",(n=r.data)==null?void 0:n.sdp),console.debug("rtsp answer",(o=r.data)==null?void 0:o.candidateList),this.webrtcSession.setRemoteSdp(((i=r.data)==null?void 0:i.sdp)??""),this.webrtcSession.addRemoteCandidate(((s=r.data)==null?void 0:s.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}onDataChannelMessage(e){}onStopDesktopShare(){}}var A=(t=>(t[t.OFFLINE=-1]="OFFLINE",t[t.IDLE=0]="IDLE",t[t.TRY=1]="TRY",t[t.RING=2]="RING",t[t.TALK=3]="TALK",t))(A||{}),F=(t=>(t.VIDEO="video",t.AUDIO="audio",t))(F||{}),$=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))($||{}),re=(t=>(t.IN="in",t.OUT="out",t))(re||{}),_=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(_||{});function Kr(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function us(){return"browser-"+fs()+ds(6)}function fs(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function ds(t){let e="",r=["0","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];for(let n=0;n<t;n++)e+=r[Math.floor(Math.random()*(r.length-1))];return e}class ps{constructor(e,r,n){m(this,"tel");m(this,"mediaType");m(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Qr{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onAnswer(){console.debug("onAnswer")}onClose(e){console.debug("onClose:",e)}onError(e){console.debug("onError:",e)}onHangup(e){console.debug("onHangup:",e)}onNewCall(e){console.debug("onNewCall:",e)}onRing(){console.debug("onRing")}onInitResult(e){console.debug("onInitResult: ",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}class Xr{constructor(e,r,n){m(this,"tel","");m(this,"status",A.OFFLINE);m(this,"mediaType",F.AUDIO);m(this,"callMode",$.FULL);m(this,"callDirect",re.OUT);m(this,"called","");m(this,"callId");m(this,"remoteSdp");m(this,"candidate");m(this,"ringBackTone",new Audio("sound/ringbacktone.wav"));m(this,"ringtone",new Audio("sound/ringtone.wav"));m(this,"dtmfAudio",new Audio("sound/dtmf.wav"));m(this,"ws");m(this,"wsConnected",!1);m(this,"closeBySelf",!1);m(this,"webrtcSession");m(this,"sessionListener",new Qr);m(this,"wsUrl");m(this,"accountId");this.tel=r??"",this.wsUrl=e,this.accountId=n,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}audioCall(e){this.makeCall(e)}videoCall(e){this.makeCall(e,F.VIDEO)}answer(){var r;if(this.status!=A.RING){console.debug("session is not ring state");return}if(this.callDirect!=re.IN){console.debug("session is call out, not allow answer");return}let e;this.callMode==$.HALF?e=F.VIDEO==this.mediaType?g.VIDEO_HALF:g.AUDIO_HALF:e=F.VIDEO==this.mediaType?g.VIDEO:g.AUDIO,this.webrtcCreate(e),(r=this.webrtcSession)==null||r.start(!1,this.remoteSdp)}hangup(){this.status<=A.IDLE||(this.status==A.TALK?this.sendHangup(this.callId??""):this.callDirect==re.IN?this.sendHangup(this.callId??"",488):this.sendHangup(this.callId??"",801),this.close())}dtmf(e){return this.status!==A.TALK?!1:(this.sendDtmf(e),!0)}changeCamera(){return new Promise((e,r)=>{var n;this.webrtcSession||r(new Error("webrtc session not start")),(n=this.webrtcSession)==null||n.changeFacing().then(o=>e(o)).catch(o=>r(o))})}changeMuted(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeMuted().then(n=>e(n)).catch(n=>r(n))})}changeCameraOpened(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeCameraOpened().then(n=>e(n)).catch(n=>r(n))})}startDesktopShare(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.status!=A.TALK&&r(new Error(`session status[${this.status}] not talk`)),this.webrtcSession.startDesktopShare().then(()=>e()).catch(n=>r(n))})}stopDesktopShare(){this.webrtcSession&&this.status==A.TALK&&this.webrtcSession.stopDesktopShare()}destroy(){var e;this.closeBySelf=!0,this.hangup(),this.close(),(e=this.ws)==null||e.close()}makeCall(e,r=F.AUDIO,n=$.FULL){var o;try{if(!Kr()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}if(this.status==A.OFFLINE){console.debug("The initialization has not been completed yet. Please try again later"),this.sessionListener.onError(new Error("The initialization has not been completed yet. Please try again later"));return}this.status>A.IDLE&&(console.debug("Another call is currently in progress, hangup it"),this.hangup()),this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=re.OUT,this.callId=us();let i;this.callMode==$.HALF?i=F.VIDEO==r?g.VIDEO_HALF:g.AUDIO_HALF:i=F.VIDEO==r?g.VIDEO:g.AUDIO,this.webrtcCreate(i),(o=this.webrtcSession)==null||o.start(!0),this.status=A.TRY}catch(i){this.status=A.IDLE,this.sessionListener.onError(new Error(""+i))}}close(){this.webrtcClose();try{this.ringtone.pause(),this.ringBackTone.pause()}catch(e){console.debug("FullSession.close: ",e)}this.status=A.IDLE}websocketInit(e){this.ws=new WebSocket(e),this.closeBySelf=!1,this.ws.onopen=()=>{console.debug("ws connect success"),this.wsConnected=!0,this.sendLogin()},this.ws.onclose=r=>{console.error("ws on close: ",r),this.wsConnected=!1,this.close(),this.status=A.OFFLINE,this.closeBySelf||this.sessionListener.onClose(new Error(r.reason)),this.ws=void 0},this.ws.onmessage=r=>{try{let n=JSON.parse(r.data);switch(console.debug("receive msg from server <<<<<<<<<<<<<<<",n),n.type){case _.Invite:this.inviteHandler(n);break;case _.ANSWER:this.answerHandler(n);break;case _.RING:this.ringHandler(n);break;case _.HANGUP:this.hangupHandler(n);break;case _.LOGIN:this.loginHandler(n);break}}catch(n){console.error("receive msg from server, but process error: ",n,r)}},this.ws.onerror=r=>{console.error("ws on error: ",r)}}sendTo(e){var r;try{this.wsConnected?(console.debug("send msg to server >>>>>>>>>>>>>>>>>> ",e),(r=this.ws)==null||r.send(JSON.stringify(e))):console.error("ws not connected.")}catch(n){console.debug("FullSession sendTo error: ",n)}}sendLogin(){this.sendTo({type:_.LOGIN,username:this.tel,userAgent:this.getUserAgent(),accountId:this.accountId})}sendLogout(){this.sendTo({type:_.LOGOUT,username:this.tel}),this.status=A.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:_.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=A.TRY}sendRing(){this.sendTo({type:_.RING,callId:this.callId,code:180}),this.status=A.RING}sendAnswer(e){this.sendTo({type:_.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=A.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:_.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:_.HANGUP,callId:e,code:r}),e==this.callId&&(this.status=A.IDLE,this.callId=void 0)}loginHandler(e){var r;if(e.code!=200){(r=this.ws)==null||r.close(),this.wsConnected=!1,this.ws=void 0,this.status=A.OFFLINE,this.sessionListener.onInitResult(!1);return}this.tel=e.username??"",this.status=A.IDLE,this.sessionListener.onInitResult(!0)}inviteHandler(e){if(!e.callId){console.debug("receive invite, but callId is null.");return}if(!Kr()){console.debug("receive invite, but unsupported webrtc."),this.sendHangup(e.callId,803);return}if(this.status>A.IDLE){e.callId!=this.callId?(console.debug("receive invite, but busy."),this.sendHangup(e.callId,486)):console.debug("receive re invite. not process");return}this.callId=e.callId,this.mediaType=e.mediaType??F.AUDIO,this.callMode=e.callMode??$.FULL,this.called=e.from??"",this.callDirect=re.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{}),this.sessionListener.onNewCall(new ps(this.called,this.mediaType,this.callMode))}ringHandler(e){var r,n;!e.callId||e.callId!=this.callId||(e.code==183?(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[])):(this.ringBackTone.currentTime=0,this.ringBackTone.play().then(()=>{}).catch(()=>{})),this.sessionListener.onRing(),this.status=A.RING)}answerHandler(e){var r,n;!e.callId||e.callId!=this.callId||(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[]),this.sessionListener.onAnswer(),this.status=A.TALK)}hangupHandler(e){!e.callId||e.callId!=this.callId||(this.close(),this.sessionListener.onHangup(e.code))}getUserAgent(){return navigator.platform.indexOf("Win")>=0?"windows":"phone"}webrtcCreate(e){this.webrtcClose(),this.webrtcSession=new Ft(e),this.webrtcSession.setListener(this)}webrtcClose(){var e;(e=this.webrtcSession)==null||e.stop(),this.webrtcSession=void 0}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.close(),this.callDirect==re.OUT&&this.hangup(),this.sessionListener.onError(e)}onStartSuccess(e){var r;e.type=="answer"?(this.sendAnswer(e.sdp??""),(r=this.webrtcSession)==null||r.addRemoteCandidate(this.candidate??[])):e.type=="offer"&&this.sendInvite(e.sdp??"")}onDataChannelMessage(e){}onStopDesktopShare(){this.sessionListener.onStopDesktopShare()}}class hs{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}const ys="/media-server/broadcast/webrtc";class ms{constructor(e,r,n){m(this,"tel");m(this,"mediaType");m(this,"webrtcSession");m(this,"sessionListener",new hs);m(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===F.VIDEO?F.VIDEO:F.AUDIO,this.webrtcSession=new Ft(n==F.VIDEO?g.VIDEO_PUSH:g.AUDIO_PUSH),this.webrtcSession.setListener(this)}setBroadcastSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}startDesktopShare(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.startDesktopShare().then(()=>e()).catch(n=>r(n))})}stopDesktopShare(){this.webrtcSession&&this.webrtcSession.stopDesktopShare()}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("offer:",e.sdp),this.httpClient.Post(ys,new Jr(this.tel,e.sdp??"")).then(r=>{var n,o,i;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("answer",(n=r.data)==null?void 0:n.sdp),this.webrtcSession.setRemoteSdp(((o=r.data)==null?void 0:o.sdp)??""),this.webrtcSession.addRemoteCandidate(((i=r.data)==null?void 0:i.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}onDataChannelMessage(e){}onStopDesktopShare(){this.sessionListener.onStopDesktopShare()}}var Nt=(t=>(t.TB_REQUEST="tb_request",t.TB_GRANTED="tb_granted",t.TB_TAKEN="tb_taken",t.TB_DENY="tb_deny",t.TB_RELEASE="tb_release",t.TB_IDLE="tb_idle",t.TB_REVOKE="tb_revoke",t))(Nt||{});class gs extends Qr{onTbcpMessage(e){console.debug("onTbcpMessage:",e)}}class Ss extends Xr{constructor(r,n,o){super(r,n,o);m(this,"sessionListener",new gs)}setCallSessionListener(r){this.sessionListener=r}audioHalfCall(r){this.makeCall(r,F.AUDIO,$.HALF)}videoHalfCall(r){this.makeCall(r,F.VIDEO,$.HALF)}tbcpRequest(){var r;this.callMode==$.HALF&&this.status==A.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:Nt.TB_REQUEST})))}tbcpRelease(){var r;this.callMode==$.HALF&&this.status==A.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:Nt.TB_RELEASE})))}onDataChannelMessage(r){try{this.sessionListener.onTbcpMessage(JSON.parse(r))}catch(n){console.debug("onDataChannelMessage err: ",n,r)}}}let _t=new zr("/"),Yr="/media-server/ws/voip",Zr="/media-server/ws/b-trun-c",xt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Yr),Ut=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Zr);function ws(t){_t=new zr(t)}function bs(t){return new ls(t,_t)}function vs(t,e){return new ms(t,_t,e)}function Es(t){xt=new URL(t),xt.pathname=Yr,Ut=new URL(t),Ut.pathname=Zr}function As(t){return new Xr(xt.toString(),t)}function Os(t,e){return new Ss(Ut.toString(),t,e)}T.createAppCallSession=Os,T.createBroadcastSession=vs,T.createCallSession=As,T.createRtspPullSession=bs,T.videoModuleInit=ws,T.voipModuleInit=Es,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
9
+ `+e.prev}function $e(t,e){var r=Et(t),n=[];if(r){n.length=t.length;for(var o=0;o<t.length;o++)n[o]=z(t,o)?e(t[o],t):""}var i=typeof wt=="function"?wt(t):[],s;if(ue){s={};for(var a=0;a<i.length;a++)s["$"+i[a]]=i[a]}for(var c in t)z(t,c)&&(r&&String(Number(c))===c&&c<t.length||ue&&s["$"+c]instanceof Symbol||(Cr.call(/[^\w$]/,c)?n.push(e(c,t)+": "+e(t[c],t)):n.push(c+": "+e(t[c],t))));if(typeof wt=="function")for(var l=0;l<i.length;l++)Pr.call(t,i[l])&&n.push("["+e(i[l])+"]: "+e(t[i[l]],t));return n}var Rt=dt,fe=Bo,hi=Ko,yi=Rt("%TypeError%"),Ve=Rt("%WeakMap%",!0),Ge=Rt("%Map%",!0),mi=fe("WeakMap.prototype.get",!0),gi=fe("WeakMap.prototype.set",!0),Si=fe("WeakMap.prototype.has",!0),wi=fe("Map.prototype.get",!0),bi=fe("Map.prototype.set",!0),vi=fe("Map.prototype.has",!0),Ct=function(t,e){for(var r=t,n;(n=r.next)!==null;r=n)if(n.key===e)return r.next=n.next,n.next=t.next,t.next=n,n},Ei=function(t,e){var r=Ct(t,e);return r&&r.value},Ai=function(t,e,r){var n=Ct(t,e);n?n.value=r:t.next={key:e,next:t.next,value:r}},Oi=function(t,e){return!!Ct(t,e)},Ri=function(){var e,r,n,o={assert:function(i){if(!o.has(i))throw new yi("Side channel does not contain "+hi(i))},get:function(i){if(Ve&&i&&(typeof i=="object"||typeof i=="function")){if(e)return mi(e,i)}else if(Ge){if(r)return wi(r,i)}else if(n)return Ei(n,i)},has:function(i){if(Ve&&i&&(typeof i=="object"||typeof i=="function")){if(e)return Si(e,i)}else if(Ge){if(r)return vi(r,i)}else if(n)return Oi(n,i);return!1},set:function(i,s){Ve&&i&&(typeof i=="object"||typeof i=="function")?(e||(e=new Ve),gi(e,i,s)):Ge?(r||(r=new Ge),bi(r,i,s)):(n||(n={key:{},next:null}),Ai(n,i,s))}};return o},Ci=String.prototype.replace,Ii=/%20/g,It={RFC1738:"RFC1738",RFC3986:"RFC3986"},Tt={default:It.RFC3986,formatters:{RFC1738:function(t){return Ci.call(t,Ii,"+")},RFC3986:function(t){return String(t)}},RFC1738:It.RFC1738,RFC3986:It.RFC3986},Ti=Tt,Pt=Object.prototype.hasOwnProperty,ee=Array.isArray,H=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),Pi=function(e){for(;e.length>1;){var r=e.pop(),n=r.obj[r.prop];if(ee(n)){for(var o=[],i=0;i<n.length;++i)typeof n[i]<"u"&&o.push(n[i]);r.obj[r.prop]=o}}},Hr=function(e,r){for(var n=r&&r.plainObjects?Object.create(null):{},o=0;o<e.length;++o)typeof e[o]<"u"&&(n[o]=e[o]);return n},Di=function t(e,r,n){if(!r)return e;if(typeof r!="object"){if(ee(e))e.push(r);else if(e&&typeof e=="object")(n&&(n.plainObjects||n.allowPrototypes)||!Pt.call(Object.prototype,r))&&(e[r]=!0);else return[e,r];return e}if(!e||typeof e!="object")return[e].concat(r);var o=e;return ee(e)&&!ee(r)&&(o=Hr(e,n)),ee(e)&&ee(r)?(r.forEach(function(i,s){if(Pt.call(e,s)){var a=e[s];a&&typeof a=="object"&&i&&typeof i=="object"?e[s]=t(a,i,n):e.push(i)}else e[s]=i}),e):Object.keys(r).reduce(function(i,s){var a=r[s];return Pt.call(i,s)?i[s]=t(i[s],a,n):i[s]=a,i},o)},Li=function(e,r){return Object.keys(r).reduce(function(n,o){return n[o]=r[o],n},e)},Fi=function(t,e,r){var n=t.replace(/\+/g," ");if(r==="iso-8859-1")return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch{return n}},Ni=function(e,r,n,o,i){if(e.length===0)return e;var s=e;if(typeof e=="symbol"?s=Symbol.prototype.toString.call(e):typeof e!="string"&&(s=String(e)),n==="iso-8859-1")return escape(s).replace(/%u[0-9a-f]{4}/gi,function(d){return"%26%23"+parseInt(d.slice(2),16)+"%3B"});for(var a="",c=0;c<s.length;++c){var l=s.charCodeAt(c);if(l===45||l===46||l===95||l===126||l>=48&&l<=57||l>=65&&l<=90||l>=97&&l<=122||i===Ti.RFC1738&&(l===40||l===41)){a+=s.charAt(c);continue}if(l<128){a=a+H[l];continue}if(l<2048){a=a+(H[192|l>>6]+H[128|l&63]);continue}if(l<55296||l>=57344){a=a+(H[224|l>>12]+H[128|l>>6&63]+H[128|l&63]);continue}c+=1,l=65536+((l&1023)<<10|s.charCodeAt(c)&1023),a+=H[240|l>>18]+H[128|l>>12&63]+H[128|l>>6&63]+H[128|l&63]}return a},_i=function(e){for(var r=[{obj:{o:e},prop:"o"}],n=[],o=0;o<r.length;++o)for(var i=r[o],s=i.obj[i.prop],a=Object.keys(s),c=0;c<a.length;++c){var l=a[c],d=s[l];typeof d=="object"&&d!==null&&n.indexOf(d)===-1&&(r.push({obj:s,prop:l}),n.push(d))}return Pi(r),e},xi=function(e){return Object.prototype.toString.call(e)==="[object RegExp]"},Ui=function(e){return!e||typeof e!="object"?!1:!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},ki=function(e,r){return[].concat(e,r)},Bi=function(e,r){if(ee(e)){for(var n=[],o=0;o<e.length;o+=1)n.push(r(e[o]));return n}return r(e)},$r={arrayToObject:Hr,assign:Li,combine:ki,compact:_i,decode:Fi,encode:Ni,isBuffer:Ui,isRegExp:xi,maybeMap:Bi,merge:Di},Vr=Ri,We=$r,Re=Tt,Mi=Object.prototype.hasOwnProperty,Gr={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},G=Array.isArray,Hi=Array.prototype.push,Wr=function(t,e){Hi.apply(t,G(e)?e:[e])},$i=Date.prototype.toISOString,qr=Re.default,L={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:We.encode,encodeValuesOnly:!1,format:qr,formatter:Re.formatters[qr],indices:!1,serializeDate:function(e){return $i.call(e)},skipNulls:!1,strictNullHandling:!1},Vi=function(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="symbol"||typeof e=="bigint"},Dt={},Gi=function t(e,r,n,o,i,s,a,c,l,d,f,y,w,p,h,E){for(var S=e,I=E,P=0,K=!1;(I=I.get(Dt))!==void 0&&!K;){var Ce=I.get(e);if(P+=1,typeof Ce<"u"){if(Ce===P)throw new RangeError("Cyclic object value");K=!0}typeof I.get(Dt)>"u"&&(P=0)}if(typeof c=="function"?S=c(r,S):S instanceof Date?S=f(S):n==="comma"&&G(S)&&(S=We.maybeMap(S,function(me){return me instanceof Date?f(me):me})),S===null){if(i)return a&&!p?a(r,L.encoder,h,"key",y):r;S=""}if(Vi(S)||We.isBuffer(S)){if(a){var qe=p?r:a(r,L.encoder,h,"key",y);return[w(qe)+"="+w(a(S,L.encoder,h,"value",y))]}return[w(r)+"="+w(String(S))]}var ne=[];if(typeof S>"u")return ne;var Q;if(n==="comma"&&G(S))p&&a&&(S=We.maybeMap(S,a)),Q=[{value:S.length>0?S.join(",")||null:void 0}];else if(G(c))Q=c;else{var pe=Object.keys(S);Q=l?pe.sort(l):pe}for(var he=o&&G(S)&&S.length===1?r+"[]":r,Ie=0;Ie<Q.length;++Ie){var U=Q[Ie],W=typeof U=="object"&&typeof U.value<"u"?U.value:S[U];if(!(s&&W===null)){var ye=G(S)?typeof n=="function"?n(he,U):he:he+(d?"."+U:"["+U+"]");E.set(e,P);var je=Vr();je.set(Dt,E),Wr(ne,t(W,ye,n,o,i,s,n==="comma"&&p&&G(S)?null:a,c,l,d,f,y,w,p,h,je))}}return ne},Wi=function(e){if(!e)return L;if(e.encoder!==null&&typeof e.encoder<"u"&&typeof e.encoder!="function")throw new TypeError("Encoder has to be a function.");var r=e.charset||L.charset;if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Re.default;if(typeof e.format<"u"){if(!Mi.call(Re.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var o=Re.formatters[n],i=L.filter;return(typeof e.filter=="function"||G(e.filter))&&(i=e.filter),{addQueryPrefix:typeof e.addQueryPrefix=="boolean"?e.addQueryPrefix:L.addQueryPrefix,allowDots:typeof e.allowDots>"u"?L.allowDots:!!e.allowDots,charset:r,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:L.charsetSentinel,delimiter:typeof e.delimiter>"u"?L.delimiter:e.delimiter,encode:typeof e.encode=="boolean"?e.encode:L.encode,encoder:typeof e.encoder=="function"?e.encoder:L.encoder,encodeValuesOnly:typeof e.encodeValuesOnly=="boolean"?e.encodeValuesOnly:L.encodeValuesOnly,filter:i,format:n,formatter:o,serializeDate:typeof e.serializeDate=="function"?e.serializeDate:L.serializeDate,skipNulls:typeof e.skipNulls=="boolean"?e.skipNulls:L.skipNulls,sort:typeof e.sort=="function"?e.sort:null,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:L.strictNullHandling}},qi=function(t,e){var r=t,n=Wi(e),o,i;typeof n.filter=="function"?(i=n.filter,r=i("",r)):G(n.filter)&&(i=n.filter,o=i);var s=[];if(typeof r!="object"||r===null)return"";var a;e&&e.arrayFormat in Gr?a=e.arrayFormat:e&&"indices"in e?a=e.indices?"indices":"repeat":a="indices";var c=Gr[a];if(e&&"commaRoundTrip"in e&&typeof e.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var l=c==="comma"&&e&&e.commaRoundTrip;o||(o=Object.keys(r)),n.sort&&o.sort(n.sort);for(var d=Vr(),f=0;f<o.length;++f){var y=o[f];n.skipNulls&&r[y]===null||Wr(s,Gi(r[y],y,c,l,n.strictNullHandling,n.skipNulls,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,d))}var w=s.join(n.delimiter),p=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),w.length>0?p+w:""},de=$r,Lt=Object.prototype.hasOwnProperty,ji=Array.isArray,C={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:de.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},zi=function(t){return t.replace(/&#(\d+);/g,function(e,r){return String.fromCharCode(parseInt(r,10))})},jr=function(t,e){return t&&typeof t=="string"&&e.comma&&t.indexOf(",")>-1?t.split(","):t},Ji="utf8=%26%2310003%3B",Ki="utf8=%E2%9C%93",Qi=function(e,r){var n={__proto__:null},o=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=r.parameterLimit===1/0?void 0:r.parameterLimit,s=o.split(r.delimiter,i),a=-1,c,l=r.charset;if(r.charsetSentinel)for(c=0;c<s.length;++c)s[c].indexOf("utf8=")===0&&(s[c]===Ki?l="utf-8":s[c]===Ji&&(l="iso-8859-1"),a=c,c=s.length);for(c=0;c<s.length;++c)if(c!==a){var d=s[c],f=d.indexOf("]="),y=f===-1?d.indexOf("="):f+1,w,p;y===-1?(w=r.decoder(d,C.decoder,l,"key"),p=r.strictNullHandling?null:""):(w=r.decoder(d.slice(0,y),C.decoder,l,"key"),p=de.maybeMap(jr(d.slice(y+1),r),function(h){return r.decoder(h,C.decoder,l,"value")})),p&&r.interpretNumericEntities&&l==="iso-8859-1"&&(p=zi(p)),d.indexOf("[]=")>-1&&(p=ji(p)?[p]:p),Lt.call(n,w)?n[w]=de.combine(n[w],p):n[w]=p}return n},Xi=function(t,e,r,n){for(var o=n?e:jr(e,r),i=t.length-1;i>=0;--i){var s,a=t[i];if(a==="[]"&&r.parseArrays)s=[].concat(o);else{s=r.plainObjects?Object.create(null):{};var c=a.charAt(0)==="["&&a.charAt(a.length-1)==="]"?a.slice(1,-1):a,l=parseInt(c,10);!r.parseArrays&&c===""?s={0:o}:!isNaN(l)&&a!==c&&String(l)===c&&l>=0&&r.parseArrays&&l<=r.arrayLimit?(s=[],s[l]=o):c!=="__proto__"&&(s[c]=o)}o=s}return o},Yi=function(e,r,n,o){if(e){var i=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,s=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,c=n.depth>0&&s.exec(i),l=c?i.slice(0,c.index):i,d=[];if(l){if(!n.plainObjects&&Lt.call(Object.prototype,l)&&!n.allowPrototypes)return;d.push(l)}for(var f=0;n.depth>0&&(c=a.exec(i))!==null&&f<n.depth;){if(f+=1,!n.plainObjects&&Lt.call(Object.prototype,c[1].slice(1,-1))&&!n.allowPrototypes)return;d.push(c[1])}return c&&d.push("["+i.slice(c.index)+"]"),Xi(d,r,n,o)}},Zi=function(e){if(!e)return C;if(e.decoder!==null&&e.decoder!==void 0&&typeof e.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof e.charset<"u"&&e.charset!=="utf-8"&&e.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=typeof e.charset>"u"?C.charset:e.charset;return{allowDots:typeof e.allowDots>"u"?C.allowDots:!!e.allowDots,allowPrototypes:typeof e.allowPrototypes=="boolean"?e.allowPrototypes:C.allowPrototypes,allowSparse:typeof e.allowSparse=="boolean"?e.allowSparse:C.allowSparse,arrayLimit:typeof e.arrayLimit=="number"?e.arrayLimit:C.arrayLimit,charset:r,charsetSentinel:typeof e.charsetSentinel=="boolean"?e.charsetSentinel:C.charsetSentinel,comma:typeof e.comma=="boolean"?e.comma:C.comma,decoder:typeof e.decoder=="function"?e.decoder:C.decoder,delimiter:typeof e.delimiter=="string"||de.isRegExp(e.delimiter)?e.delimiter:C.delimiter,depth:typeof e.depth=="number"||e.depth===!1?+e.depth:C.depth,ignoreQueryPrefix:e.ignoreQueryPrefix===!0,interpretNumericEntities:typeof e.interpretNumericEntities=="boolean"?e.interpretNumericEntities:C.interpretNumericEntities,parameterLimit:typeof e.parameterLimit=="number"?e.parameterLimit:C.parameterLimit,parseArrays:e.parseArrays!==!1,plainObjects:typeof e.plainObjects=="boolean"?e.plainObjects:C.plainObjects,strictNullHandling:typeof e.strictNullHandling=="boolean"?e.strictNullHandling:C.strictNullHandling}},es=function(t,e){var r=Zi(e);if(t===""||t===null||typeof t>"u")return r.plainObjects?Object.create(null):{};for(var n=typeof t=="string"?Qi(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),s=0;s<i.length;++s){var a=i[s],c=Yi(a,n[a],r,typeof t=="string");o=de.merge(o,c,r)}return r.allowSparse===!0?o:de.compact(o)},ts=qi,rs=es,ns=Tt,os={formats:ns,parse:rs,stringify:ts};const is=lo(os);class zr{constructor(e){m(this,"axiosInstance");this.axiosInstance=O.create({baseURL:e,timeout:12e4})}Request(e){return new Promise((r,n)=>{this.axiosInstance.request(e).then(o=>r(o)).catch(o=>n(o))})}Get(e,r,n){return new Promise((o,i)=>{r&&(n?n.params=r:n={params:r}),n&&(n.paramsSerializer={serialize:(s,a)=>is.stringify(s,{indices:!1})}),this.axiosInstance.get(e,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Post(e,r,n){return new Promise((o,i)=>{this.axiosInstance.post(e,r,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Put(e,r,n){return new Promise((o,i)=>{this.axiosInstance.put(e,r,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}Delete(e,r,n){return new Promise((o,i)=>{r&&(n?n.data=r:n={data:r}),this.axiosInstance.delete(e,n??{}).then(({data:s})=>o(s)).catch(s=>i(s))})}}class ss{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}onStartSuccess(e){console.debug("onStartSuccess:",e)}onDataChannelMessage(e){console.debug("onDataChannelMessage:",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}var g=(t=>(t[t.UNKNOWN=0]="UNKNOWN",t[t.AUDIO=1]="AUDIO",t[t.VIDEO=2]="VIDEO",t[t.RTSP_PULL=3]="RTSP_PULL",t[t.AUDIO_PUSH=4]="AUDIO_PUSH",t[t.VIDEO_PUSH=5]="VIDEO_PUSH",t[t.AUDIO_HALF=6]="AUDIO_HALF",t[t.VIDEO_HALF=7]="VIDEO_HALF",t))(g||{}),te=(t=>(t.FRONT_FACING="user",t.BACK_FACING="environment",t))(te||{});class Ft{constructor(e){m(this,"peerConnection");m(this,"sessionListener",new ss);m(this,"isCallOut",!1);m(this,"sessionType",g.UNKNOWN);m(this,"localStream");m(this,"remoteStream");m(this,"dataChannel");m(this,"hasSetRemoteSdp",!1);m(this,"facingMode",te.FRONT_FACING);m(this,"facingChanging",!1);m(this,"muted",!1);m(this,"openCamera",!1);m(this,"desktopSharing",!1);this.sessionType=e}setListener(e){this.sessionListener=e}start(e,r){if(!e&&!r){this.error(new Error("start failed, remoteSdp is null."));return}switch(this.isCallOut=e,this.hasSetRemoteSdp=!1,this.facingMode=te.FRONT_FACING,this.facingChanging=!1,this.muted=!1,this.desktopSharing=!1,this.peerConnection=new RTCPeerConnection({iceServers:[]}),this.peerConnection.onnegotiationneeded=()=>{switch(this.sessionType){case g.AUDIO_PUSH:case g.VIDEO_PUSH:case g.AUDIO_HALF:case g.VIDEO_HALF:this.createDataChannel()}e?(console.debug("webrtc call out"),this.peerConnection.createOffer().then(n=>{console.debug("webrtc createOffer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(o=>{this.error(o)})}).catch(n=>{this.error(n)})):(console.debug("webrtc call in: ",r),this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"offer",sdp:r})).then(()=>{console.debug("webrtc setRemoteDescription success"),this.peerConnection.createAnswer().then(n=>{console.debug("webrtc createAnswer success"),this.peerConnection.setLocalDescription(n).then(()=>{console.debug("webrtc setLocalDescription success")}).catch(o=>{this.error(o)})}).catch(n=>{this.error(n)})}).catch(n=>{this.error(n)}))},this.peerConnection.onicegatheringstatechange=()=>{var n;console.debug("webrtc onicegatheringstatechange",(n=this.peerConnection)==null?void 0:n.iceGatheringState),this.peerConnection&&this.peerConnection.iceGatheringState=="complete"&&this.peerConnection.localDescription&&this.sessionListener.onStartSuccess(this.peerConnection.localDescription)},this.peerConnection.ontrack=n=>{console.debug("webrtc ontrack");for(let o=0;o<n.streams.length;o++)this.remoteStream?n.streams[o].getTracks().forEach(i=>{var s;(s=this.remoteStream)==null||s.addTrack(i)}):this.remoteStream=new MediaStream(n.streams[o]);this.sessionListener.onAddRemoteStream(this.remoteStream)},this.peerConnection.oniceconnectionstatechange=n=>{var o,i,s,a,c;console.debug("oniceconnectionstatechange",(o=this.peerConnection)==null?void 0:o.iceConnectionState),(((i=this.peerConnection)==null?void 0:i.iceConnectionState)=="completed"||((s=this.peerConnection)==null?void 0:s.iceConnectionState)=="disconnected"||((a=this.peerConnection)==null?void 0:a.iceConnectionState)=="failed"||((c=this.peerConnection)==null?void 0:c.iceConnectionState)=="closed")&&(this.stop(),this.sessionListener.onError(new Error("session closed.")))},this.sessionType){case g.RTSP_PULL:this.addTransceivers(),this.createDataChannel();break;case g.AUDIO_PUSH:case g.VIDEO_PUSH:case g.AUDIO_HALF:case g.VIDEO_HALF:case g.VIDEO:case g.AUDIO:this.gotLocalMedia();break;default:this.error(new Error("session type unknown: "+this.sessionType));break}}setRemoteSdp(e){e&&e!==""&&this.peerConnection&&this.isCallOut&&!this.hasSetRemoteSdp&&(this.hasSetRemoteSdp=!0,this.peerConnection.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:e})).then(()=>{console.debug("webrtc setRemoteDescription success")}).catch(r=>{this.error(r),this.hasSetRemoteSdp=!1}))}addRemoteCandidate(e){this.peerConnection&&e.forEach(r=>{this.peerConnection.addIceCandidate(r).then(()=>{console.debug("webrtc addIceCandidate success")}).catch(n=>console.log(n))})}sendStringData(e){this.dataChannel&&this.dataChannel.send(e)}stop(){var e;if(console.debug("webrtc stop"),(this.sessionType==g.VIDEO_PUSH||this.sessionType==g.AUDIO_PUSH||this.sessionType==g.RTSP_PULL)&&this.sendStringData("close"),(e=this.peerConnection)==null||e.close(),this.peerConnection=void 0,this.localStream){for(let r of this.localStream.getTracks())this.localStream.removeTrack(r),r.stop();this.localStream=void 0}this.remoteStream=void 0,this.desktopSharing&&(this.desktopSharing=!1,this.sessionListener.onStopDesktopShare())}changeFacing(){return new Promise((e,r)=>{if(this.sessionType!==g.VIDEO&&this.sessionType!==g.VIDEO_PUSH){r(new Error("not video call"));return}if(!this.localStream||this.localStream.getVideoTracks().length<=0){r(new Error("not in calling or not video call"));return}if(this.facingChanging){r(new Error("camera switching in progress"));return}if(!/mobile/i.test(navigator.userAgent)){r(new Error("not mobile device"));return}this.facingChanging=!0,this.changeCameraLocalMedia().then(()=>e(this.facingMode)).catch(n=>r(n))})}changeMuted(){return new Promise((e,r)=>{!this.localStream||this.localStream.getAudioTracks().length<=0?r(new Error("not in calling")):(this.localStream.getAudioTracks().forEach(n=>{n.enabled=!n.enabled,this.muted=!n.enabled}),e(this.muted))})}changeCameraOpened(){return new Promise((e,r)=>{!this.localStream||this.localStream.getVideoTracks().length<=0?r(new Error("not in video calling")):(this.localStream.getVideoTracks().forEach(n=>{n.enabled=!n.enabled,this.openCamera=!n.enabled}),e(this.openCamera))})}startDesktopShare(){return new Promise((e,r)=>{if(this.desktopSharing){r(new Error("desktop sharing has opened"));return}if(this.sessionType!=g.VIDEO&&this.sessionType!=g.VIDEO_PUSH){r(new Error("desktop sharing not in video calling"));return}if(!this.localStream){r(new Error("localStream undefined"));return}navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia?(this.desktopSharing=!0,navigator.mediaDevices.getDisplayMedia({audio:!1,video:!0}).then(n=>{let o=this.changeVideoTrack(n,()=>{this.stopDesktopShare(),this.sessionListener.onStopDesktopShare()});o?(this.desktopSharing=!1,r(o)):e()}).catch(n=>{this.desktopSharing=!1,r(n)})):r(new Error("error: browsers unsupported DesktopShare"))})}stopDesktopShare(){if(!(!this.peerConnection||!this.localStream)&&this.desktopSharing){for(let e of this.localStream.getVideoTracks())this.localStream.removeTrack(e),e.stop();navigator.mediaDevices.getUserMedia({audio:!1,video:{height:{exact:720},width:{exact:1280}}}).then(e=>{this.changeVideoTrack(e),this.desktopSharing=!1}).catch(e=>{this.desktopSharing=!1,console.debug("stopDesktopShare getUserMedia failed: ",e)})}}changeVideoTrack(e,r){if(!this.localStream||!this.peerConnection){for(let n of e.getTracks())e.removeTrack(n),n.stop();return new Error("localStream undefined or peerConnection undefined")}for(let n of this.localStream.getVideoTracks())this.localStream.removeTrack(n),n.stop();for(let n of e.getTracks())e.removeTrack(n),n.kind=="video"?(this.localStream.addTrack(n),r&&(n.onended=o=>{r()})):n.stop();for(let n of this.peerConnection.getSenders())n.track&&n.track.kind==="video"&&n.replaceTrack(this.localStream.getVideoTracks()[0]).then(()=>{}).catch(o=>{console.error(o)})}error(e){console.debug("webrtc error: ",e),this.stop(),this.sessionListener.onError(e)}addTransceivers(){this.peerConnection.addTransceiver("audio",{direction:"recvonly"}),this.peerConnection.addTransceiver("video",{direction:"recvonly"})}gotLocalMedia(){let e={audio:{echoCancellation:!0,noiseSuppression:!0}};switch(this.sessionType){case g.VIDEO:case g.VIDEO_PUSH:case g.VIDEO_HALF:e.video={height:{exact:720},width:{exact:1280}};break}navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia(e).then(r=>{this.getMediaSuccess(r)}).catch(r=>{this.getMediaFailed(r)}):this.error(new Error("Browser does not support WebRTC"))}getMediaSuccess(e){console.debug("webrtc getMediaSuccess"),this.localStream=e,(this.sessionType===g.VIDEO||this.sessionType===g.VIDEO_PUSH||this.sessionType===g.VIDEO_HALF)&&this.sessionListener.onAddLocalStream(e),e.getTracks().forEach(r=>{switch(this.sessionType){case g.AUDIO_PUSH:case g.VIDEO_PUSH:this.peerConnection.addTransceiver(r,{direction:"sendonly",streams:[e]});break;default:this.peerConnection.addTrack(r,e)}}),this.muted=!1}getMediaFailed(e){if(console.debug("webrtc getMediaFailed failed"),this.sessionType===g.VIDEO){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO,this.gotLocalMedia();return}else if(this.sessionType===g.VIDEO_PUSH){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO_PUSH,this.gotLocalMedia();return}else if(this.sessionType===g.VIDEO_HALF){console.error("get video media failed. maybe not found camera.",e),this.sessionType=g.AUDIO_HALF,this.gotLocalMedia();return}this.error(e)}createDataChannel(){this.peerConnection&&(this.isCallOut?(this.dataChannel=this.peerConnection.createDataChannel("command_channel"),this.dataChannel.onmessage=e=>{this.onDataChannelReceive(e.data)}):this.peerConnection.ondatachannel=e=>{this.dataChannel=e.channel,this.dataChannel.onmessage=r=>{this.onDataChannelReceive(r.data)}})}onDataChannelReceive(e){if(e==="close"){console.debug("data channel receive from server: close"),this.dataChannel=void 0,this.stop();return}(this.sessionType==g.VIDEO_HALF||this.sessionType==g.AUDIO_HALF)&&this.sessionListener.onDataChannelMessage(e)}changeCameraLocalMedia(){return new Promise((e,r)=>{let n;if(this.facingMode===te.FRONT_FACING?n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:1280},width:{exact:720},facingMode:"environment"}}:n={audio:{echoCancellation:!0,noiseSuppression:!0},video:{height:{exact:720},width:{exact:1280},facingMode:"user"}},navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)navigator.mediaDevices.getUserMedia(n).then(o=>{this.changeCameraSuccess(o),e()}).catch(o=>{this.changeCameraFailed(o),r(o)});else{let o=new Error("Browser does not support WebRTC");this.changeCameraFailed(o),r(new Error("Browser does not support WebRTC"))}})}changeCameraSuccess(e){if(!this.localStream){e.getTracks().forEach(r=>{r.stop()}),this.facingChanging=!1;return}this.localStream.getVideoTracks().forEach(r=>{this.localStream.removeTrack(r),r.stop()}),e.getVideoTracks().forEach(r=>{this.localStream.addTrack(r)}),this.peerConnection.getSenders().forEach(r=>{r.track&&r.track.kind==="video"&&r.replaceTrack(e.getVideoTracks()[0]).then(()=>{}).catch(n=>{console.log(n)})}),this.facingMode===te.FRONT_FACING?this.facingMode=te.BACK_FACING:this.facingMode=te.FRONT_FACING,this.facingChanging=!1}changeCameraFailed(e){console.log(e),this.facingChanging=!1}}class as{onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onError(e){console.debug("onError:",e)}}class Jr{constructor(e,r){m(this,"url");m(this,"offerSdp");this.url=e,this.offerSdp=r}}const cs="/media-server/video-play/webrtc";class ls{constructor(e,r){m(this,"rtspUrl");m(this,"webrtcSession",new Ft(g.RTSP_PULL));m(this,"sessionListener",new as);m(this,"httpClient");this.rtspUrl=e,this.httpClient=r,this.webrtcSession.setListener(this)}setRtspPullSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}onAddLocalStream(e){}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("rtsp offer:",e.sdp),this.httpClient.Post(cs,new Jr(this.rtspUrl,e.sdp??"")).then(r=>{var n,o,i,s;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("rtsp answer",(n=r.data)==null?void 0:n.sdp),console.debug("rtsp answer",(o=r.data)==null?void 0:o.candidateList),this.webrtcSession.setRemoteSdp(((i=r.data)==null?void 0:i.sdp)??""),this.webrtcSession.addRemoteCandidate(((s=r.data)==null?void 0:s.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}onDataChannelMessage(e){}onStopDesktopShare(){}}var A=(t=>(t[t.OFFLINE=-1]="OFFLINE",t[t.IDLE=0]="IDLE",t[t.TRY=1]="TRY",t[t.RING=2]="RING",t[t.TALK=3]="TALK",t))(A||{}),F=(t=>(t.VIDEO="video",t.AUDIO="audio",t))(F||{}),$=(t=>(t.FULL="full-duplex",t.HALF="half-duplex",t))($||{}),re=(t=>(t.IN="in",t.OUT="out",t))(re||{}),_=(t=>(t.LOGIN="login",t.LOGOUT="logout",t.Invite="invite",t.RING="ring",t.ANSWER="answer",t.HANGUP="hangup",t.DTMF="dtmf",t))(_||{});function Kr(){try{return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}catch{return!1}}function us(){return"browser-"+fs()+ds(6)}function fs(){let t=new Date;return`${t.getFullYear()}${t.getMonth()}${t.getDate()}${t.getHours()}${t.getMinutes()}${t.getSeconds()}`}function ds(t){let e="",r=["0","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];for(let n=0;n<t;n++)e+=r[Math.floor(Math.random()*(r.length-1))];return e}class ps{constructor(e,r,n){m(this,"tel");m(this,"mediaType");m(this,"callMode");this.tel=e,this.callMode=n,this.mediaType=r}}class Qr{onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onAddRemoteStream(e){console.debug("onAddRemoteStream:",e)}onAnswer(){console.debug("onAnswer")}onClose(e){console.debug("onClose:",e)}onError(e){console.debug("onError:",e)}onHangup(e){console.debug("onHangup:",e)}onNewCall(e){console.debug("onNewCall:",e)}onRing(){console.debug("onRing")}onInitResult(e){console.debug("onInitResult: ",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}class Xr{constructor(e,r,n){m(this,"tel","");m(this,"status",A.OFFLINE);m(this,"mediaType",F.AUDIO);m(this,"callMode",$.FULL);m(this,"callDirect",re.OUT);m(this,"called","");m(this,"callId");m(this,"remoteSdp");m(this,"candidate");m(this,"ringBackTone",new Audio("sound/ringbacktone.wav"));m(this,"ringtone",new Audio("sound/ringtone.wav"));m(this,"dtmfAudio",new Audio("sound/dtmf.wav"));m(this,"ws");m(this,"wsConnected",!1);m(this,"closeBySelf",!1);m(this,"webrtcSession");m(this,"sessionListener",new Qr);m(this,"wsUrl");m(this,"accountId");this.tel=r??"",this.wsUrl=e,this.accountId=n,this.ringBackTone.loop=!0,this.ringtone.loop=!0}setCallSessionListener(e){this.sessionListener=e}init(){this.websocketInit(this.wsUrl)}audioCall(e){this.makeCall(e)}videoCall(e){this.makeCall(e,F.VIDEO)}answer(){var r;if(this.status!=A.RING){console.debug("session is not ring state");return}if(this.callDirect!=re.IN){console.debug("session is call out, not allow answer");return}let e;this.callMode==$.HALF?e=F.VIDEO==this.mediaType?g.VIDEO_HALF:g.AUDIO_HALF:e=F.VIDEO==this.mediaType?g.VIDEO:g.AUDIO,this.webrtcCreate(e),(r=this.webrtcSession)==null||r.start(!1,this.remoteSdp)}hangup(){this.status<=A.IDLE||(this.status==A.TALK?this.sendHangup(this.callId??""):this.callDirect==re.IN?this.sendHangup(this.callId??"",488):this.sendHangup(this.callId??"",801),this.close())}dtmf(e){return this.status!==A.TALK?!1:(this.sendDtmf(e),!0)}changeCamera(){return new Promise((e,r)=>{var n;this.webrtcSession||r(new Error("webrtc session not start")),(n=this.webrtcSession)==null||n.changeFacing().then(o=>e(o)).catch(o=>r(o))})}changeMuted(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeMuted().then(n=>e(n)).catch(n=>r(n))})}changeCameraOpened(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.changeCameraOpened().then(n=>e(n)).catch(n=>r(n))})}startDesktopShare(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.status!=A.TALK&&r(new Error(`session status[${this.status}] not talk`)),this.webrtcSession.startDesktopShare().then(()=>e()).catch(n=>r(n))})}stopDesktopShare(){this.webrtcSession&&this.status==A.TALK&&this.webrtcSession.stopDesktopShare()}destroy(){var e;this.closeBySelf=!0,this.hangup(),this.close(),(e=this.ws)==null||e.close()}makeCall(e,r=F.AUDIO,n=$.FULL){var o;try{if(!Kr()){console.debug("Browser does not support WEBRTC"),this.sessionListener.onError(new Error("Browser does not support WEBRTC"));return}if(this.status==A.OFFLINE){console.debug("The initialization has not been completed yet. Please try again later"),this.sessionListener.onError(new Error("The initialization has not been completed yet. Please try again later"));return}this.status>A.IDLE&&(console.debug("Another call is currently in progress, hangup it"),this.hangup()),this.mediaType=r,this.callMode=n,this.called=e,this.callDirect=re.OUT,this.callId=us();let i;this.callMode==$.HALF?i=F.VIDEO==r?g.VIDEO_HALF:g.AUDIO_HALF:i=F.VIDEO==r?g.VIDEO:g.AUDIO,this.webrtcCreate(i),(o=this.webrtcSession)==null||o.start(!0),this.status=A.TRY}catch(i){this.status=A.IDLE,this.sessionListener.onError(new Error(""+i))}}close(){this.webrtcClose();try{this.ringtone.pause(),this.ringBackTone.pause()}catch(e){console.debug("FullSession.close: ",e)}this.status=A.IDLE}websocketInit(e){this.ws=new WebSocket(e),this.closeBySelf=!1,this.ws.onopen=()=>{console.debug("ws connect success"),this.wsConnected=!0,this.sendLogin()},this.ws.onclose=r=>{console.error("ws on close: ",r),this.wsConnected=!1,this.close(),this.status=A.OFFLINE,this.closeBySelf||this.sessionListener.onClose(new Error(r.reason)),this.ws=void 0},this.ws.onmessage=r=>{try{let n=JSON.parse(r.data);switch(console.debug("receive msg from server <<<<<<<<<<<<<<<",n),n.type){case _.Invite:this.inviteHandler(n);break;case _.ANSWER:this.answerHandler(n);break;case _.RING:this.ringHandler(n);break;case _.HANGUP:this.hangupHandler(n);break;case _.LOGIN:this.loginHandler(n);break}}catch(n){console.error("receive msg from server, but process error: ",n,r)}},this.ws.onerror=r=>{console.error("ws on error: ",r)}}sendTo(e){var r;try{this.wsConnected?(console.debug("send msg to server >>>>>>>>>>>>>>>>>> ",e),(r=this.ws)==null||r.send(JSON.stringify(e))):console.error("ws not connected.")}catch(n){console.debug("FullSession sendTo error: ",n)}}sendLogin(){this.sendTo({type:_.LOGIN,username:this.tel,userAgent:this.getUserAgent(),accountId:this.accountId})}sendLogout(){this.sendTo({type:_.LOGOUT,username:this.tel}),this.status=A.OFFLINE}sendInvite(e){this.sendTo({callId:this.callId,type:_.Invite,from:this.tel,to:this.called,callMode:this.callMode,mediaType:this.mediaType,sdp:e}),this.status=A.TRY}sendRing(){this.sendTo({type:_.RING,callId:this.callId,code:180}),this.status=A.RING}sendAnswer(e){this.sendTo({type:_.ANSWER,callId:this.callId,mediaType:this.mediaType,sdp:e}),this.status=A.TALK,this.ringtone.pause(),this.ringBackTone.pause()}sendDtmf(e){this.sendTo({type:_.DTMF,callId:this.callId,callInfo:"dtmf="+e}),this.dtmfAudio.play().then(()=>{}).catch(r=>console.debug(r))}sendHangup(e,r=800){this.sendTo({type:_.HANGUP,callId:e,code:r}),e==this.callId&&(this.status=A.IDLE,this.callId=void 0)}loginHandler(e){var r;if(e.code!=200){(r=this.ws)==null||r.close(),this.wsConnected=!1,this.ws=void 0,this.status=A.OFFLINE,this.sessionListener.onInitResult(!1);return}this.tel=e.username??"",this.status=A.IDLE,this.sessionListener.onInitResult(!0)}inviteHandler(e){if(!e.callId){console.debug("receive invite, but callId is null.");return}if(!Kr()){console.debug("receive invite, but unsupported webrtc."),this.sendHangup(e.callId,803);return}if(this.status>A.IDLE){e.callId!=this.callId?(console.debug("receive invite, but busy."),this.sendHangup(e.callId,486)):console.debug("receive re invite. not process");return}this.callId=e.callId,this.mediaType=e.mediaType??F.AUDIO,this.callMode=e.callMode??$.FULL,this.called=e.from??"",this.callDirect=re.IN,this.remoteSdp=e.sdp,this.candidate=e.candidate,this.sendRing(),this.ringtone.currentTime=0,this.ringtone.play().then(()=>{}).catch(()=>{}),this.sessionListener.onNewCall(new ps(this.called,this.mediaType,this.callMode))}ringHandler(e){var r,n;!e.callId||e.callId!=this.callId||(e.code==183?(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[])):(this.ringBackTone.currentTime=0,this.ringBackTone.play().then(()=>{}).catch(()=>{})),this.sessionListener.onRing(),this.status=A.RING)}answerHandler(e){var r,n;!e.callId||e.callId!=this.callId||(this.ringBackTone.pause(),(r=this.webrtcSession)==null||r.setRemoteSdp(e.sdp??""),(n=this.webrtcSession)==null||n.addRemoteCandidate(e.candidate??[]),this.sessionListener.onAnswer(),this.status=A.TALK)}hangupHandler(e){!e.callId||e.callId!=this.callId||(this.close(),this.sessionListener.onHangup(e.code))}getUserAgent(){return navigator.platform.indexOf("Win")>=0?"windows":"phone"}webrtcCreate(e){this.webrtcClose(),this.webrtcSession=new Ft(e),this.webrtcSession.setListener(this)}webrtcClose(){var e;(e=this.webrtcSession)==null||e.stop(),this.webrtcSession=void 0}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){this.sessionListener.onAddRemoteStream(e)}onError(e){this.close(),this.callDirect==re.OUT&&this.hangup(),this.sessionListener.onError(e)}onStartSuccess(e){var r;e.type=="answer"?(this.sendAnswer(e.sdp??""),(r=this.webrtcSession)==null||r.addRemoteCandidate(this.candidate??[])):e.type=="offer"&&this.sendInvite(e.sdp??"")}onDataChannelMessage(e){}onStopDesktopShare(){this.sessionListener.onStopDesktopShare()}}class hs{onError(e){console.debug("onError:",e)}onAddLocalStream(e){console.debug("onAddLocalStream:",e)}onStopDesktopShare(){console.debug("onStopDesktopShare")}}const ys="/media-server/broadcast/webrtc";class ms{constructor(e,r,n){m(this,"tel");m(this,"mediaType");m(this,"webrtcSession");m(this,"sessionListener",new hs);m(this,"httpClient");this.tel=e,this.httpClient=r,this.mediaType=n===F.VIDEO?F.VIDEO:F.AUDIO,this.webrtcSession=new Ft(n==F.VIDEO?g.VIDEO_PUSH:g.AUDIO_PUSH),this.webrtcSession.setListener(this)}setBroadcastSessionListener(e){this.sessionListener=e}start(){this.webrtcSession.start(!0)}stop(){this.webrtcSession.stop()}startDesktopShare(){return new Promise((e,r)=>{this.webrtcSession||r(new Error("webrtc session not start")),this.webrtcSession.startDesktopShare().then(()=>e()).catch(n=>r(n))})}stopDesktopShare(){this.webrtcSession&&this.webrtcSession.stopDesktopShare()}onAddLocalStream(e){this.sessionListener.onAddLocalStream(e)}onAddRemoteStream(e){}onError(e){this.sessionListener.onError(e)}onStartSuccess(e){console.debug("offer:",e.sdp),this.httpClient.Post(ys,new Jr(this.tel,e.sdp??"")).then(r=>{var n,o,i;if(r.code!=200){this.stop(),this.sessionListener.onError(new Error(r.message));return}console.debug("answer",(n=r.data)==null?void 0:n.sdp),this.webrtcSession.setRemoteSdp(((o=r.data)==null?void 0:o.sdp)??""),this.webrtcSession.addRemoteCandidate(((i=r.data)==null?void 0:i.candidateList)??[])}).catch(r=>{this.stop(),this.sessionListener.onError(r)})}onDataChannelMessage(e){}onStopDesktopShare(){this.sessionListener.onStopDesktopShare()}}var Nt=(t=>(t.TB_REQUEST="tb_request",t.TB_GRANTED="tb_granted",t.TB_TAKEN="tb_taken",t.TB_DENY="tb_deny",t.TB_RELEASE="tb_release",t.TB_IDLE="tb_idle",t.TB_REVOKE="tb_revoke",t))(Nt||{});class gs extends Qr{onTbcpMessage(e){console.debug("onTbcpMessage:",e)}}class Ss extends Xr{constructor(r,n,o){super(r,n,o);m(this,"sessionListener",new gs)}setCallSessionListener(r){this.sessionListener=r}audioHalfCall(r){this.makeCall(r,F.AUDIO,$.HALF)}videoHalfCall(r){this.makeCall(r,F.VIDEO,$.HALF)}tbcpRequest(){var r;this.callMode==$.HALF&&this.status==A.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:Nt.TB_REQUEST})))}tbcpRelease(){var r;this.callMode==$.HALF&&this.status==A.TALK&&((r=this.webrtcSession)==null||r.sendStringData(JSON.stringify({type:Nt.TB_RELEASE})))}onDataChannelMessage(r){try{this.sessionListener.onTbcpMessage(JSON.parse(r))}catch(n){console.debug("onDataChannelMessage err: ",n,r)}}}let _t=new zr("/"),Yr="/media-server/ws/voip",Zr="/media-server/ws/b-trun-c",xt=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Yr),Ut=new URL((location.protocol=="https:"?"wss://":"ws://")+location.host+Zr);function ws(t){_t=new zr(t)}function bs(t){return new ls(t,_t)}function vs(t,e){return new ms(t,_t,e)}function Es(t){xt=new URL(t),xt.pathname=Yr,Ut=new URL(t),Ut.pathname=Zr}function As(t){return new Xr(xt.toString(),t)}function Os(t,e){return new Ss(Ut.toString(),t,e)}T.createAppCallSession=Os,T.createBroadcastSession=vs,T.createCallSession=As,T.createRtspPullSession=bs,T.videoModuleInit=ws,T.voipModuleInit=Es,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "media-av",
3
3
  "private": false,
4
- "version": "0.0.18",
4
+ "version": "0.0.19",
5
5
  "type": "module",
6
6
  "author": "W.w.",
7
7
  "license": "MIT",