@microsoft/signalr
Advanced tools
Comparing version 6.0.0-preview.5.21301.17 to 6.0.0-preview.6.21355.2
@@ -1,2 +0,2 @@ | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},s={};e.r(s),e.d(s,{AbortError:()=>r,DefaultHttpClient:()=>S,HttpClient:()=>h,HttpError:()=>n,HttpResponse:()=>o,HttpTransportType:()=>U,HubConnection:()=>H,HubConnectionBuilder:()=>X,HubConnectionState:()=>I,JsonHubProtocol:()=>F,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>c,Subject:()=>_,TimeoutError:()=>i,TransferFormat:()=>x,VERSION:()=>a});class n extends Error{constructor(t,e){const s=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=s}}class i extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class r extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class o{constructor(t,e,s){this.statusCode=t,this.statusText=e,this.content=s}}class h{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class c{constructor(){}log(t,e){}}c.instance=new c;const a="6.0.0-preview.5.21301.17";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,s){if(!(t in e))throw new Error(`Unknown ${s} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let s="";return f(t)?(s=`Binary data of length ${t.byteLength}`,e&&(s+=`. Content: '${function(t){const e=new Uint8Array(t);let s="";return e.forEach((t=>{s+=`0x${t<16?"0":""}${t.toString(16)} `})),s.substr(0,s.length-1)}(t)}'`)):"string"==typeof t&&(s=`String data of length ${t.length}`,e&&(s+=`. Content: '${t}'`)),s}function f(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,s,n,i,r,o,h,c,a){let l={};if(r){const t=await r();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=y();l[u]=p,e.log(t.Trace,`(${s} transport) sending data. ${d(o,h)}.`);const w=f(o)?"arraybuffer":"text",g=await n.post(i,{content:o,headers:{...l,...a},responseType:w,withCredentials:c});e.log(t.Trace,`(${s} transport) request complete. Response status: ${g.statusCode}.`)}class w{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class g{constructor(t){this.l=t,this.out=console}log(e,s){if(e>=this.l){const n=`[${(new Date).toISOString()}] ${t[e]}: ${s}`;switch(e){case t.Critical:case t.Error:this.out.error(n);break;case t.Warning:this.out.warn(n);break;case t.Information:this.out.info(n);break;default:this.out.log(n)}}}}function y(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,m(a,b(),u.isNode?"NodeJS":"Browser",v())]}function m(t,e,s,n){let i="Microsoft SignalR/";const r=t.split(".");return i+=`${r[0]}.${r[1]}`,i+=` (${t}; `,i+=e&&""!==e?`${e}; `:"Unknown OS; ",i+=`${s}`,i+=n?`; ${n}`:"; Unknown Runtime Version",i+=")",i}function b(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class E extends h{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new r;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const s=new this.m;let h;e.abortSignal&&(e.abortSignal.onabort=()=>{s.abort(),h=new r});let c,a=null;if(e.timeout){const n=e.timeout;a=setTimeout((()=>{s.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),h=new i}),n)}try{c=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:s.signal})}catch(e){if(h)throw h;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{a&&clearTimeout(a),e.abortSignal&&(e.abortSignal.onabort=null)}if(!c.ok){const t=await $(c,"text");throw new n(t||c.statusText,c.status)}const l=$(c,e.responseType),u=await l;return new o(c.status,c.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,s)=>e=s.join("; "))),e}}function $(t,e){let s;switch(e){case"arraybuffer":s=t.arrayBuffer();break;case"text":s=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:s=t.text()}return s}class C extends h{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new r):e.method?e.url?new Promise(((s,h)=>{const c=new XMLHttpRequest;c.open(e.method,e.url,!0),c.withCredentials=void 0===e.withCredentials||e.withCredentials,c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const a=e.headers;a&&Object.keys(a).forEach((t=>{c.setRequestHeader(t,a[t])})),e.responseType&&(c.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{c.abort(),h(new r)}),e.timeout&&(c.timeout=e.timeout),c.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),c.status>=200&&c.status<300?s(new o(c.status,c.statusText,c.response||c.responseText)):h(new n(c.response||c.responseText||c.statusText,c.status))},c.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${c.status}: ${c.statusText}.`),h(new n(c.statusText,c.status))},c.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),h(new i)},c.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class S extends h{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new E(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new C(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new r):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class k{static write(t){return`${t}${k.RecordSeparator}`}static parse(t){if(t[t.length-1]!==k.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(k.RecordSeparator);return e.pop(),e}}k.RecordSeparatorCode=30,k.RecordSeparator=String.fromCharCode(k.RecordSeparatorCode);class P{writeHandshakeRequest(t){return k.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,s;if(f(t)){const n=new Uint8Array(t),i=n.indexOf(k.RecordSeparatorCode);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(n.slice(0,r))),s=n.byteLength>r?n.slice(r).buffer:null}else{const n=t,i=n.indexOf(k.RecordSeparator);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=n.substring(0,r),s=n.length>r?n.substring(r):null}const n=k.parse(e),i=JSON.parse(n[0]);if(i.type)throw new Error("Expected a handshake response from the server.");return[s,i]}}var T,I;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class _{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new w(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(I||(I={}));class H{constructor(t,e,s,n){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(s,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=s,this.connection=t,this.S=n,this.k=new P,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=I.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,s,n){return new H(t,e,s,n)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==I.Disconnected&&this.L!==I.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==I.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=I.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=I.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=I.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const s={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(s)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===I.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===I.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=I.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[s,n]=this.st(e),i=this.nt(t,e,n);let r;const o=new _;return o.cancelCallback=()=>{const t=this.it(i.invocationId);return delete this.I[i.invocationId],r.then((()=>this.rt(t)))},this.I[i.invocationId]=(t,e)=>{e?o.error(e):t&&(t.type===T.Completion?t.error?o.error(new Error(t.error)):o.complete():o.next(t.item))},r=this.rt(i).catch((t=>{o.error(t),delete this.I[i.invocationId]})),this.ot(s,r),o}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[s,n]=this.st(e),i=this.rt(this.ht(t,e,!0,n));return this.ot(s,i),i}invoke(t,...e){const[s,n]=this.st(e),i=this.ht(t,e,!1,n);return new Promise(((t,e)=>{this.I[i.invocationId]=(s,n)=>{n?e(n):s&&(s.type===T.Completion?s.error?e(new Error(s.error)):t(s.result):e(new Error(`Unexpected message type: ${s.type}`)))};const n=this.rt(i).catch((t=>{e(t),delete this.I[i.invocationId]}));this.ot(s,n)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const s=this._[t];if(s)if(e){const n=s.indexOf(e);-1!==n&&(s.splice(n,1),0===s.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const s=this.C.parseMessages(e,this.u);for(const e of s)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const s=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(s):this.Y=this.Z(s);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let s,n;try{[n,s]=this.k.parseHandshakeResponse(e)}catch(e){const s="Error parsing handshake response: "+e;this.u.log(t.Error,s);const n=new Error(s);throw this.B(n),n}if(s.error){const e="Server returned handshake error: "+s.error;this.u.log(t.Error,e);const n=new Error(e);throw this.B(n),n}return this.u.log(t.Debug,"Server handshake complete."),this.F(),n}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===I.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const s=this._[e.target.toLowerCase()];if(s){try{s.forEach((t=>t.apply(this,e.arguments)))}catch(s){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${s}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===I.Disconnecting?this.et(e):this.L===I.Connected&&this.S?this.ft(e):this.L===I.Connected&&this.et(e)}et(e){if(this.N){this.L=I.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${s}'.`)}}}async ft(e){const s=Date.now();let n=0,i=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),r=this.wt(n++,0,i);if(null===r)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=I.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${s}'.`)}if(this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==r;){if(this.u.log(t.Information,`Reconnect attempt number ${n} will start in ${r} ms.`),await new Promise((t=>{this.tt=setTimeout(t,r)})),this.tt=void 0,this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=I.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==I.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===I.Disconnecting&&this.et());i=e instanceof Error?e:new Error(e.toString()),r=this.wt(n++,Date.now()-s,i)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-s} ms and ${n} failed attempts. Connection disconnecting.`),this.et()}wt(e,s,n){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:s,previousRetryCount:e,retryReason:n})}catch(n){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${s}) threw error '${n}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((s=>{(0,e[s])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,s,n){if(s)return 0!==n.length?{arguments:e,streamIds:n,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const s=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:s.toString(),streamIds:n,target:t,type:T.Invocation}:{arguments:e,invocationId:s.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const s in t)t[s].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(s))))},error:t=>{let n;n=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(s,n))))},next:t=>{e=e.then((()=>this.rt(this.yt(s,t))))}})}}st(t){const e=[],s=[];for(let n=0;n<t.length;n++){const i=t[n];if(this.bt(i)){const r=this.R;this.R++,e[r]=i,s.push(r.toString()),t.splice(n,1)}}return[e,s]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,s){const n=this.R;return this.R++,0!==s.length?{arguments:e,invocationId:n.toString(),streamIds:s,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,s){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:s,type:T.Completion}}}const D=[0,2e3,1e4,3e4,null];class A{constructor(t){this.vt=void 0!==t?[...t,null]:D}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class R{}var U,x;R.Authorization="Authorization",R.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(U||(U={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(x||(x={}));class L{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class N{constructor(t,e,s,n,i,r){this.v=t,this.$t=e,this.u=s,this.Ct=new L,this.St=n,this.kt=i,this.Pt=r,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),s===x.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[i,r]=y(),o={[i]:r,...this.Pt},h={abortSignal:this.Ct.signal,headers:o,timeout:1e5,withCredentials:this.kt};s===x.Binary&&(h.responseType="arraybuffer");const c=await this._t();this.Ht(h,c);const a=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${a}.`);const u=await this.v.get(a,h);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new n(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,h)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[R.Authorization]=`Bearer ${e}`:t.headers[R.Authorization]&&delete t.headers[R.Authorization]}async Rt(e,s){try{for(;this.Tt;){const r=await this._t();this.Ht(s,r);try{const i=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${i}.`);const r=await this.v.get(i,s);204===r.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==r.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${r.statusCode}.`),this.Dt=new n(r.statusText||"",r.statusCode),this.Tt=!1):r.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(r.content,this.St)}.`),this.onreceive&&this.onreceive(r.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof i?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[s,n]=y();e[s]=n;const i={headers:{...e,...this.Pt},withCredentials:this.kt},r=await this._t();this.Ht(i,r),await this.v.delete(this.It,i),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,s,n,i,r,o){this.v=t,this.$t=e,this.u=s,this.St=n,this.kt=r,this.xt=i,this.Pt=o,this.onreceive=null,this.onclose=null}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r,o=!1;if(s===x.Text){if(u.isBrowser||u.isWebWorker)r=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),s={};s.Cookie=t;const[n,i]=y();s[n]=i,r=new this.xt(e,{withCredentials:this.kt,headers:{...s,...this.Pt}})}try{r.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onerror=t=>{o?this.Lt():i(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},r.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=r,o=!0,n()}}catch(t){return void i(t)}}else i(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class M{constructor(t,e,s,n,i,r){this.u=s,this.$t=e,this.St=n,this.qt=i,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=r}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r;e=e.replace(/^http/,"ws");const o=this.v.getCookieString(e);let h=!1;if(u.isNode){const t={},[s,n]=y();t[s]=n,o&&(t[R.Cookie]=`${o}`),r=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}r||(r=new this.qt(e)),s===x.Binary&&(r.binaryType="arraybuffer"),r.onopen=s=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=r,h=!0,n()},r.onerror=e=>{let s=null;s="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${s}.`)},r.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onclose=t=>{if(h)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",i(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,s={}){var n;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(n=s.logger)?new g(t.Information):null===n?c.instance:void 0!==n.log?n:new g(n),this.baseUrl=this.Ft(e),(s=s||{}).logMessageContent=void 0!==s.logMessageContent&&s.logMessageContent,"boolean"!=typeof s.withCredentials&&void 0!==s.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");s.withCredentials=void 0===s.withCredentials||s.withCredentials;let i=null,r=null;if(u.isNode){const t=require;i=t("ws"),r=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||s.WebSocket?u.isNode&&!s.WebSocket&&i&&(s.WebSocket=i):s.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||s.EventSource?u.isNode&&!s.EventSource&&void 0!==r&&(s.EventSource=r):s.EventSource=EventSource,this.v=s.httpClient||new S(this.u),this.L="Disconnected",this.N=!1,this.Bt=s,this.onreceive=null,this.onclose=null}async start(e){if(e=e||x.Binary,l.isIn(e,x,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${x[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new W(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let s=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==U.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(U.WebSockets),await this.Kt(s,e)}else{let t=null,n=0;do{if(t=await this.Qt(s),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(s=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}n++}while(t.url&&n<100);if(100===n&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(s,this.Bt.transport,t,e)}this.transport instanceof N&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const s={};if(this.$t){const t=await this.$t();t&&(s[R.Authorization]=`Bearer ${t}`)}const[i,r]=y();s[i]=r;const o=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${o}.`);try{const t=await this.v.post(o,{content:"",headers:{...s,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let s="Failed to complete negotiation with the server: "+e;return e instanceof n&&404===e.statusCode&&(s+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,s),Promise.reject(new Error(s))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,s,n,i){let r=this.te(e,n.connectionToken);if(this.ee(s))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=s,await this.Kt(r,i),void(this.connectionId=n.connectionId);const o=[],h=n.availableTransports||[];let c=n;for(const n of h){const h=this.se(n,s,i);if(h instanceof Error)o.push(`${n.transport} failed: ${h}`);else if(this.ee(h)){if(this.transport=h,!c){try{c=await this.Qt(e)}catch(t){return Promise.reject(t)}r=this.te(e,c.connectionToken)}try{return await this.Kt(r,i),void(this.connectionId=c.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${n.transport}': ${e}`),c=void 0,o.push(`${n.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return o.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${o.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case U.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new M(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case U.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case U.LongPolling:return new N(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,s,n){const i=U[e.transport];if(null==i)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(s,i))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it was disabled by the client.`),new Error(`'${U[i]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>x[t])).indexOf(n)>=0))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it does not support the requested transfer format '${x[n]}'.`),new Error(`'${U[i]}' does not support ${x[n]}.`);if(i===U.WebSockets&&!this.Bt.WebSocket||i===U.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it is not supported in your environment.'`),new Error(`'${U[i]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${U[i]}'.`);try{return this.Gt(i)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(s){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${s}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const s=window.document.createElement("a");return s.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${s.href}'.`),s.href}Zt(t){const e=t.indexOf("?");let s=t.substring(0,-1===e?t.length:e);return"/"!==s[s.length-1]&&(s+="/"),s+="negotiate",s+=-1===e?"":t.substring(e),-1===s.indexOf("negotiateVersion")&&(s+=-1===e?"?":"&",s+="negotiateVersion="+this.jt),s}}class W{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new j,this.he=new j,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new j),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new j;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):W.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),s=new Uint8Array(e);let n=0;for(const e of t)s.set(new Uint8Array(e),n),n+=e.byteLength;return s.buffer}}class j{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class F{constructor(){this.name="json",this.version=1,this.transferFormat=x.Text}parseMessages(e,s){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===s&&(s=c.instance);const n=k.parse(e),i=[];for(const e of n){const n=JSON.parse(e);if("number"!=typeof n.type)throw new Error("Invalid payload.");switch(n.type){case T.Invocation:this.pe(n);break;case T.StreamItem:this.we(n);break;case T.Completion:this.ge(n);break;case T.Ping:case T.Close:break;default:s.log(t.Information,"Unknown message type '"+n.type+"' ignored.");continue}i.push(n)}return i}writeMessage(t){return k.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const B={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class X{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=B[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new g(e)}else this.logger=new g(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new A(t):this.reconnectPolicy=t:this.reconnectPolicy=new A,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return H.create(e,this.logger||c.instance,this.protocol||new F,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),s})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},s={};e.r(s),e.d(s,{AbortError:()=>r,DefaultHttpClient:()=>S,HttpClient:()=>h,HttpError:()=>n,HttpResponse:()=>o,HttpTransportType:()=>U,HubConnection:()=>H,HubConnectionBuilder:()=>X,HubConnectionState:()=>I,JsonHubProtocol:()=>F,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>c,Subject:()=>_,TimeoutError:()=>i,TransferFormat:()=>x,VERSION:()=>a});class n extends Error{constructor(t,e){const s=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=s}}class i extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class r extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class o{constructor(t,e,s){this.statusCode=t,this.statusText=e,this.content=s}}class h{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class c{constructor(){}log(t,e){}}c.instance=new c;const a="6.0.0-preview.6.21355.2";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,s){if(!(t in e))throw new Error(`Unknown ${s} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let s="";return f(t)?(s=`Binary data of length ${t.byteLength}`,e&&(s+=`. Content: '${function(t){const e=new Uint8Array(t);let s="";return e.forEach((t=>{s+=`0x${t<16?"0":""}${t.toString(16)} `})),s.substr(0,s.length-1)}(t)}'`)):"string"==typeof t&&(s=`String data of length ${t.length}`,e&&(s+=`. Content: '${t}'`)),s}function f(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,s,n,i,r,o,h,c,a){let l={};if(r){const t=await r();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=y();l[u]=p,e.log(t.Trace,`(${s} transport) sending data. ${d(o,h)}.`);const w=f(o)?"arraybuffer":"text",g=await n.post(i,{content:o,headers:{...l,...a},responseType:w,withCredentials:c});e.log(t.Trace,`(${s} transport) request complete. Response status: ${g.statusCode}.`)}class w{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class g{constructor(t){this.l=t,this.out=console}log(e,s){if(e>=this.l){const n=`[${(new Date).toISOString()}] ${t[e]}: ${s}`;switch(e){case t.Critical:case t.Error:this.out.error(n);break;case t.Warning:this.out.warn(n);break;case t.Information:this.out.info(n);break;default:this.out.log(n)}}}}function y(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,m(a,b(),u.isNode?"NodeJS":"Browser",v())]}function m(t,e,s,n){let i="Microsoft SignalR/";const r=t.split(".");return i+=`${r[0]}.${r[1]}`,i+=` (${t}; `,i+=e&&""!==e?`${e}; `:"Unknown OS; ",i+=`${s}`,i+=n?`; ${n}`:"; Unknown Runtime Version",i+=")",i}function b(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class E extends h{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new r;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const s=new this.m;let h;e.abortSignal&&(e.abortSignal.onabort=()=>{s.abort(),h=new r});let c,a=null;if(e.timeout){const n=e.timeout;a=setTimeout((()=>{s.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),h=new i}),n)}try{c=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:s.signal})}catch(e){if(h)throw h;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{a&&clearTimeout(a),e.abortSignal&&(e.abortSignal.onabort=null)}if(!c.ok){const t=await $(c,"text");throw new n(t||c.statusText,c.status)}const l=$(c,e.responseType),u=await l;return new o(c.status,c.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,s)=>e=s.join("; "))),e}}function $(t,e){let s;switch(e){case"arraybuffer":s=t.arrayBuffer();break;case"text":s=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:s=t.text()}return s}class C extends h{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new r):e.method?e.url?new Promise(((s,h)=>{const c=new XMLHttpRequest;c.open(e.method,e.url,!0),c.withCredentials=void 0===e.withCredentials||e.withCredentials,c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const a=e.headers;a&&Object.keys(a).forEach((t=>{c.setRequestHeader(t,a[t])})),e.responseType&&(c.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{c.abort(),h(new r)}),e.timeout&&(c.timeout=e.timeout),c.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),c.status>=200&&c.status<300?s(new o(c.status,c.statusText,c.response||c.responseText)):h(new n(c.response||c.responseText||c.statusText,c.status))},c.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${c.status}: ${c.statusText}.`),h(new n(c.statusText,c.status))},c.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),h(new i)},c.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class S extends h{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new E(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new C(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new r):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class k{static write(t){return`${t}${k.RecordSeparator}`}static parse(t){if(t[t.length-1]!==k.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(k.RecordSeparator);return e.pop(),e}}k.RecordSeparatorCode=30,k.RecordSeparator=String.fromCharCode(k.RecordSeparatorCode);class P{writeHandshakeRequest(t){return k.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,s;if(f(t)){const n=new Uint8Array(t),i=n.indexOf(k.RecordSeparatorCode);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(n.slice(0,r))),s=n.byteLength>r?n.slice(r).buffer:null}else{const n=t,i=n.indexOf(k.RecordSeparator);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=n.substring(0,r),s=n.length>r?n.substring(r):null}const n=k.parse(e),i=JSON.parse(n[0]);if(i.type)throw new Error("Expected a handshake response from the server.");return[s,i]}}var T,I;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class _{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new w(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(I||(I={}));class H{constructor(t,e,s,n){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(s,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=s,this.connection=t,this.S=n,this.k=new P,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=I.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,s,n){return new H(t,e,s,n)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==I.Disconnected&&this.L!==I.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==I.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=I.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=I.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=I.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const s={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(s)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===I.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===I.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=I.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[s,n]=this.st(e),i=this.nt(t,e,n);let r;const o=new _;return o.cancelCallback=()=>{const t=this.it(i.invocationId);return delete this.I[i.invocationId],r.then((()=>this.rt(t)))},this.I[i.invocationId]=(t,e)=>{e?o.error(e):t&&(t.type===T.Completion?t.error?o.error(new Error(t.error)):o.complete():o.next(t.item))},r=this.rt(i).catch((t=>{o.error(t),delete this.I[i.invocationId]})),this.ot(s,r),o}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[s,n]=this.st(e),i=this.rt(this.ht(t,e,!0,n));return this.ot(s,i),i}invoke(t,...e){const[s,n]=this.st(e),i=this.ht(t,e,!1,n);return new Promise(((t,e)=>{this.I[i.invocationId]=(s,n)=>{n?e(n):s&&(s.type===T.Completion?s.error?e(new Error(s.error)):t(s.result):e(new Error(`Unexpected message type: ${s.type}`)))};const n=this.rt(i).catch((t=>{e(t),delete this.I[i.invocationId]}));this.ot(s,n)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const s=this._[t];if(s)if(e){const n=s.indexOf(e);-1!==n&&(s.splice(n,1),0===s.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const s=this.C.parseMessages(e,this.u);for(const e of s)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const s=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(s):this.Y=this.Z(s);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let s,n;try{[n,s]=this.k.parseHandshakeResponse(e)}catch(e){const s="Error parsing handshake response: "+e;this.u.log(t.Error,s);const n=new Error(s);throw this.B(n),n}if(s.error){const e="Server returned handshake error: "+s.error;this.u.log(t.Error,e);const n=new Error(e);throw this.B(n),n}return this.u.log(t.Debug,"Server handshake complete."),this.F(),n}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===I.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const s=this._[e.target.toLowerCase()];if(s){try{s.forEach((t=>t.apply(this,e.arguments)))}catch(s){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${s}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===I.Disconnecting?this.et(e):this.L===I.Connected&&this.S?this.ft(e):this.L===I.Connected&&this.et(e)}et(e){if(this.N){this.L=I.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${s}'.`)}}}async ft(e){const s=Date.now();let n=0,i=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),r=this.wt(n++,0,i);if(null===r)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=I.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${s}'.`)}if(this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==r;){if(this.u.log(t.Information,`Reconnect attempt number ${n} will start in ${r} ms.`),await new Promise((t=>{this.tt=setTimeout(t,r)})),this.tt=void 0,this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=I.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==I.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===I.Disconnecting&&this.et());i=e instanceof Error?e:new Error(e.toString()),r=this.wt(n++,Date.now()-s,i)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-s} ms and ${n} failed attempts. Connection disconnecting.`),this.et()}wt(e,s,n){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:s,previousRetryCount:e,retryReason:n})}catch(n){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${s}) threw error '${n}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((s=>{(0,e[s])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,s,n){if(s)return 0!==n.length?{arguments:e,streamIds:n,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const s=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:s.toString(),streamIds:n,target:t,type:T.Invocation}:{arguments:e,invocationId:s.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const s in t)t[s].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(s))))},error:t=>{let n;n=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(s,n))))},next:t=>{e=e.then((()=>this.rt(this.yt(s,t))))}})}}st(t){const e=[],s=[];for(let n=0;n<t.length;n++){const i=t[n];if(this.bt(i)){const r=this.R;this.R++,e[r]=i,s.push(r.toString()),t.splice(n,1)}}return[e,s]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,s){const n=this.R;return this.R++,0!==s.length?{arguments:e,invocationId:n.toString(),streamIds:s,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,s){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:s,type:T.Completion}}}const D=[0,2e3,1e4,3e4,null];class A{constructor(t){this.vt=void 0!==t?[...t,null]:D}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class R{}var U,x;R.Authorization="Authorization",R.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(U||(U={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(x||(x={}));class L{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class N{constructor(t,e,s,n,i,r){this.v=t,this.$t=e,this.u=s,this.Ct=new L,this.St=n,this.kt=i,this.Pt=r,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),s===x.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[i,r]=y(),o={[i]:r,...this.Pt},h={abortSignal:this.Ct.signal,headers:o,timeout:1e5,withCredentials:this.kt};s===x.Binary&&(h.responseType="arraybuffer");const c=await this._t();this.Ht(h,c);const a=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${a}.`);const u=await this.v.get(a,h);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new n(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,h)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[R.Authorization]=`Bearer ${e}`:t.headers[R.Authorization]&&delete t.headers[R.Authorization]}async Rt(e,s){try{for(;this.Tt;){const r=await this._t();this.Ht(s,r);try{const i=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${i}.`);const r=await this.v.get(i,s);204===r.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==r.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${r.statusCode}.`),this.Dt=new n(r.statusText||"",r.statusCode),this.Tt=!1):r.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(r.content,this.St)}.`),this.onreceive&&this.onreceive(r.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof i?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[s,n]=y();e[s]=n;const i={headers:{...e,...this.Pt},withCredentials:this.kt},r=await this._t();this.Ht(i,r),await this.v.delete(this.It,i),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,s,n,i,r,o){this.v=t,this.$t=e,this.u=s,this.St=n,this.kt=r,this.xt=i,this.Pt=o,this.onreceive=null,this.onclose=null}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r,o=!1;if(s===x.Text){if(u.isBrowser||u.isWebWorker)r=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),s={};s.Cookie=t;const[n,i]=y();s[n]=i,r=new this.xt(e,{withCredentials:this.kt,headers:{...s,...this.Pt}})}try{r.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onerror=t=>{o?this.Lt():i(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},r.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=r,o=!0,n()}}catch(t){return void i(t)}}else i(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class M{constructor(t,e,s,n,i,r){this.u=s,this.$t=e,this.St=n,this.qt=i,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=r}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r;e=e.replace(/^http/,"ws");const o=this.v.getCookieString(e);let h=!1;if(u.isNode){const t={},[s,n]=y();t[s]=n,o&&(t[R.Cookie]=`${o}`),r=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}r||(r=new this.qt(e)),s===x.Binary&&(r.binaryType="arraybuffer"),r.onopen=s=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=r,h=!0,n()},r.onerror=e=>{let s=null;s="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${s}.`)},r.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onclose=t=>{if(h)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",i(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,s={}){var n;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(n=s.logger)?new g(t.Information):null===n?c.instance:void 0!==n.log?n:new g(n),this.baseUrl=this.Ft(e),(s=s||{}).logMessageContent=void 0!==s.logMessageContent&&s.logMessageContent,"boolean"!=typeof s.withCredentials&&void 0!==s.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");s.withCredentials=void 0===s.withCredentials||s.withCredentials;let i=null,r=null;if(u.isNode){const t=require;i=t("ws"),r=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||s.WebSocket?u.isNode&&!s.WebSocket&&i&&(s.WebSocket=i):s.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||s.EventSource?u.isNode&&!s.EventSource&&void 0!==r&&(s.EventSource=r):s.EventSource=EventSource,this.v=s.httpClient||new S(this.u),this.L="Disconnected",this.N=!1,this.Bt=s,this.onreceive=null,this.onclose=null}async start(e){if(e=e||x.Binary,l.isIn(e,x,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${x[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new W(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let s=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==U.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(U.WebSockets),await this.Kt(s,e)}else{let t=null,n=0;do{if(t=await this.Qt(s),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(s=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}n++}while(t.url&&n<100);if(100===n&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(s,this.Bt.transport,t,e)}this.transport instanceof N&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const s={};if(this.$t){const t=await this.$t();t&&(s[R.Authorization]=`Bearer ${t}`)}const[i,r]=y();s[i]=r;const o=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${o}.`);try{const t=await this.v.post(o,{content:"",headers:{...s,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let s="Failed to complete negotiation with the server: "+e;return e instanceof n&&404===e.statusCode&&(s+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,s),Promise.reject(new Error(s))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,s,n,i){let r=this.te(e,n.connectionToken);if(this.ee(s))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=s,await this.Kt(r,i),void(this.connectionId=n.connectionId);const o=[],h=n.availableTransports||[];let c=n;for(const n of h){const h=this.se(n,s,i);if(h instanceof Error)o.push(`${n.transport} failed: ${h}`);else if(this.ee(h)){if(this.transport=h,!c){try{c=await this.Qt(e)}catch(t){return Promise.reject(t)}r=this.te(e,c.connectionToken)}try{return await this.Kt(r,i),void(this.connectionId=c.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${n.transport}': ${e}`),c=void 0,o.push(`${n.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return o.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${o.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case U.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new M(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case U.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case U.LongPolling:return new N(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,s,n){const i=U[e.transport];if(null==i)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(s,i))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it was disabled by the client.`),new Error(`'${U[i]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>x[t])).indexOf(n)>=0))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it does not support the requested transfer format '${x[n]}'.`),new Error(`'${U[i]}' does not support ${x[n]}.`);if(i===U.WebSockets&&!this.Bt.WebSocket||i===U.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it is not supported in your environment.'`),new Error(`'${U[i]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${U[i]}'.`);try{return this.Gt(i)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(s){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${s}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const s=window.document.createElement("a");return s.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${s.href}'.`),s.href}Zt(t){const e=t.indexOf("?");let s=t.substring(0,-1===e?t.length:e);return"/"!==s[s.length-1]&&(s+="/"),s+="negotiate",s+=-1===e?"":t.substring(e),-1===s.indexOf("negotiateVersion")&&(s+=-1===e?"?":"&",s+="negotiateVersion="+this.jt),s}}class W{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new j,this.he=new j,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new j),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new j;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):W.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),s=new Uint8Array(e);let n=0;for(const e of t)s.set(new Uint8Array(e),n),n+=e.byteLength;return s.buffer}}class j{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class F{constructor(){this.name="json",this.version=1,this.transferFormat=x.Text}parseMessages(e,s){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===s&&(s=c.instance);const n=k.parse(e),i=[];for(const e of n){const n=JSON.parse(e);if("number"!=typeof n.type)throw new Error("Invalid payload.");switch(n.type){case T.Invocation:this.pe(n);break;case T.StreamItem:this.we(n);break;case T.Completion:this.ge(n);break;case T.Ping:case T.Close:break;default:s.log(t.Information,"Unknown message type '"+n.type+"' ignored.");continue}i.push(n)}return i}writeMessage(t){return k.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const B={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class X{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=B[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new g(e)}else this.logger=new g(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new A(t):this.reconnectPolicy=t:this.reconnectPolicy=new A,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return H.create(e,this.logger||c.instance,this.protocol||new F,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),s})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
//# sourceMappingURL=signalr.js.map |
@@ -1,2 +0,2 @@ | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},n={};e.r(n),e.d(n,{AbortError:()=>i,DefaultHttpClient:()=>$,HttpClient:()=>c,HttpError:()=>o,HttpResponse:()=>s,HttpTransportType:()=>N,HubConnection:()=>L,HubConnectionBuilder:()=>J,HubConnectionState:()=>P,JsonHubProtocol:()=>_,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>a,Subject:()=>D,TimeoutError:()=>r,TransferFormat:()=>W,VERSION:()=>h});class o extends Error{constructor(t,e){const n=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=n}}class r extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class i extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class s{constructor(t,e,n){this.statusCode=t,this.statusText=e,this.content=n}}class c{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class a{constructor(){}log(t,e){}}a.instance=new a;const h="6.0.0-preview.5.21301.17";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,n){if(!(t in e))throw new Error(`Unknown ${n} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let n="";return g(t)?(n=`Binary data of length ${t.byteLength}`,e&&(n+=`. Content: '${function(t){const e=new Uint8Array(t);let n="";return e.forEach((t=>{n+=`0x${t<16?"0":""}${t.toString(16)} `})),n.substr(0,n.length-1)}(t)}'`)):"string"==typeof t&&(n=`String data of length ${t.length}`,e&&(n+=`. Content: '${t}'`)),n}function g(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,n,o,r,i,s,c,a,h){let l={};if(i){const t=await i();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=b();l[u]=p,e.log(t.Trace,`(${n} transport) sending data. ${d(s,c)}.`);const f=g(s)?"arraybuffer":"text",w=await o.post(r,{content:s,headers:{...l,...h},responseType:f,withCredentials:a});e.log(t.Trace,`(${n} transport) request complete. Response status: ${w.statusCode}.`)}class f{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class w{constructor(t){this.l=t,this.out=console}log(e,n){if(e>=this.l){const o=`[${(new Date).toISOString()}] ${t[e]}: ${n}`;switch(e){case t.Critical:case t.Error:this.out.error(o);break;case t.Warning:this.out.warn(o);break;case t.Information:this.out.info(o);break;default:this.out.log(o)}}}}function b(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,y(h,m(),u.isNode?"NodeJS":"Browser",v())]}function y(t,e,n,o){let r="Microsoft SignalR/";const i=t.split(".");return r+=`${i[0]}.${i[1]}`,r+=` (${t}; `,r+=e&&""!==e?`${e}; `:"Unknown OS; ",r+=`${n}`,r+=o?`; ${o}`:"; Unknown Runtime Version",r+=")",r}function m(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class C extends c{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new i;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const n=new this.m;let c;e.abortSignal&&(e.abortSignal.onabort=()=>{n.abort(),c=new i});let a,h=null;if(e.timeout){const o=e.timeout;h=setTimeout((()=>{n.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),c=new r}),o)}try{a=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:n.signal})}catch(e){if(c)throw c;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{h&&clearTimeout(h),e.abortSignal&&(e.abortSignal.onabort=null)}if(!a.ok){const t=await S(a,"text");throw new o(t||a.statusText,a.status)}const l=S(a,e.responseType),u=await l;return new s(a.status,a.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,n)=>e=n.join("; "))),e}}function S(t,e){let n;switch(e){case"arraybuffer":n=t.arrayBuffer();break;case"text":n=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:n=t.text()}return n}class E extends c{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new i):e.method?e.url?new Promise(((n,c)=>{const a=new XMLHttpRequest;a.open(e.method,e.url,!0),a.withCredentials=void 0===e.withCredentials||e.withCredentials,a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const h=e.headers;h&&Object.keys(h).forEach((t=>{a.setRequestHeader(t,h[t])})),e.responseType&&(a.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{a.abort(),c(new i)}),e.timeout&&(a.timeout=e.timeout),a.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),a.status>=200&&a.status<300?n(new s(a.status,a.statusText,a.response||a.responseText)):c(new o(a.response||a.responseText||a.statusText,a.status))},a.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${a.status}: ${a.statusText}.`),c(new o(a.statusText,a.status))},a.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),c(new r)},a.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class $ extends c{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new C(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new E(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new i):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class I{static write(t){return`${t}${I.RecordSeparator}`}static parse(t){if(t[t.length-1]!==I.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(I.RecordSeparator);return e.pop(),e}}I.RecordSeparatorCode=30,I.RecordSeparator=String.fromCharCode(I.RecordSeparatorCode);class k{writeHandshakeRequest(t){return I.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,n;if(g(t)){const o=new Uint8Array(t),r=o.indexOf(I.RecordSeparatorCode);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(o.slice(0,i))),n=o.byteLength>i?o.slice(i).buffer:null}else{const o=t,r=o.indexOf(I.RecordSeparator);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=o.substring(0,i),n=o.length>i?o.substring(i):null}const o=I.parse(e),r=JSON.parse(o[0]);if(r.type)throw new Error("Expected a handshake response from the server.");return[n,r]}}var T,P;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class D{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new f(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(P||(P={}));class L{constructor(t,e,n,o){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(n,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=n,this.connection=t,this.S=o,this.k=new k,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=P.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,n,o){return new L(t,e,n,o)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==P.Disconnected&&this.L!==P.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==P.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=P.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=P.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=P.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const n={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(n)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===P.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===P.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=P.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[n,o]=this.st(e),r=this.nt(t,e,o);let i;const s=new D;return s.cancelCallback=()=>{const t=this.it(r.invocationId);return delete this.I[r.invocationId],i.then((()=>this.rt(t)))},this.I[r.invocationId]=(t,e)=>{e?s.error(e):t&&(t.type===T.Completion?t.error?s.error(new Error(t.error)):s.complete():s.next(t.item))},i=this.rt(r).catch((t=>{s.error(t),delete this.I[r.invocationId]})),this.ot(n,i),s}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[n,o]=this.st(e),r=this.rt(this.ht(t,e,!0,o));return this.ot(n,r),r}invoke(t,...e){const[n,o]=this.st(e),r=this.ht(t,e,!1,o);return new Promise(((t,e)=>{this.I[r.invocationId]=(n,o)=>{o?e(o):n&&(n.type===T.Completion?n.error?e(new Error(n.error)):t(n.result):e(new Error(`Unexpected message type: ${n.type}`)))};const o=this.rt(r).catch((t=>{e(t),delete this.I[r.invocationId]}));this.ot(n,o)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const n=this._[t];if(n)if(e){const o=n.indexOf(e);-1!==o&&(n.splice(o,1),0===n.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const n=this.C.parseMessages(e,this.u);for(const e of n)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const n=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(n):this.Y=this.Z(n);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let n,o;try{[o,n]=this.k.parseHandshakeResponse(e)}catch(e){const n="Error parsing handshake response: "+e;this.u.log(t.Error,n);const o=new Error(n);throw this.B(o),o}if(n.error){const e="Server returned handshake error: "+n.error;this.u.log(t.Error,e);const o=new Error(e);throw this.B(o),o}return this.u.log(t.Debug,"Server handshake complete."),this.F(),o}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===P.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const n=this._[e.target.toLowerCase()];if(n){try{n.forEach((t=>t.apply(this,e.arguments)))}catch(n){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${n}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===P.Disconnecting?this.et(e):this.L===P.Connected&&this.S?this.ft(e):this.L===P.Connected&&this.et(e)}et(e){if(this.N){this.L=P.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${n}'.`)}}}async ft(e){const n=Date.now();let o=0,r=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),i=this.wt(o++,0,r);if(null===i)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=P.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${n}'.`)}if(this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==i;){if(this.u.log(t.Information,`Reconnect attempt number ${o} will start in ${i} ms.`),await new Promise((t=>{this.tt=setTimeout(t,i)})),this.tt=void 0,this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=P.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==P.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===P.Disconnecting&&this.et());r=e instanceof Error?e:new Error(e.toString()),i=this.wt(o++,Date.now()-n,r)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-n} ms and ${o} failed attempts. Connection disconnecting.`),this.et()}wt(e,n,o){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:n,previousRetryCount:e,retryReason:o})}catch(o){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${n}) threw error '${o}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((n=>{(0,e[n])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,n,o){if(n)return 0!==o.length?{arguments:e,streamIds:o,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const n=this.R;return this.R++,0!==o.length?{arguments:e,invocationId:n.toString(),streamIds:o,target:t,type:T.Invocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const n in t)t[n].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(n))))},error:t=>{let o;o=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(n,o))))},next:t=>{e=e.then((()=>this.rt(this.yt(n,t))))}})}}st(t){const e=[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(this.bt(r)){const i=this.R;this.R++,e[i]=r,n.push(i.toString()),t.splice(o,1)}}return[e,n]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,n){const o=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:o.toString(),streamIds:n,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:o.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,n){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:n,type:T.Completion}}}const R=[0,2e3,1e4,3e4,null];class x{constructor(t){this.vt=void 0!==t?[...t,null]:R}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class H{}var N,W;H.Authorization="Authorization",H.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(N||(N={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(W||(W={}));class j{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class A{constructor(t,e,n,o,r,i){this.v=t,this.$t=e,this.u=n,this.Ct=new j,this.St=o,this.kt=r,this.Pt=i,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),n===W.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[r,i]=b(),s={[r]:i,...this.Pt},c={abortSignal:this.Ct.signal,headers:s,timeout:1e5,withCredentials:this.kt};n===W.Binary&&(c.responseType="arraybuffer");const a=await this._t();this.Ht(c,a);const h=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${h}.`);const u=await this.v.get(h,c);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new o(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,c)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[H.Authorization]=`Bearer ${e}`:t.headers[H.Authorization]&&delete t.headers[H.Authorization]}async Rt(e,n){try{for(;this.Tt;){const i=await this._t();this.Ht(n,i);try{const r=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${r}.`);const i=await this.v.get(r,n);204===i.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==i.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${i.statusCode}.`),this.Dt=new o(i.statusText||"",i.statusCode),this.Tt=!1):i.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(i.content,this.St)}.`),this.onreceive&&this.onreceive(i.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof r?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[n,o]=b();e[n]=o;const r={headers:{...e,...this.Pt},withCredentials:this.kt},i=await this._t();this.Ht(r,i),await this.v.delete(this.It,r),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,n,o,r,i,s){this.v=t,this.$t=e,this.u=n,this.St=o,this.kt=i,this.xt=r,this.Pt=s,this.onreceive=null,this.onclose=null}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i,s=!1;if(n===W.Text){if(u.isBrowser||u.isWebWorker)i=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),n={};n.Cookie=t;const[o,r]=b();n[o]=r,i=new this.xt(e,{withCredentials:this.kt,headers:{...n,...this.Pt}})}try{i.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onerror=t=>{s?this.Lt():r(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},i.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=i,s=!0,o()}}catch(t){return void r(t)}}else r(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class B{constructor(t,e,n,o,r,i){this.u=n,this.$t=e,this.St=o,this.qt=r,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=i}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i;e=e.replace(/^http/,"ws");const s=this.v.getCookieString(e);let c=!1;if(u.isNode){const t={},[n,o]=b();t[n]=o,s&&(t[H.Cookie]=`${s}`),i=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}i||(i=new this.qt(e)),n===W.Binary&&(i.binaryType="arraybuffer"),i.onopen=n=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=i,c=!0,o()},i.onerror=e=>{let n=null;n="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${n}.`)},i.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onclose=t=>{if(c)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",r(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,n={}){var o;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(o=n.logger)?new w(t.Information):null===o?a.instance:void 0!==o.log?o:new w(o),this.baseUrl=this.Ft(e),(n=n||{}).logMessageContent=void 0!==n.logMessageContent&&n.logMessageContent,"boolean"!=typeof n.withCredentials&&void 0!==n.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");n.withCredentials=void 0===n.withCredentials||n.withCredentials;let r=null,i=null;if(u.isNode){const t=require;r=t("ws"),i=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||n.WebSocket?u.isNode&&!n.WebSocket&&r&&(n.WebSocket=r):n.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||n.EventSource?u.isNode&&!n.EventSource&&void 0!==i&&(n.EventSource=i):n.EventSource=EventSource,this.v=n.httpClient||new $(this.u),this.L="Disconnected",this.N=!1,this.Bt=n,this.onreceive=null,this.onclose=null}async start(e){if(e=e||W.Binary,l.isIn(e,W,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${W[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new U(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let n=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==N.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(N.WebSockets),await this.Kt(n,e)}else{let t=null,o=0;do{if(t=await this.Qt(n),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(n=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}o++}while(t.url&&o<100);if(100===o&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(n,this.Bt.transport,t,e)}this.transport instanceof A&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const n={};if(this.$t){const t=await this.$t();t&&(n[H.Authorization]=`Bearer ${t}`)}const[r,i]=b();n[r]=i;const s=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${s}.`);try{const t=await this.v.post(s,{content:"",headers:{...n,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let n="Failed to complete negotiation with the server: "+e;return e instanceof o&&404===e.statusCode&&(n+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,n),Promise.reject(new Error(n))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,n,o,r){let i=this.te(e,o.connectionToken);if(this.ee(n))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=n,await this.Kt(i,r),void(this.connectionId=o.connectionId);const s=[],c=o.availableTransports||[];let a=o;for(const o of c){const c=this.se(o,n,r);if(c instanceof Error)s.push(`${o.transport} failed: ${c}`);else if(this.ee(c)){if(this.transport=c,!a){try{a=await this.Qt(e)}catch(t){return Promise.reject(t)}i=this.te(e,a.connectionToken)}try{return await this.Kt(i,r),void(this.connectionId=a.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${o.transport}': ${e}`),a=void 0,s.push(`${o.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return s.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${s.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case N.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new B(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case N.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case N.LongPolling:return new A(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,n,o){const r=N[e.transport];if(null==r)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(n,r))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it was disabled by the client.`),new Error(`'${N[r]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>W[t])).indexOf(o)>=0))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it does not support the requested transfer format '${W[o]}'.`),new Error(`'${N[r]}' does not support ${W[o]}.`);if(r===N.WebSockets&&!this.Bt.WebSocket||r===N.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it is not supported in your environment.'`),new Error(`'${N[r]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${N[r]}'.`);try{return this.Gt(r)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(n){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${n}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const n=window.document.createElement("a");return n.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${n.href}'.`),n.href}Zt(t){const e=t.indexOf("?");let n=t.substring(0,-1===e?t.length:e);return"/"!==n[n.length-1]&&(n+="/"),n+="negotiate",n+=-1===e?"":t.substring(e),-1===n.indexOf("negotiateVersion")&&(n+=-1===e?"?":"&",n+="negotiateVersion="+this.jt),n}}class U{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new M,this.he=new M,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new M),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new M;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):U.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),n=new Uint8Array(e);let o=0;for(const e of t)n.set(new Uint8Array(e),o),o+=e.byteLength;return n.buffer}}class M{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class _{constructor(){this.name="json",this.version=1,this.transferFormat=W.Text}parseMessages(e,n){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===n&&(n=a.instance);const o=I.parse(e),r=[];for(const e of o){const o=JSON.parse(e);if("number"!=typeof o.type)throw new Error("Invalid payload.");switch(o.type){case T.Invocation:this.pe(o);break;case T.StreamItem:this.we(o);break;case T.Completion:this.ge(o);break;case T.Ping:case T.Close:break;default:n.log(t.Information,"Unknown message type '"+o.type+"' ignored.");continue}r.push(o)}return r}writeMessage(t){return I.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const F={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class J{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=F[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new w(e)}else this.logger=new w(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new x(t):this.reconnectPolicy=t:this.reconnectPolicy=new x,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return L.create(e,this.logger||a.instance,this.protocol||new _,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),n})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},n={};e.r(n),e.d(n,{AbortError:()=>i,DefaultHttpClient:()=>$,HttpClient:()=>c,HttpError:()=>o,HttpResponse:()=>s,HttpTransportType:()=>N,HubConnection:()=>L,HubConnectionBuilder:()=>J,HubConnectionState:()=>P,JsonHubProtocol:()=>_,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>a,Subject:()=>D,TimeoutError:()=>r,TransferFormat:()=>W,VERSION:()=>h});class o extends Error{constructor(t,e){const n=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=n}}class r extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class i extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class s{constructor(t,e,n){this.statusCode=t,this.statusText=e,this.content=n}}class c{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class a{constructor(){}log(t,e){}}a.instance=new a;const h="6.0.0-preview.6.21355.2";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,n){if(!(t in e))throw new Error(`Unknown ${n} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let n="";return g(t)?(n=`Binary data of length ${t.byteLength}`,e&&(n+=`. Content: '${function(t){const e=new Uint8Array(t);let n="";return e.forEach((t=>{n+=`0x${t<16?"0":""}${t.toString(16)} `})),n.substr(0,n.length-1)}(t)}'`)):"string"==typeof t&&(n=`String data of length ${t.length}`,e&&(n+=`. Content: '${t}'`)),n}function g(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,n,o,r,i,s,c,a,h){let l={};if(i){const t=await i();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=b();l[u]=p,e.log(t.Trace,`(${n} transport) sending data. ${d(s,c)}.`);const f=g(s)?"arraybuffer":"text",w=await o.post(r,{content:s,headers:{...l,...h},responseType:f,withCredentials:a});e.log(t.Trace,`(${n} transport) request complete. Response status: ${w.statusCode}.`)}class f{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class w{constructor(t){this.l=t,this.out=console}log(e,n){if(e>=this.l){const o=`[${(new Date).toISOString()}] ${t[e]}: ${n}`;switch(e){case t.Critical:case t.Error:this.out.error(o);break;case t.Warning:this.out.warn(o);break;case t.Information:this.out.info(o);break;default:this.out.log(o)}}}}function b(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,y(h,m(),u.isNode?"NodeJS":"Browser",v())]}function y(t,e,n,o){let r="Microsoft SignalR/";const i=t.split(".");return r+=`${i[0]}.${i[1]}`,r+=` (${t}; `,r+=e&&""!==e?`${e}; `:"Unknown OS; ",r+=`${n}`,r+=o?`; ${o}`:"; Unknown Runtime Version",r+=")",r}function m(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class C extends c{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new i;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const n=new this.m;let c;e.abortSignal&&(e.abortSignal.onabort=()=>{n.abort(),c=new i});let a,h=null;if(e.timeout){const o=e.timeout;h=setTimeout((()=>{n.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),c=new r}),o)}try{a=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:n.signal})}catch(e){if(c)throw c;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{h&&clearTimeout(h),e.abortSignal&&(e.abortSignal.onabort=null)}if(!a.ok){const t=await S(a,"text");throw new o(t||a.statusText,a.status)}const l=S(a,e.responseType),u=await l;return new s(a.status,a.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,n)=>e=n.join("; "))),e}}function S(t,e){let n;switch(e){case"arraybuffer":n=t.arrayBuffer();break;case"text":n=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:n=t.text()}return n}class E extends c{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new i):e.method?e.url?new Promise(((n,c)=>{const a=new XMLHttpRequest;a.open(e.method,e.url,!0),a.withCredentials=void 0===e.withCredentials||e.withCredentials,a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const h=e.headers;h&&Object.keys(h).forEach((t=>{a.setRequestHeader(t,h[t])})),e.responseType&&(a.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{a.abort(),c(new i)}),e.timeout&&(a.timeout=e.timeout),a.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),a.status>=200&&a.status<300?n(new s(a.status,a.statusText,a.response||a.responseText)):c(new o(a.response||a.responseText||a.statusText,a.status))},a.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${a.status}: ${a.statusText}.`),c(new o(a.statusText,a.status))},a.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),c(new r)},a.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class $ extends c{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new C(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new E(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new i):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class I{static write(t){return`${t}${I.RecordSeparator}`}static parse(t){if(t[t.length-1]!==I.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(I.RecordSeparator);return e.pop(),e}}I.RecordSeparatorCode=30,I.RecordSeparator=String.fromCharCode(I.RecordSeparatorCode);class k{writeHandshakeRequest(t){return I.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,n;if(g(t)){const o=new Uint8Array(t),r=o.indexOf(I.RecordSeparatorCode);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(o.slice(0,i))),n=o.byteLength>i?o.slice(i).buffer:null}else{const o=t,r=o.indexOf(I.RecordSeparator);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=o.substring(0,i),n=o.length>i?o.substring(i):null}const o=I.parse(e),r=JSON.parse(o[0]);if(r.type)throw new Error("Expected a handshake response from the server.");return[n,r]}}var T,P;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class D{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new f(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(P||(P={}));class L{constructor(t,e,n,o){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(n,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=n,this.connection=t,this.S=o,this.k=new k,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=P.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,n,o){return new L(t,e,n,o)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==P.Disconnected&&this.L!==P.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==P.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=P.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=P.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=P.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const n={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(n)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===P.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===P.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=P.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[n,o]=this.st(e),r=this.nt(t,e,o);let i;const s=new D;return s.cancelCallback=()=>{const t=this.it(r.invocationId);return delete this.I[r.invocationId],i.then((()=>this.rt(t)))},this.I[r.invocationId]=(t,e)=>{e?s.error(e):t&&(t.type===T.Completion?t.error?s.error(new Error(t.error)):s.complete():s.next(t.item))},i=this.rt(r).catch((t=>{s.error(t),delete this.I[r.invocationId]})),this.ot(n,i),s}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[n,o]=this.st(e),r=this.rt(this.ht(t,e,!0,o));return this.ot(n,r),r}invoke(t,...e){const[n,o]=this.st(e),r=this.ht(t,e,!1,o);return new Promise(((t,e)=>{this.I[r.invocationId]=(n,o)=>{o?e(o):n&&(n.type===T.Completion?n.error?e(new Error(n.error)):t(n.result):e(new Error(`Unexpected message type: ${n.type}`)))};const o=this.rt(r).catch((t=>{e(t),delete this.I[r.invocationId]}));this.ot(n,o)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const n=this._[t];if(n)if(e){const o=n.indexOf(e);-1!==o&&(n.splice(o,1),0===n.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const n=this.C.parseMessages(e,this.u);for(const e of n)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const n=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(n):this.Y=this.Z(n);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let n,o;try{[o,n]=this.k.parseHandshakeResponse(e)}catch(e){const n="Error parsing handshake response: "+e;this.u.log(t.Error,n);const o=new Error(n);throw this.B(o),o}if(n.error){const e="Server returned handshake error: "+n.error;this.u.log(t.Error,e);const o=new Error(e);throw this.B(o),o}return this.u.log(t.Debug,"Server handshake complete."),this.F(),o}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===P.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const n=this._[e.target.toLowerCase()];if(n){try{n.forEach((t=>t.apply(this,e.arguments)))}catch(n){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${n}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===P.Disconnecting?this.et(e):this.L===P.Connected&&this.S?this.ft(e):this.L===P.Connected&&this.et(e)}et(e){if(this.N){this.L=P.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${n}'.`)}}}async ft(e){const n=Date.now();let o=0,r=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),i=this.wt(o++,0,r);if(null===i)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=P.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${n}'.`)}if(this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==i;){if(this.u.log(t.Information,`Reconnect attempt number ${o} will start in ${i} ms.`),await new Promise((t=>{this.tt=setTimeout(t,i)})),this.tt=void 0,this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=P.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==P.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===P.Disconnecting&&this.et());r=e instanceof Error?e:new Error(e.toString()),i=this.wt(o++,Date.now()-n,r)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-n} ms and ${o} failed attempts. Connection disconnecting.`),this.et()}wt(e,n,o){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:n,previousRetryCount:e,retryReason:o})}catch(o){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${n}) threw error '${o}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((n=>{(0,e[n])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,n,o){if(n)return 0!==o.length?{arguments:e,streamIds:o,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const n=this.R;return this.R++,0!==o.length?{arguments:e,invocationId:n.toString(),streamIds:o,target:t,type:T.Invocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const n in t)t[n].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(n))))},error:t=>{let o;o=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(n,o))))},next:t=>{e=e.then((()=>this.rt(this.yt(n,t))))}})}}st(t){const e=[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(this.bt(r)){const i=this.R;this.R++,e[i]=r,n.push(i.toString()),t.splice(o,1)}}return[e,n]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,n){const o=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:o.toString(),streamIds:n,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:o.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,n){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:n,type:T.Completion}}}const R=[0,2e3,1e4,3e4,null];class x{constructor(t){this.vt=void 0!==t?[...t,null]:R}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class H{}var N,W;H.Authorization="Authorization",H.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(N||(N={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(W||(W={}));class j{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class A{constructor(t,e,n,o,r,i){this.v=t,this.$t=e,this.u=n,this.Ct=new j,this.St=o,this.kt=r,this.Pt=i,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),n===W.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[r,i]=b(),s={[r]:i,...this.Pt},c={abortSignal:this.Ct.signal,headers:s,timeout:1e5,withCredentials:this.kt};n===W.Binary&&(c.responseType="arraybuffer");const a=await this._t();this.Ht(c,a);const h=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${h}.`);const u=await this.v.get(h,c);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new o(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,c)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[H.Authorization]=`Bearer ${e}`:t.headers[H.Authorization]&&delete t.headers[H.Authorization]}async Rt(e,n){try{for(;this.Tt;){const i=await this._t();this.Ht(n,i);try{const r=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${r}.`);const i=await this.v.get(r,n);204===i.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==i.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${i.statusCode}.`),this.Dt=new o(i.statusText||"",i.statusCode),this.Tt=!1):i.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(i.content,this.St)}.`),this.onreceive&&this.onreceive(i.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof r?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[n,o]=b();e[n]=o;const r={headers:{...e,...this.Pt},withCredentials:this.kt},i=await this._t();this.Ht(r,i),await this.v.delete(this.It,r),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,n,o,r,i,s){this.v=t,this.$t=e,this.u=n,this.St=o,this.kt=i,this.xt=r,this.Pt=s,this.onreceive=null,this.onclose=null}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i,s=!1;if(n===W.Text){if(u.isBrowser||u.isWebWorker)i=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),n={};n.Cookie=t;const[o,r]=b();n[o]=r,i=new this.xt(e,{withCredentials:this.kt,headers:{...n,...this.Pt}})}try{i.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onerror=t=>{s?this.Lt():r(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},i.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=i,s=!0,o()}}catch(t){return void r(t)}}else r(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class B{constructor(t,e,n,o,r,i){this.u=n,this.$t=e,this.St=o,this.qt=r,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=i}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i;e=e.replace(/^http/,"ws");const s=this.v.getCookieString(e);let c=!1;if(u.isNode){const t={},[n,o]=b();t[n]=o,s&&(t[H.Cookie]=`${s}`),i=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}i||(i=new this.qt(e)),n===W.Binary&&(i.binaryType="arraybuffer"),i.onopen=n=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=i,c=!0,o()},i.onerror=e=>{let n=null;n="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${n}.`)},i.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onclose=t=>{if(c)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",r(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,n={}){var o;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(o=n.logger)?new w(t.Information):null===o?a.instance:void 0!==o.log?o:new w(o),this.baseUrl=this.Ft(e),(n=n||{}).logMessageContent=void 0!==n.logMessageContent&&n.logMessageContent,"boolean"!=typeof n.withCredentials&&void 0!==n.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");n.withCredentials=void 0===n.withCredentials||n.withCredentials;let r=null,i=null;if(u.isNode){const t=require;r=t("ws"),i=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||n.WebSocket?u.isNode&&!n.WebSocket&&r&&(n.WebSocket=r):n.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||n.EventSource?u.isNode&&!n.EventSource&&void 0!==i&&(n.EventSource=i):n.EventSource=EventSource,this.v=n.httpClient||new $(this.u),this.L="Disconnected",this.N=!1,this.Bt=n,this.onreceive=null,this.onclose=null}async start(e){if(e=e||W.Binary,l.isIn(e,W,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${W[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new U(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let n=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==N.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(N.WebSockets),await this.Kt(n,e)}else{let t=null,o=0;do{if(t=await this.Qt(n),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(n=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}o++}while(t.url&&o<100);if(100===o&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(n,this.Bt.transport,t,e)}this.transport instanceof A&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const n={};if(this.$t){const t=await this.$t();t&&(n[H.Authorization]=`Bearer ${t}`)}const[r,i]=b();n[r]=i;const s=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${s}.`);try{const t=await this.v.post(s,{content:"",headers:{...n,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let n="Failed to complete negotiation with the server: "+e;return e instanceof o&&404===e.statusCode&&(n+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,n),Promise.reject(new Error(n))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,n,o,r){let i=this.te(e,o.connectionToken);if(this.ee(n))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=n,await this.Kt(i,r),void(this.connectionId=o.connectionId);const s=[],c=o.availableTransports||[];let a=o;for(const o of c){const c=this.se(o,n,r);if(c instanceof Error)s.push(`${o.transport} failed: ${c}`);else if(this.ee(c)){if(this.transport=c,!a){try{a=await this.Qt(e)}catch(t){return Promise.reject(t)}i=this.te(e,a.connectionToken)}try{return await this.Kt(i,r),void(this.connectionId=a.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${o.transport}': ${e}`),a=void 0,s.push(`${o.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return s.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${s.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case N.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new B(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case N.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case N.LongPolling:return new A(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,n,o){const r=N[e.transport];if(null==r)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(n,r))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it was disabled by the client.`),new Error(`'${N[r]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>W[t])).indexOf(o)>=0))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it does not support the requested transfer format '${W[o]}'.`),new Error(`'${N[r]}' does not support ${W[o]}.`);if(r===N.WebSockets&&!this.Bt.WebSocket||r===N.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it is not supported in your environment.'`),new Error(`'${N[r]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${N[r]}'.`);try{return this.Gt(r)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(n){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${n}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const n=window.document.createElement("a");return n.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${n.href}'.`),n.href}Zt(t){const e=t.indexOf("?");let n=t.substring(0,-1===e?t.length:e);return"/"!==n[n.length-1]&&(n+="/"),n+="negotiate",n+=-1===e?"":t.substring(e),-1===n.indexOf("negotiateVersion")&&(n+=-1===e?"?":"&",n+="negotiateVersion="+this.jt),n}}class U{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new M,this.he=new M,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new M),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new M;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):U.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),n=new Uint8Array(e);let o=0;for(const e of t)n.set(new Uint8Array(e),o),o+=e.byteLength;return n.buffer}}class M{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class _{constructor(){this.name="json",this.version=1,this.transferFormat=W.Text}parseMessages(e,n){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===n&&(n=a.instance);const o=I.parse(e),r=[];for(const e of o){const o=JSON.parse(e);if("number"!=typeof o.type)throw new Error("Invalid payload.");switch(o.type){case T.Invocation:this.pe(o);break;case T.StreamItem:this.we(o);break;case T.Completion:this.ge(o);break;case T.Ping:case T.Close:break;default:n.log(t.Information,"Unknown message type '"+o.type+"' ignored.");continue}r.push(o)}return r}writeMessage(t){return I.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const F={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class J{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=F[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new w(e)}else this.logger=new w(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new x(t):this.reconnectPolicy=t:this.reconnectPolicy=new x,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return L.create(e,this.logger||a.instance,this.protocol||new _,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),n})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
//# sourceMappingURL=signalr.min.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
/** The version of the SignalR client. */ | ||
exports.VERSION = "6.0.0-preview.5.21301.17"; | ||
exports.VERSION = "6.0.0-preview.6.21355.2"; | ||
/** @private */ | ||
@@ -13,0 +13,0 @@ class Arg { |
@@ -7,3 +7,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** The version of the SignalR client. */ | ||
export const VERSION = "6.0.0-preview.5.21301.17"; | ||
export const VERSION = "6.0.0-preview.6.21355.2"; | ||
/** @private */ | ||
@@ -10,0 +10,0 @@ export class Arg { |
@@ -1,2 +0,2 @@ | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},s={};e.r(s),e.d(s,{AbortError:()=>r,DefaultHttpClient:()=>S,HttpClient:()=>h,HttpError:()=>n,HttpResponse:()=>o,HttpTransportType:()=>U,HubConnection:()=>H,HubConnectionBuilder:()=>X,HubConnectionState:()=>I,JsonHubProtocol:()=>F,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>c,Subject:()=>_,TimeoutError:()=>i,TransferFormat:()=>x,VERSION:()=>a});class n extends Error{constructor(t,e){const s=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=s}}class i extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class r extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class o{constructor(t,e,s){this.statusCode=t,this.statusText=e,this.content=s}}class h{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class c{constructor(){}log(t,e){}}c.instance=new c;const a="6.0.0-preview.5.21301.17";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,s){if(!(t in e))throw new Error(`Unknown ${s} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let s="";return f(t)?(s=`Binary data of length ${t.byteLength}`,e&&(s+=`. Content: '${function(t){const e=new Uint8Array(t);let s="";return e.forEach((t=>{s+=`0x${t<16?"0":""}${t.toString(16)} `})),s.substr(0,s.length-1)}(t)}'`)):"string"==typeof t&&(s=`String data of length ${t.length}`,e&&(s+=`. Content: '${t}'`)),s}function f(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,s,n,i,r,o,h,c,a){let l={};if(r){const t=await r();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=y();l[u]=p,e.log(t.Trace,`(${s} transport) sending data. ${d(o,h)}.`);const w=f(o)?"arraybuffer":"text",g=await n.post(i,{content:o,headers:{...l,...a},responseType:w,withCredentials:c});e.log(t.Trace,`(${s} transport) request complete. Response status: ${g.statusCode}.`)}class w{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class g{constructor(t){this.l=t,this.out=console}log(e,s){if(e>=this.l){const n=`[${(new Date).toISOString()}] ${t[e]}: ${s}`;switch(e){case t.Critical:case t.Error:this.out.error(n);break;case t.Warning:this.out.warn(n);break;case t.Information:this.out.info(n);break;default:this.out.log(n)}}}}function y(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,m(a,b(),u.isNode?"NodeJS":"Browser",v())]}function m(t,e,s,n){let i="Microsoft SignalR/";const r=t.split(".");return i+=`${r[0]}.${r[1]}`,i+=` (${t}; `,i+=e&&""!==e?`${e}; `:"Unknown OS; ",i+=`${s}`,i+=n?`; ${n}`:"; Unknown Runtime Version",i+=")",i}function b(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class E extends h{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new r;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const s=new this.m;let h;e.abortSignal&&(e.abortSignal.onabort=()=>{s.abort(),h=new r});let c,a=null;if(e.timeout){const n=e.timeout;a=setTimeout((()=>{s.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),h=new i}),n)}try{c=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:s.signal})}catch(e){if(h)throw h;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{a&&clearTimeout(a),e.abortSignal&&(e.abortSignal.onabort=null)}if(!c.ok){const t=await $(c,"text");throw new n(t||c.statusText,c.status)}const l=$(c,e.responseType),u=await l;return new o(c.status,c.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,s)=>e=s.join("; "))),e}}function $(t,e){let s;switch(e){case"arraybuffer":s=t.arrayBuffer();break;case"text":s=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:s=t.text()}return s}class C extends h{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new r):e.method?e.url?new Promise(((s,h)=>{const c=new XMLHttpRequest;c.open(e.method,e.url,!0),c.withCredentials=void 0===e.withCredentials||e.withCredentials,c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const a=e.headers;a&&Object.keys(a).forEach((t=>{c.setRequestHeader(t,a[t])})),e.responseType&&(c.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{c.abort(),h(new r)}),e.timeout&&(c.timeout=e.timeout),c.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),c.status>=200&&c.status<300?s(new o(c.status,c.statusText,c.response||c.responseText)):h(new n(c.response||c.responseText||c.statusText,c.status))},c.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${c.status}: ${c.statusText}.`),h(new n(c.statusText,c.status))},c.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),h(new i)},c.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class S extends h{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new E(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new C(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new r):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class k{static write(t){return`${t}${k.RecordSeparator}`}static parse(t){if(t[t.length-1]!==k.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(k.RecordSeparator);return e.pop(),e}}k.RecordSeparatorCode=30,k.RecordSeparator=String.fromCharCode(k.RecordSeparatorCode);class P{writeHandshakeRequest(t){return k.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,s;if(f(t)){const n=new Uint8Array(t),i=n.indexOf(k.RecordSeparatorCode);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(n.slice(0,r))),s=n.byteLength>r?n.slice(r).buffer:null}else{const n=t,i=n.indexOf(k.RecordSeparator);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=n.substring(0,r),s=n.length>r?n.substring(r):null}const n=k.parse(e),i=JSON.parse(n[0]);if(i.type)throw new Error("Expected a handshake response from the server.");return[s,i]}}var T,I;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class _{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new w(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(I||(I={}));class H{constructor(t,e,s,n){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(s,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=s,this.connection=t,this.S=n,this.k=new P,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=I.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,s,n){return new H(t,e,s,n)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==I.Disconnected&&this.L!==I.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==I.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=I.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=I.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=I.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const s={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(s)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===I.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===I.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=I.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[s,n]=this.st(e),i=this.nt(t,e,n);let r;const o=new _;return o.cancelCallback=()=>{const t=this.it(i.invocationId);return delete this.I[i.invocationId],r.then((()=>this.rt(t)))},this.I[i.invocationId]=(t,e)=>{e?o.error(e):t&&(t.type===T.Completion?t.error?o.error(new Error(t.error)):o.complete():o.next(t.item))},r=this.rt(i).catch((t=>{o.error(t),delete this.I[i.invocationId]})),this.ot(s,r),o}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[s,n]=this.st(e),i=this.rt(this.ht(t,e,!0,n));return this.ot(s,i),i}invoke(t,...e){const[s,n]=this.st(e),i=this.ht(t,e,!1,n);return new Promise(((t,e)=>{this.I[i.invocationId]=(s,n)=>{n?e(n):s&&(s.type===T.Completion?s.error?e(new Error(s.error)):t(s.result):e(new Error(`Unexpected message type: ${s.type}`)))};const n=this.rt(i).catch((t=>{e(t),delete this.I[i.invocationId]}));this.ot(s,n)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const s=this._[t];if(s)if(e){const n=s.indexOf(e);-1!==n&&(s.splice(n,1),0===s.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const s=this.C.parseMessages(e,this.u);for(const e of s)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const s=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(s):this.Y=this.Z(s);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let s,n;try{[n,s]=this.k.parseHandshakeResponse(e)}catch(e){const s="Error parsing handshake response: "+e;this.u.log(t.Error,s);const n=new Error(s);throw this.B(n),n}if(s.error){const e="Server returned handshake error: "+s.error;this.u.log(t.Error,e);const n=new Error(e);throw this.B(n),n}return this.u.log(t.Debug,"Server handshake complete."),this.F(),n}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===I.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const s=this._[e.target.toLowerCase()];if(s){try{s.forEach((t=>t.apply(this,e.arguments)))}catch(s){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${s}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===I.Disconnecting?this.et(e):this.L===I.Connected&&this.S?this.ft(e):this.L===I.Connected&&this.et(e)}et(e){if(this.N){this.L=I.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${s}'.`)}}}async ft(e){const s=Date.now();let n=0,i=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),r=this.wt(n++,0,i);if(null===r)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=I.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${s}'.`)}if(this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==r;){if(this.u.log(t.Information,`Reconnect attempt number ${n} will start in ${r} ms.`),await new Promise((t=>{this.tt=setTimeout(t,r)})),this.tt=void 0,this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=I.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==I.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===I.Disconnecting&&this.et());i=e instanceof Error?e:new Error(e.toString()),r=this.wt(n++,Date.now()-s,i)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-s} ms and ${n} failed attempts. Connection disconnecting.`),this.et()}wt(e,s,n){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:s,previousRetryCount:e,retryReason:n})}catch(n){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${s}) threw error '${n}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((s=>{(0,e[s])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,s,n){if(s)return 0!==n.length?{arguments:e,streamIds:n,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const s=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:s.toString(),streamIds:n,target:t,type:T.Invocation}:{arguments:e,invocationId:s.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const s in t)t[s].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(s))))},error:t=>{let n;n=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(s,n))))},next:t=>{e=e.then((()=>this.rt(this.yt(s,t))))}})}}st(t){const e=[],s=[];for(let n=0;n<t.length;n++){const i=t[n];if(this.bt(i)){const r=this.R;this.R++,e[r]=i,s.push(r.toString()),t.splice(n,1)}}return[e,s]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,s){const n=this.R;return this.R++,0!==s.length?{arguments:e,invocationId:n.toString(),streamIds:s,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,s){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:s,type:T.Completion}}}const D=[0,2e3,1e4,3e4,null];class A{constructor(t){this.vt=void 0!==t?[...t,null]:D}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class R{}var U,x;R.Authorization="Authorization",R.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(U||(U={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(x||(x={}));class L{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class N{constructor(t,e,s,n,i,r){this.v=t,this.$t=e,this.u=s,this.Ct=new L,this.St=n,this.kt=i,this.Pt=r,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),s===x.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[i,r]=y(),o={[i]:r,...this.Pt},h={abortSignal:this.Ct.signal,headers:o,timeout:1e5,withCredentials:this.kt};s===x.Binary&&(h.responseType="arraybuffer");const c=await this._t();this.Ht(h,c);const a=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${a}.`);const u=await this.v.get(a,h);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new n(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,h)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[R.Authorization]=`Bearer ${e}`:t.headers[R.Authorization]&&delete t.headers[R.Authorization]}async Rt(e,s){try{for(;this.Tt;){const r=await this._t();this.Ht(s,r);try{const i=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${i}.`);const r=await this.v.get(i,s);204===r.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==r.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${r.statusCode}.`),this.Dt=new n(r.statusText||"",r.statusCode),this.Tt=!1):r.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(r.content,this.St)}.`),this.onreceive&&this.onreceive(r.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof i?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[s,n]=y();e[s]=n;const i={headers:{...e,...this.Pt},withCredentials:this.kt},r=await this._t();this.Ht(i,r),await this.v.delete(this.It,i),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,s,n,i,r,o){this.v=t,this.$t=e,this.u=s,this.St=n,this.kt=r,this.xt=i,this.Pt=o,this.onreceive=null,this.onclose=null}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r,o=!1;if(s===x.Text){if(u.isBrowser||u.isWebWorker)r=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),s={};s.Cookie=t;const[n,i]=y();s[n]=i,r=new this.xt(e,{withCredentials:this.kt,headers:{...s,...this.Pt}})}try{r.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onerror=t=>{o?this.Lt():i(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},r.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=r,o=!0,n()}}catch(t){return void i(t)}}else i(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class M{constructor(t,e,s,n,i,r){this.u=s,this.$t=e,this.St=n,this.qt=i,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=r}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r;e=e.replace(/^http/,"ws");const o=this.v.getCookieString(e);let h=!1;if(u.isNode){const t={},[s,n]=y();t[s]=n,o&&(t[R.Cookie]=`${o}`),r=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}r||(r=new this.qt(e)),s===x.Binary&&(r.binaryType="arraybuffer"),r.onopen=s=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=r,h=!0,n()},r.onerror=e=>{let s=null;s="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${s}.`)},r.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onclose=t=>{if(h)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",i(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,s={}){var n;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(n=s.logger)?new g(t.Information):null===n?c.instance:void 0!==n.log?n:new g(n),this.baseUrl=this.Ft(e),(s=s||{}).logMessageContent=void 0!==s.logMessageContent&&s.logMessageContent,"boolean"!=typeof s.withCredentials&&void 0!==s.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");s.withCredentials=void 0===s.withCredentials||s.withCredentials;let i=null,r=null;if(u.isNode){const t=require;i=t("ws"),r=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||s.WebSocket?u.isNode&&!s.WebSocket&&i&&(s.WebSocket=i):s.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||s.EventSource?u.isNode&&!s.EventSource&&void 0!==r&&(s.EventSource=r):s.EventSource=EventSource,this.v=s.httpClient||new S(this.u),this.L="Disconnected",this.N=!1,this.Bt=s,this.onreceive=null,this.onclose=null}async start(e){if(e=e||x.Binary,l.isIn(e,x,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${x[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new W(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let s=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==U.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(U.WebSockets),await this.Kt(s,e)}else{let t=null,n=0;do{if(t=await this.Qt(s),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(s=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}n++}while(t.url&&n<100);if(100===n&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(s,this.Bt.transport,t,e)}this.transport instanceof N&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const s={};if(this.$t){const t=await this.$t();t&&(s[R.Authorization]=`Bearer ${t}`)}const[i,r]=y();s[i]=r;const o=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${o}.`);try{const t=await this.v.post(o,{content:"",headers:{...s,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let s="Failed to complete negotiation with the server: "+e;return e instanceof n&&404===e.statusCode&&(s+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,s),Promise.reject(new Error(s))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,s,n,i){let r=this.te(e,n.connectionToken);if(this.ee(s))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=s,await this.Kt(r,i),void(this.connectionId=n.connectionId);const o=[],h=n.availableTransports||[];let c=n;for(const n of h){const h=this.se(n,s,i);if(h instanceof Error)o.push(`${n.transport} failed: ${h}`);else if(this.ee(h)){if(this.transport=h,!c){try{c=await this.Qt(e)}catch(t){return Promise.reject(t)}r=this.te(e,c.connectionToken)}try{return await this.Kt(r,i),void(this.connectionId=c.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${n.transport}': ${e}`),c=void 0,o.push(`${n.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return o.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${o.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case U.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new M(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case U.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case U.LongPolling:return new N(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,s,n){const i=U[e.transport];if(null==i)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(s,i))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it was disabled by the client.`),new Error(`'${U[i]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>x[t])).indexOf(n)>=0))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it does not support the requested transfer format '${x[n]}'.`),new Error(`'${U[i]}' does not support ${x[n]}.`);if(i===U.WebSockets&&!this.Bt.WebSocket||i===U.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it is not supported in your environment.'`),new Error(`'${U[i]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${U[i]}'.`);try{return this.Gt(i)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(s){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${s}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const s=window.document.createElement("a");return s.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${s.href}'.`),s.href}Zt(t){const e=t.indexOf("?");let s=t.substring(0,-1===e?t.length:e);return"/"!==s[s.length-1]&&(s+="/"),s+="negotiate",s+=-1===e?"":t.substring(e),-1===s.indexOf("negotiateVersion")&&(s+=-1===e?"?":"&",s+="negotiateVersion="+this.jt),s}}class W{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new j,this.he=new j,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new j),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new j;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):W.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),s=new Uint8Array(e);let n=0;for(const e of t)s.set(new Uint8Array(e),n),n+=e.byteLength;return s.buffer}}class j{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class F{constructor(){this.name="json",this.version=1,this.transferFormat=x.Text}parseMessages(e,s){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===s&&(s=c.instance);const n=k.parse(e),i=[];for(const e of n){const n=JSON.parse(e);if("number"!=typeof n.type)throw new Error("Invalid payload.");switch(n.type){case T.Invocation:this.pe(n);break;case T.StreamItem:this.we(n);break;case T.Completion:this.ge(n);break;case T.Ping:case T.Close:break;default:s.log(t.Information,"Unknown message type '"+n.type+"' ignored.");continue}i.push(n)}return i}writeMessage(t){return k.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const B={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class X{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=B[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new g(e)}else this.logger=new g(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new A(t):this.reconnectPolicy=t:this.reconnectPolicy=new A,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return H.create(e,this.logger||c.instance,this.protocol||new F,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),s})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},s={};e.r(s),e.d(s,{AbortError:()=>r,DefaultHttpClient:()=>S,HttpClient:()=>h,HttpError:()=>n,HttpResponse:()=>o,HttpTransportType:()=>U,HubConnection:()=>H,HubConnectionBuilder:()=>X,HubConnectionState:()=>I,JsonHubProtocol:()=>F,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>c,Subject:()=>_,TimeoutError:()=>i,TransferFormat:()=>x,VERSION:()=>a});class n extends Error{constructor(t,e){const s=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=s}}class i extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class r extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class o{constructor(t,e,s){this.statusCode=t,this.statusText=e,this.content=s}}class h{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class c{constructor(){}log(t,e){}}c.instance=new c;const a="6.0.0-preview.6.21355.2";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,s){if(!(t in e))throw new Error(`Unknown ${s} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let s="";return f(t)?(s=`Binary data of length ${t.byteLength}`,e&&(s+=`. Content: '${function(t){const e=new Uint8Array(t);let s="";return e.forEach((t=>{s+=`0x${t<16?"0":""}${t.toString(16)} `})),s.substr(0,s.length-1)}(t)}'`)):"string"==typeof t&&(s=`String data of length ${t.length}`,e&&(s+=`. Content: '${t}'`)),s}function f(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,s,n,i,r,o,h,c,a){let l={};if(r){const t=await r();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=y();l[u]=p,e.log(t.Trace,`(${s} transport) sending data. ${d(o,h)}.`);const w=f(o)?"arraybuffer":"text",g=await n.post(i,{content:o,headers:{...l,...a},responseType:w,withCredentials:c});e.log(t.Trace,`(${s} transport) request complete. Response status: ${g.statusCode}.`)}class w{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class g{constructor(t){this.l=t,this.out=console}log(e,s){if(e>=this.l){const n=`[${(new Date).toISOString()}] ${t[e]}: ${s}`;switch(e){case t.Critical:case t.Error:this.out.error(n);break;case t.Warning:this.out.warn(n);break;case t.Information:this.out.info(n);break;default:this.out.log(n)}}}}function y(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,m(a,b(),u.isNode?"NodeJS":"Browser",v())]}function m(t,e,s,n){let i="Microsoft SignalR/";const r=t.split(".");return i+=`${r[0]}.${r[1]}`,i+=` (${t}; `,i+=e&&""!==e?`${e}; `:"Unknown OS; ",i+=`${s}`,i+=n?`; ${n}`:"; Unknown Runtime Version",i+=")",i}function b(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class E extends h{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new r;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const s=new this.m;let h;e.abortSignal&&(e.abortSignal.onabort=()=>{s.abort(),h=new r});let c,a=null;if(e.timeout){const n=e.timeout;a=setTimeout((()=>{s.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),h=new i}),n)}try{c=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:s.signal})}catch(e){if(h)throw h;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{a&&clearTimeout(a),e.abortSignal&&(e.abortSignal.onabort=null)}if(!c.ok){const t=await $(c,"text");throw new n(t||c.statusText,c.status)}const l=$(c,e.responseType),u=await l;return new o(c.status,c.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,s)=>e=s.join("; "))),e}}function $(t,e){let s;switch(e){case"arraybuffer":s=t.arrayBuffer();break;case"text":s=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:s=t.text()}return s}class C extends h{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new r):e.method?e.url?new Promise(((s,h)=>{const c=new XMLHttpRequest;c.open(e.method,e.url,!0),c.withCredentials=void 0===e.withCredentials||e.withCredentials,c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const a=e.headers;a&&Object.keys(a).forEach((t=>{c.setRequestHeader(t,a[t])})),e.responseType&&(c.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{c.abort(),h(new r)}),e.timeout&&(c.timeout=e.timeout),c.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),c.status>=200&&c.status<300?s(new o(c.status,c.statusText,c.response||c.responseText)):h(new n(c.response||c.responseText||c.statusText,c.status))},c.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${c.status}: ${c.statusText}.`),h(new n(c.statusText,c.status))},c.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),h(new i)},c.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class S extends h{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new E(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new C(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new r):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class k{static write(t){return`${t}${k.RecordSeparator}`}static parse(t){if(t[t.length-1]!==k.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(k.RecordSeparator);return e.pop(),e}}k.RecordSeparatorCode=30,k.RecordSeparator=String.fromCharCode(k.RecordSeparatorCode);class P{writeHandshakeRequest(t){return k.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,s;if(f(t)){const n=new Uint8Array(t),i=n.indexOf(k.RecordSeparatorCode);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(n.slice(0,r))),s=n.byteLength>r?n.slice(r).buffer:null}else{const n=t,i=n.indexOf(k.RecordSeparator);if(-1===i)throw new Error("Message is incomplete.");const r=i+1;e=n.substring(0,r),s=n.length>r?n.substring(r):null}const n=k.parse(e),i=JSON.parse(n[0]);if(i.type)throw new Error("Expected a handshake response from the server.");return[s,i]}}var T,I;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class _{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new w(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(I||(I={}));class H{constructor(t,e,s,n){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(s,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=s,this.connection=t,this.S=n,this.k=new P,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=I.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,s,n){return new H(t,e,s,n)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==I.Disconnected&&this.L!==I.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==I.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=I.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=I.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=I.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const s={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(s)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===I.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===I.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=I.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[s,n]=this.st(e),i=this.nt(t,e,n);let r;const o=new _;return o.cancelCallback=()=>{const t=this.it(i.invocationId);return delete this.I[i.invocationId],r.then((()=>this.rt(t)))},this.I[i.invocationId]=(t,e)=>{e?o.error(e):t&&(t.type===T.Completion?t.error?o.error(new Error(t.error)):o.complete():o.next(t.item))},r=this.rt(i).catch((t=>{o.error(t),delete this.I[i.invocationId]})),this.ot(s,r),o}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[s,n]=this.st(e),i=this.rt(this.ht(t,e,!0,n));return this.ot(s,i),i}invoke(t,...e){const[s,n]=this.st(e),i=this.ht(t,e,!1,n);return new Promise(((t,e)=>{this.I[i.invocationId]=(s,n)=>{n?e(n):s&&(s.type===T.Completion?s.error?e(new Error(s.error)):t(s.result):e(new Error(`Unexpected message type: ${s.type}`)))};const n=this.rt(i).catch((t=>{e(t),delete this.I[i.invocationId]}));this.ot(s,n)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const s=this._[t];if(s)if(e){const n=s.indexOf(e);-1!==n&&(s.splice(n,1),0===s.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const s=this.C.parseMessages(e,this.u);for(const e of s)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const s=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(s):this.Y=this.Z(s);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let s,n;try{[n,s]=this.k.parseHandshakeResponse(e)}catch(e){const s="Error parsing handshake response: "+e;this.u.log(t.Error,s);const n=new Error(s);throw this.B(n),n}if(s.error){const e="Server returned handshake error: "+s.error;this.u.log(t.Error,e);const n=new Error(e);throw this.B(n),n}return this.u.log(t.Debug,"Server handshake complete."),this.F(),n}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===I.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const s=this._[e.target.toLowerCase()];if(s){try{s.forEach((t=>t.apply(this,e.arguments)))}catch(s){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${s}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===I.Disconnecting?this.et(e):this.L===I.Connected&&this.S?this.ft(e):this.L===I.Connected&&this.et(e)}et(e){if(this.N){this.L=I.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${s}'.`)}}}async ft(e){const s=Date.now();let n=0,i=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),r=this.wt(n++,0,i);if(null===r)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=I.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(s){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${s}'.`)}if(this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==r;){if(this.u.log(t.Information,`Reconnect attempt number ${n} will start in ${r} ms.`),await new Promise((t=>{this.tt=setTimeout(t,r)})),this.tt=void 0,this.L!==I.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=I.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==I.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===I.Disconnecting&&this.et());i=e instanceof Error?e:new Error(e.toString()),r=this.wt(n++,Date.now()-s,i)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-s} ms and ${n} failed attempts. Connection disconnecting.`),this.et()}wt(e,s,n){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:s,previousRetryCount:e,retryReason:n})}catch(n){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${s}) threw error '${n}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((s=>{(0,e[s])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,s,n){if(s)return 0!==n.length?{arguments:e,streamIds:n,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const s=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:s.toString(),streamIds:n,target:t,type:T.Invocation}:{arguments:e,invocationId:s.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const s in t)t[s].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(s))))},error:t=>{let n;n=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(s,n))))},next:t=>{e=e.then((()=>this.rt(this.yt(s,t))))}})}}st(t){const e=[],s=[];for(let n=0;n<t.length;n++){const i=t[n];if(this.bt(i)){const r=this.R;this.R++,e[r]=i,s.push(r.toString()),t.splice(n,1)}}return[e,s]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,s){const n=this.R;return this.R++,0!==s.length?{arguments:e,invocationId:n.toString(),streamIds:s,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,s){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:s,type:T.Completion}}}const D=[0,2e3,1e4,3e4,null];class A{constructor(t){this.vt=void 0!==t?[...t,null]:D}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class R{}var U,x;R.Authorization="Authorization",R.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(U||(U={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(x||(x={}));class L{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class N{constructor(t,e,s,n,i,r){this.v=t,this.$t=e,this.u=s,this.Ct=new L,this.St=n,this.kt=i,this.Pt=r,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),s===x.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[i,r]=y(),o={[i]:r,...this.Pt},h={abortSignal:this.Ct.signal,headers:o,timeout:1e5,withCredentials:this.kt};s===x.Binary&&(h.responseType="arraybuffer");const c=await this._t();this.Ht(h,c);const a=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${a}.`);const u=await this.v.get(a,h);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new n(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,h)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[R.Authorization]=`Bearer ${e}`:t.headers[R.Authorization]&&delete t.headers[R.Authorization]}async Rt(e,s){try{for(;this.Tt;){const r=await this._t();this.Ht(s,r);try{const i=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${i}.`);const r=await this.v.get(i,s);204===r.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==r.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${r.statusCode}.`),this.Dt=new n(r.statusText||"",r.statusCode),this.Tt=!1):r.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(r.content,this.St)}.`),this.onreceive&&this.onreceive(r.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof i?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[s,n]=y();e[s]=n;const i={headers:{...e,...this.Pt},withCredentials:this.kt},r=await this._t();this.Ht(i,r),await this.v.delete(this.It,i),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,s,n,i,r,o){this.v=t,this.$t=e,this.u=s,this.St=n,this.kt=r,this.xt=i,this.Pt=o,this.onreceive=null,this.onclose=null}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r,o=!1;if(s===x.Text){if(u.isBrowser||u.isWebWorker)r=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),s={};s.Cookie=t;const[n,i]=y();s[n]=i,r=new this.xt(e,{withCredentials:this.kt,headers:{...s,...this.Pt}})}try{r.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onerror=t=>{o?this.Lt():i(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},r.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=r,o=!0,n()}}catch(t){return void i(t)}}else i(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class M{constructor(t,e,s,n,i,r){this.u=s,this.$t=e,this.St=n,this.qt=i,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=r}async connect(e,s){if(l.isRequired(e,"url"),l.isRequired(s,"transferFormat"),l.isIn(s,x,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((n,i)=>{let r;e=e.replace(/^http/,"ws");const o=this.v.getCookieString(e);let h=!1;if(u.isNode){const t={},[s,n]=y();t[s]=n,o&&(t[R.Cookie]=`${o}`),r=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}r||(r=new this.qt(e)),s===x.Binary&&(r.binaryType="arraybuffer"),r.onopen=s=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=r,h=!0,n()},r.onerror=e=>{let s=null;s="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${s}.`)},r.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},r.onclose=t=>{if(h)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",i(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,s={}){var n;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(n=s.logger)?new g(t.Information):null===n?c.instance:void 0!==n.log?n:new g(n),this.baseUrl=this.Ft(e),(s=s||{}).logMessageContent=void 0!==s.logMessageContent&&s.logMessageContent,"boolean"!=typeof s.withCredentials&&void 0!==s.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");s.withCredentials=void 0===s.withCredentials||s.withCredentials;let i=null,r=null;if(u.isNode){const t=require;i=t("ws"),r=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||s.WebSocket?u.isNode&&!s.WebSocket&&i&&(s.WebSocket=i):s.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||s.EventSource?u.isNode&&!s.EventSource&&void 0!==r&&(s.EventSource=r):s.EventSource=EventSource,this.v=s.httpClient||new S(this.u),this.L="Disconnected",this.N=!1,this.Bt=s,this.onreceive=null,this.onclose=null}async start(e){if(e=e||x.Binary,l.isIn(e,x,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${x[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new W(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let s=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==U.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(U.WebSockets),await this.Kt(s,e)}else{let t=null,n=0;do{if(t=await this.Qt(s),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(s=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}n++}while(t.url&&n<100);if(100===n&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(s,this.Bt.transport,t,e)}this.transport instanceof N&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const s={};if(this.$t){const t=await this.$t();t&&(s[R.Authorization]=`Bearer ${t}`)}const[i,r]=y();s[i]=r;const o=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${o}.`);try{const t=await this.v.post(o,{content:"",headers:{...s,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let s="Failed to complete negotiation with the server: "+e;return e instanceof n&&404===e.statusCode&&(s+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,s),Promise.reject(new Error(s))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,s,n,i){let r=this.te(e,n.connectionToken);if(this.ee(s))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=s,await this.Kt(r,i),void(this.connectionId=n.connectionId);const o=[],h=n.availableTransports||[];let c=n;for(const n of h){const h=this.se(n,s,i);if(h instanceof Error)o.push(`${n.transport} failed: ${h}`);else if(this.ee(h)){if(this.transport=h,!c){try{c=await this.Qt(e)}catch(t){return Promise.reject(t)}r=this.te(e,c.connectionToken)}try{return await this.Kt(r,i),void(this.connectionId=c.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${n.transport}': ${e}`),c=void 0,o.push(`${n.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return o.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${o.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case U.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new M(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case U.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case U.LongPolling:return new N(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,s,n){const i=U[e.transport];if(null==i)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(s,i))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it was disabled by the client.`),new Error(`'${U[i]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>x[t])).indexOf(n)>=0))return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it does not support the requested transfer format '${x[n]}'.`),new Error(`'${U[i]}' does not support ${x[n]}.`);if(i===U.WebSockets&&!this.Bt.WebSocket||i===U.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${U[i]}' because it is not supported in your environment.'`),new Error(`'${U[i]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${U[i]}'.`);try{return this.Gt(i)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(s){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${s}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const s=window.document.createElement("a");return s.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${s.href}'.`),s.href}Zt(t){const e=t.indexOf("?");let s=t.substring(0,-1===e?t.length:e);return"/"!==s[s.length-1]&&(s+="/"),s+="negotiate",s+=-1===e?"":t.substring(e),-1===s.indexOf("negotiateVersion")&&(s+=-1===e?"?":"&",s+="negotiateVersion="+this.jt),s}}class W{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new j,this.he=new j,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new j),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new j;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):W.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),s=new Uint8Array(e);let n=0;for(const e of t)s.set(new Uint8Array(e),n),n+=e.byteLength;return s.buffer}}class j{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class F{constructor(){this.name="json",this.version=1,this.transferFormat=x.Text}parseMessages(e,s){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===s&&(s=c.instance);const n=k.parse(e),i=[];for(const e of n){const n=JSON.parse(e);if("number"!=typeof n.type)throw new Error("Invalid payload.");switch(n.type){case T.Invocation:this.pe(n);break;case T.StreamItem:this.we(n);break;case T.Completion:this.ge(n);break;case T.Ping:case T.Close:break;default:s.log(t.Information,"Unknown message type '"+n.type+"' ignored.");continue}i.push(n)}return i}writeMessage(t){return k.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const B={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class X{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=B[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new g(e)}else this.logger=new g(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new A(t):this.reconnectPolicy=t:this.reconnectPolicy=new A,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return H.create(e,this.logger||c.instance,this.protocol||new F,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),s})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
//# sourceMappingURL=signalr.js.map |
@@ -1,1 +0,1 @@ | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},n={};e.r(n),e.d(n,{AbortError:()=>i,DefaultHttpClient:()=>$,HttpClient:()=>c,HttpError:()=>o,HttpResponse:()=>s,HttpTransportType:()=>N,HubConnection:()=>L,HubConnectionBuilder:()=>J,HubConnectionState:()=>P,JsonHubProtocol:()=>_,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>a,Subject:()=>D,TimeoutError:()=>r,TransferFormat:()=>W,VERSION:()=>h});class o extends Error{constructor(t,e){const n=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=n}}class r extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class i extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class s{constructor(t,e,n){this.statusCode=t,this.statusText=e,this.content=n}}class c{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class a{constructor(){}log(t,e){}}a.instance=new a;const h="6.0.0-preview.5.21301.17";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,n){if(!(t in e))throw new Error(`Unknown ${n} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let n="";return g(t)?(n=`Binary data of length ${t.byteLength}`,e&&(n+=`. Content: '${function(t){const e=new Uint8Array(t);let n="";return e.forEach((t=>{n+=`0x${t<16?"0":""}${t.toString(16)} `})),n.substr(0,n.length-1)}(t)}'`)):"string"==typeof t&&(n=`String data of length ${t.length}`,e&&(n+=`. Content: '${t}'`)),n}function g(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,n,o,r,i,s,c,a,h){let l={};if(i){const t=await i();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=b();l[u]=p,e.log(t.Trace,`(${n} transport) sending data. ${d(s,c)}.`);const f=g(s)?"arraybuffer":"text",w=await o.post(r,{content:s,headers:{...l,...h},responseType:f,withCredentials:a});e.log(t.Trace,`(${n} transport) request complete. Response status: ${w.statusCode}.`)}class f{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class w{constructor(t){this.l=t,this.out=console}log(e,n){if(e>=this.l){const o=`[${(new Date).toISOString()}] ${t[e]}: ${n}`;switch(e){case t.Critical:case t.Error:this.out.error(o);break;case t.Warning:this.out.warn(o);break;case t.Information:this.out.info(o);break;default:this.out.log(o)}}}}function b(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,y(h,m(),u.isNode?"NodeJS":"Browser",v())]}function y(t,e,n,o){let r="Microsoft SignalR/";const i=t.split(".");return r+=`${i[0]}.${i[1]}`,r+=` (${t}; `,r+=e&&""!==e?`${e}; `:"Unknown OS; ",r+=`${n}`,r+=o?`; ${o}`:"; Unknown Runtime Version",r+=")",r}function m(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class C extends c{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new i;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const n=new this.m;let c;e.abortSignal&&(e.abortSignal.onabort=()=>{n.abort(),c=new i});let a,h=null;if(e.timeout){const o=e.timeout;h=setTimeout((()=>{n.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),c=new r}),o)}try{a=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:n.signal})}catch(e){if(c)throw c;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{h&&clearTimeout(h),e.abortSignal&&(e.abortSignal.onabort=null)}if(!a.ok){const t=await S(a,"text");throw new o(t||a.statusText,a.status)}const l=S(a,e.responseType),u=await l;return new s(a.status,a.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,n)=>e=n.join("; "))),e}}function S(t,e){let n;switch(e){case"arraybuffer":n=t.arrayBuffer();break;case"text":n=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:n=t.text()}return n}class E extends c{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new i):e.method?e.url?new Promise(((n,c)=>{const a=new XMLHttpRequest;a.open(e.method,e.url,!0),a.withCredentials=void 0===e.withCredentials||e.withCredentials,a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const h=e.headers;h&&Object.keys(h).forEach((t=>{a.setRequestHeader(t,h[t])})),e.responseType&&(a.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{a.abort(),c(new i)}),e.timeout&&(a.timeout=e.timeout),a.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),a.status>=200&&a.status<300?n(new s(a.status,a.statusText,a.response||a.responseText)):c(new o(a.response||a.responseText||a.statusText,a.status))},a.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${a.status}: ${a.statusText}.`),c(new o(a.statusText,a.status))},a.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),c(new r)},a.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class $ extends c{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new C(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new E(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new i):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class I{static write(t){return`${t}${I.RecordSeparator}`}static parse(t){if(t[t.length-1]!==I.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(I.RecordSeparator);return e.pop(),e}}I.RecordSeparatorCode=30,I.RecordSeparator=String.fromCharCode(I.RecordSeparatorCode);class k{writeHandshakeRequest(t){return I.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,n;if(g(t)){const o=new Uint8Array(t),r=o.indexOf(I.RecordSeparatorCode);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(o.slice(0,i))),n=o.byteLength>i?o.slice(i).buffer:null}else{const o=t,r=o.indexOf(I.RecordSeparator);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=o.substring(0,i),n=o.length>i?o.substring(i):null}const o=I.parse(e),r=JSON.parse(o[0]);if(r.type)throw new Error("Expected a handshake response from the server.");return[n,r]}}var T,P;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class D{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new f(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(P||(P={}));class L{constructor(t,e,n,o){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(n,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=n,this.connection=t,this.S=o,this.k=new k,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=P.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,n,o){return new L(t,e,n,o)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==P.Disconnected&&this.L!==P.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==P.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=P.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=P.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=P.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const n={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(n)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===P.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===P.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=P.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[n,o]=this.st(e),r=this.nt(t,e,o);let i;const s=new D;return s.cancelCallback=()=>{const t=this.it(r.invocationId);return delete this.I[r.invocationId],i.then((()=>this.rt(t)))},this.I[r.invocationId]=(t,e)=>{e?s.error(e):t&&(t.type===T.Completion?t.error?s.error(new Error(t.error)):s.complete():s.next(t.item))},i=this.rt(r).catch((t=>{s.error(t),delete this.I[r.invocationId]})),this.ot(n,i),s}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[n,o]=this.st(e),r=this.rt(this.ht(t,e,!0,o));return this.ot(n,r),r}invoke(t,...e){const[n,o]=this.st(e),r=this.ht(t,e,!1,o);return new Promise(((t,e)=>{this.I[r.invocationId]=(n,o)=>{o?e(o):n&&(n.type===T.Completion?n.error?e(new Error(n.error)):t(n.result):e(new Error(`Unexpected message type: ${n.type}`)))};const o=this.rt(r).catch((t=>{e(t),delete this.I[r.invocationId]}));this.ot(n,o)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const n=this._[t];if(n)if(e){const o=n.indexOf(e);-1!==o&&(n.splice(o,1),0===n.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const n=this.C.parseMessages(e,this.u);for(const e of n)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const n=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(n):this.Y=this.Z(n);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let n,o;try{[o,n]=this.k.parseHandshakeResponse(e)}catch(e){const n="Error parsing handshake response: "+e;this.u.log(t.Error,n);const o=new Error(n);throw this.B(o),o}if(n.error){const e="Server returned handshake error: "+n.error;this.u.log(t.Error,e);const o=new Error(e);throw this.B(o),o}return this.u.log(t.Debug,"Server handshake complete."),this.F(),o}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===P.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const n=this._[e.target.toLowerCase()];if(n){try{n.forEach((t=>t.apply(this,e.arguments)))}catch(n){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${n}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===P.Disconnecting?this.et(e):this.L===P.Connected&&this.S?this.ft(e):this.L===P.Connected&&this.et(e)}et(e){if(this.N){this.L=P.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${n}'.`)}}}async ft(e){const n=Date.now();let o=0,r=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),i=this.wt(o++,0,r);if(null===i)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=P.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${n}'.`)}if(this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==i;){if(this.u.log(t.Information,`Reconnect attempt number ${o} will start in ${i} ms.`),await new Promise((t=>{this.tt=setTimeout(t,i)})),this.tt=void 0,this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=P.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==P.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===P.Disconnecting&&this.et());r=e instanceof Error?e:new Error(e.toString()),i=this.wt(o++,Date.now()-n,r)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-n} ms and ${o} failed attempts. Connection disconnecting.`),this.et()}wt(e,n,o){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:n,previousRetryCount:e,retryReason:o})}catch(o){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${n}) threw error '${o}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((n=>{(0,e[n])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,n,o){if(n)return 0!==o.length?{arguments:e,streamIds:o,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const n=this.R;return this.R++,0!==o.length?{arguments:e,invocationId:n.toString(),streamIds:o,target:t,type:T.Invocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const n in t)t[n].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(n))))},error:t=>{let o;o=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(n,o))))},next:t=>{e=e.then((()=>this.rt(this.yt(n,t))))}})}}st(t){const e=[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(this.bt(r)){const i=this.R;this.R++,e[i]=r,n.push(i.toString()),t.splice(o,1)}}return[e,n]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,n){const o=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:o.toString(),streamIds:n,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:o.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,n){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:n,type:T.Completion}}}const R=[0,2e3,1e4,3e4,null];class x{constructor(t){this.vt=void 0!==t?[...t,null]:R}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class H{}var N,W;H.Authorization="Authorization",H.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(N||(N={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(W||(W={}));class j{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class A{constructor(t,e,n,o,r,i){this.v=t,this.$t=e,this.u=n,this.Ct=new j,this.St=o,this.kt=r,this.Pt=i,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),n===W.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[r,i]=b(),s={[r]:i,...this.Pt},c={abortSignal:this.Ct.signal,headers:s,timeout:1e5,withCredentials:this.kt};n===W.Binary&&(c.responseType="arraybuffer");const a=await this._t();this.Ht(c,a);const h=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${h}.`);const u=await this.v.get(h,c);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new o(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,c)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[H.Authorization]=`Bearer ${e}`:t.headers[H.Authorization]&&delete t.headers[H.Authorization]}async Rt(e,n){try{for(;this.Tt;){const i=await this._t();this.Ht(n,i);try{const r=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${r}.`);const i=await this.v.get(r,n);204===i.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==i.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${i.statusCode}.`),this.Dt=new o(i.statusText||"",i.statusCode),this.Tt=!1):i.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(i.content,this.St)}.`),this.onreceive&&this.onreceive(i.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof r?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[n,o]=b();e[n]=o;const r={headers:{...e,...this.Pt},withCredentials:this.kt},i=await this._t();this.Ht(r,i),await this.v.delete(this.It,r),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,n,o,r,i,s){this.v=t,this.$t=e,this.u=n,this.St=o,this.kt=i,this.xt=r,this.Pt=s,this.onreceive=null,this.onclose=null}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i,s=!1;if(n===W.Text){if(u.isBrowser||u.isWebWorker)i=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),n={};n.Cookie=t;const[o,r]=b();n[o]=r,i=new this.xt(e,{withCredentials:this.kt,headers:{...n,...this.Pt}})}try{i.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onerror=t=>{s?this.Lt():r(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},i.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=i,s=!0,o()}}catch(t){return void r(t)}}else r(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class B{constructor(t,e,n,o,r,i){this.u=n,this.$t=e,this.St=o,this.qt=r,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=i}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i;e=e.replace(/^http/,"ws");const s=this.v.getCookieString(e);let c=!1;if(u.isNode){const t={},[n,o]=b();t[n]=o,s&&(t[H.Cookie]=`${s}`),i=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}i||(i=new this.qt(e)),n===W.Binary&&(i.binaryType="arraybuffer"),i.onopen=n=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=i,c=!0,o()},i.onerror=e=>{let n=null;n="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${n}.`)},i.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onclose=t=>{if(c)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",r(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,n={}){var o;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(o=n.logger)?new w(t.Information):null===o?a.instance:void 0!==o.log?o:new w(o),this.baseUrl=this.Ft(e),(n=n||{}).logMessageContent=void 0!==n.logMessageContent&&n.logMessageContent,"boolean"!=typeof n.withCredentials&&void 0!==n.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");n.withCredentials=void 0===n.withCredentials||n.withCredentials;let r=null,i=null;if(u.isNode){const t=require;r=t("ws"),i=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||n.WebSocket?u.isNode&&!n.WebSocket&&r&&(n.WebSocket=r):n.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||n.EventSource?u.isNode&&!n.EventSource&&void 0!==i&&(n.EventSource=i):n.EventSource=EventSource,this.v=n.httpClient||new $(this.u),this.L="Disconnected",this.N=!1,this.Bt=n,this.onreceive=null,this.onclose=null}async start(e){if(e=e||W.Binary,l.isIn(e,W,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${W[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new U(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let n=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==N.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(N.WebSockets),await this.Kt(n,e)}else{let t=null,o=0;do{if(t=await this.Qt(n),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(n=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}o++}while(t.url&&o<100);if(100===o&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(n,this.Bt.transport,t,e)}this.transport instanceof A&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const n={};if(this.$t){const t=await this.$t();t&&(n[H.Authorization]=`Bearer ${t}`)}const[r,i]=b();n[r]=i;const s=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${s}.`);try{const t=await this.v.post(s,{content:"",headers:{...n,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let n="Failed to complete negotiation with the server: "+e;return e instanceof o&&404===e.statusCode&&(n+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,n),Promise.reject(new Error(n))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,n,o,r){let i=this.te(e,o.connectionToken);if(this.ee(n))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=n,await this.Kt(i,r),void(this.connectionId=o.connectionId);const s=[],c=o.availableTransports||[];let a=o;for(const o of c){const c=this.se(o,n,r);if(c instanceof Error)s.push(`${o.transport} failed: ${c}`);else if(this.ee(c)){if(this.transport=c,!a){try{a=await this.Qt(e)}catch(t){return Promise.reject(t)}i=this.te(e,a.connectionToken)}try{return await this.Kt(i,r),void(this.connectionId=a.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${o.transport}': ${e}`),a=void 0,s.push(`${o.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return s.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${s.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case N.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new B(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case N.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case N.LongPolling:return new A(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,n,o){const r=N[e.transport];if(null==r)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(n,r))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it was disabled by the client.`),new Error(`'${N[r]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>W[t])).indexOf(o)>=0))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it does not support the requested transfer format '${W[o]}'.`),new Error(`'${N[r]}' does not support ${W[o]}.`);if(r===N.WebSockets&&!this.Bt.WebSocket||r===N.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it is not supported in your environment.'`),new Error(`'${N[r]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${N[r]}'.`);try{return this.Gt(r)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(n){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${n}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const n=window.document.createElement("a");return n.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${n.href}'.`),n.href}Zt(t){const e=t.indexOf("?");let n=t.substring(0,-1===e?t.length:e);return"/"!==n[n.length-1]&&(n+="/"),n+="negotiate",n+=-1===e?"":t.substring(e),-1===n.indexOf("negotiateVersion")&&(n+=-1===e?"?":"&",n+="negotiateVersion="+this.jt),n}}class U{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new M,this.he=new M,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new M),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new M;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):U.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),n=new Uint8Array(e);let o=0;for(const e of t)n.set(new Uint8Array(e),o),o+=e.byteLength;return n.buffer}}class M{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class _{constructor(){this.name="json",this.version=1,this.transferFormat=W.Text}parseMessages(e,n){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===n&&(n=a.instance);const o=I.parse(e),r=[];for(const e of o){const o=JSON.parse(e);if("number"!=typeof o.type)throw new Error("Invalid payload.");switch(o.type){case T.Invocation:this.pe(o);break;case T.StreamItem:this.we(o);break;case T.Completion:this.ge(o);break;case T.Ping:case T.Close:break;default:n.log(t.Information,"Unknown message type '"+o.type+"' ignored.");continue}r.push(o)}return r}writeMessage(t){return I.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const F={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class J{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=F[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new w(e)}else this.logger=new w(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new x(t):this.reconnectPolicy=t:this.reconnectPolicy=new x,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return L.create(e,this.logger||a.instance,this.protocol||new _,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),n})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); | ||
var t,e;t=self,e=function(){return(()=>{var t,e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"t",{value:!0})}},n={};e.r(n),e.d(n,{AbortError:()=>i,DefaultHttpClient:()=>$,HttpClient:()=>c,HttpError:()=>o,HttpResponse:()=>s,HttpTransportType:()=>N,HubConnection:()=>L,HubConnectionBuilder:()=>J,HubConnectionState:()=>P,JsonHubProtocol:()=>_,LogLevel:()=>t,MessageType:()=>T,NullLogger:()=>a,Subject:()=>D,TimeoutError:()=>r,TransferFormat:()=>W,VERSION:()=>h});class o extends Error{constructor(t,e){const n=new.target.prototype;super(`${t}: Status code '${e}'`),this.statusCode=e,this.__proto__=n}}class r extends Error{constructor(t="A timeout occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class i extends Error{constructor(t="An abort occurred."){const e=new.target.prototype;super(t),this.__proto__=e}}class s{constructor(t,e,n){this.statusCode=t,this.statusText=e,this.content=n}}class c{get(t,e){return this.send({...e,method:"GET",url:t})}post(t,e){return this.send({...e,method:"POST",url:t})}delete(t,e){return this.send({...e,method:"DELETE",url:t})}getCookieString(t){return""}}!function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"}(t||(t={}));class a{constructor(){}log(t,e){}}a.instance=new a;const h="6.0.0-preview.6.21355.2";class l{static isRequired(t,e){if(null==t)throw new Error(`The '${e}' argument is required.`)}static isNotEmpty(t,e){if(!t||t.match(/^\s*$/))throw new Error(`The '${e}' argument should not be empty.`)}static isIn(t,e,n){if(!(t in e))throw new Error(`Unknown ${n} value: ${t}.`)}}class u{static get isBrowser(){return"object"==typeof window}static get isWebWorker(){return"object"==typeof self&&"importScripts"in self}static get isNode(){return!this.isBrowser&&!this.isWebWorker}}function d(t,e){let n="";return g(t)?(n=`Binary data of length ${t.byteLength}`,e&&(n+=`. Content: '${function(t){const e=new Uint8Array(t);let n="";return e.forEach((t=>{n+=`0x${t<16?"0":""}${t.toString(16)} `})),n.substr(0,n.length-1)}(t)}'`)):"string"==typeof t&&(n=`String data of length ${t.length}`,e&&(n+=`. Content: '${t}'`)),n}function g(t){return t&&"undefined"!=typeof ArrayBuffer&&(t instanceof ArrayBuffer||t.constructor&&"ArrayBuffer"===t.constructor.name)}async function p(e,n,o,r,i,s,c,a,h){let l={};if(i){const t=await i();t&&(l={Authorization:`Bearer ${t}`})}const[u,p]=b();l[u]=p,e.log(t.Trace,`(${n} transport) sending data. ${d(s,c)}.`);const f=g(s)?"arraybuffer":"text",w=await o.post(r,{content:s,headers:{...l,...h},responseType:f,withCredentials:a});e.log(t.Trace,`(${n} transport) request complete. Response status: ${w.statusCode}.`)}class f{constructor(t,e){this.i=t,this.h=e}dispose(){const t=this.i.observers.indexOf(this.h);t>-1&&this.i.observers.splice(t,1),0===this.i.observers.length&&this.i.cancelCallback&&this.i.cancelCallback().catch((t=>{}))}}class w{constructor(t){this.l=t,this.out=console}log(e,n){if(e>=this.l){const o=`[${(new Date).toISOString()}] ${t[e]}: ${n}`;switch(e){case t.Critical:case t.Error:this.out.error(o);break;case t.Warning:this.out.warn(o);break;case t.Information:this.out.info(o);break;default:this.out.log(o)}}}}function b(){let t="X-SignalR-User-Agent";return u.isNode&&(t="User-Agent"),[t,y(h,m(),u.isNode?"NodeJS":"Browser",v())]}function y(t,e,n,o){let r="Microsoft SignalR/";const i=t.split(".");return r+=`${i[0]}.${i[1]}`,r+=` (${t}; `,r+=e&&""!==e?`${e}; `:"Unknown OS; ",r+=`${n}`,r+=o?`; ${o}`:"; Unknown Runtime Version",r+=")",r}function m(){if(!u.isNode)return"";switch(process.platform){case"win32":return"Windows NT";case"darwin":return"macOS";case"linux":return"Linux";default:return process.platform}}function v(){if(u.isNode)return process.versions.node}class C extends c{constructor(t){if(super(),this.u=t,"undefined"==typeof fetch){const t=require;this.p=new(t("tough-cookie").CookieJar),this.g=t("node-fetch"),this.g=t("fetch-cookie")(this.g,this.p),this.m=t("abort-controller")}else this.g=fetch.bind(self),this.m=AbortController}async send(e){if(e.abortSignal&&e.abortSignal.aborted)throw new i;if(!e.method)throw new Error("No method defined.");if(!e.url)throw new Error("No url defined.");const n=new this.m;let c;e.abortSignal&&(e.abortSignal.onabort=()=>{n.abort(),c=new i});let a,h=null;if(e.timeout){const o=e.timeout;h=setTimeout((()=>{n.abort(),this.u.log(t.Warning,"Timeout from HTTP request."),c=new r}),o)}try{a=await this.g(e.url,{body:e.content,cache:"no-cache",credentials:!0===e.withCredentials?"include":"same-origin",headers:{"Content-Type":"text/plain;charset=UTF-8","X-Requested-With":"XMLHttpRequest",...e.headers},method:e.method,mode:"cors",redirect:"follow",signal:n.signal})}catch(e){if(c)throw c;throw this.u.log(t.Warning,`Error from HTTP request. ${e}.`),e}finally{h&&clearTimeout(h),e.abortSignal&&(e.abortSignal.onabort=null)}if(!a.ok){const t=await S(a,"text");throw new o(t||a.statusText,a.status)}const l=S(a,e.responseType),u=await l;return new s(a.status,a.statusText,u)}getCookieString(t){let e="";return u.isNode&&this.p&&this.p.getCookies(t,((t,n)=>e=n.join("; "))),e}}function S(t,e){let n;switch(e){case"arraybuffer":n=t.arrayBuffer();break;case"text":n=t.text();break;case"blob":case"document":case"json":throw new Error(`${e} is not supported.`);default:n=t.text()}return n}class E extends c{constructor(t){super(),this.u=t}send(e){return e.abortSignal&&e.abortSignal.aborted?Promise.reject(new i):e.method?e.url?new Promise(((n,c)=>{const a=new XMLHttpRequest;a.open(e.method,e.url,!0),a.withCredentials=void 0===e.withCredentials||e.withCredentials,a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.setRequestHeader("Content-Type","text/plain;charset=UTF-8");const h=e.headers;h&&Object.keys(h).forEach((t=>{a.setRequestHeader(t,h[t])})),e.responseType&&(a.responseType=e.responseType),e.abortSignal&&(e.abortSignal.onabort=()=>{a.abort(),c(new i)}),e.timeout&&(a.timeout=e.timeout),a.onload=()=>{e.abortSignal&&(e.abortSignal.onabort=null),a.status>=200&&a.status<300?n(new s(a.status,a.statusText,a.response||a.responseText)):c(new o(a.response||a.responseText||a.statusText,a.status))},a.onerror=()=>{this.u.log(t.Warning,`Error from HTTP request. ${a.status}: ${a.statusText}.`),c(new o(a.statusText,a.status))},a.ontimeout=()=>{this.u.log(t.Warning,"Timeout from HTTP request."),c(new r)},a.send(e.content||"")})):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}}class $ extends c{constructor(t){if(super(),"undefined"!=typeof fetch||u.isNode)this.v=new C(t);else{if("undefined"==typeof XMLHttpRequest)throw new Error("No usable HttpClient found.");this.v=new E(t)}}send(t){return t.abortSignal&&t.abortSignal.aborted?Promise.reject(new i):t.method?t.url?this.v.send(t):Promise.reject(new Error("No url defined.")):Promise.reject(new Error("No method defined."))}getCookieString(t){return this.v.getCookieString(t)}}class I{static write(t){return`${t}${I.RecordSeparator}`}static parse(t){if(t[t.length-1]!==I.RecordSeparator)throw new Error("Message is incomplete.");const e=t.split(I.RecordSeparator);return e.pop(),e}}I.RecordSeparatorCode=30,I.RecordSeparator=String.fromCharCode(I.RecordSeparatorCode);class k{writeHandshakeRequest(t){return I.write(JSON.stringify(t))}parseHandshakeResponse(t){let e,n;if(g(t)){const o=new Uint8Array(t),r=o.indexOf(I.RecordSeparatorCode);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=String.fromCharCode.apply(null,Array.prototype.slice.call(o.slice(0,i))),n=o.byteLength>i?o.slice(i).buffer:null}else{const o=t,r=o.indexOf(I.RecordSeparator);if(-1===r)throw new Error("Message is incomplete.");const i=r+1;e=o.substring(0,i),n=o.length>i?o.substring(i):null}const o=I.parse(e),r=JSON.parse(o[0]);if(r.type)throw new Error("Expected a handshake response from the server.");return[n,r]}}var T,P;!function(t){t[t.Invocation=1]="Invocation",t[t.StreamItem=2]="StreamItem",t[t.Completion=3]="Completion",t[t.StreamInvocation=4]="StreamInvocation",t[t.CancelInvocation=5]="CancelInvocation",t[t.Ping=6]="Ping",t[t.Close=7]="Close"}(T||(T={}));class D{constructor(){this.observers=[]}next(t){for(const e of this.observers)e.next(t)}error(t){for(const e of this.observers)e.error&&e.error(t)}complete(){for(const t of this.observers)t.complete&&t.complete()}subscribe(t){return this.observers.push(t),new f(this,t)}}!function(t){t.Disconnected="Disconnected",t.Connecting="Connecting",t.Connected="Connected",t.Disconnecting="Disconnecting",t.Reconnecting="Reconnecting"}(P||(P={}));class L{constructor(t,e,n,o){this.$=0,l.isRequired(t,"connection"),l.isRequired(e,"logger"),l.isRequired(n,"protocol"),this.serverTimeoutInMilliseconds=3e4,this.keepAliveIntervalInMilliseconds=15e3,this.u=e,this.C=n,this.connection=t,this.S=o,this.k=new k,this.connection.onreceive=t=>this.P(t),this.connection.onclose=t=>this.T(t),this.I={},this._={},this.H=[],this.D=[],this.A=[],this.R=0,this.U=!1,this.L=P.Disconnected,this.N=!1,this.q=this.C.writeMessage({type:T.Ping})}static create(t,e,n,o){return new L(t,e,n,o)}get state(){return this.L}get connectionId(){return this.connection&&this.connection.connectionId||null}get baseUrl(){return this.connection.baseUrl||""}set baseUrl(t){if(this.L!==P.Disconnected&&this.L!==P.Reconnecting)throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");if(!t)throw new Error("The HubConnection url must be a valid url.");this.connection.baseUrl=t}start(){return this.M=this.O(),this.M}async O(){if(this.L!==P.Disconnected)return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));this.L=P.Connecting,this.u.log(t.Debug,"Starting HubConnection.");try{await this.W(),this.L=P.Connected,this.N=!0,this.u.log(t.Debug,"HubConnection connected successfully.")}catch(e){return this.L=P.Disconnected,this.u.log(t.Debug,`HubConnection failed to start successfully because of error '${e}'.`),Promise.reject(e)}}async W(){this.j=void 0,this.U=!1;const e=new Promise(((t,e)=>{this.F=t,this.B=e}));await this.connection.start(this.C.transferFormat);try{const n={protocol:this.C.name,version:this.C.version};if(this.u.log(t.Debug,"Sending handshake request."),await this.X(this.k.writeHandshakeRequest(n)),this.u.log(t.Information,`Using HubProtocol '${this.C.name}'.`),this.J(),this.V(),this.G(),await e,this.j)throw this.j}catch(e){throw this.u.log(t.Debug,`Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`),this.J(),this.K(),await this.connection.stop(e),e}}async stop(){const t=this.M;this.Y=this.Z(),await this.Y;try{await t}catch(t){}}Z(e){return this.L===P.Disconnected?(this.u.log(t.Debug,`Call to HubConnection.stop(${e}) ignored because it is already in the disconnected state.`),Promise.resolve()):this.L===P.Disconnecting?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L=P.Disconnecting,this.u.log(t.Debug,"Stopping HubConnection."),this.tt?(this.u.log(t.Debug,"Connection stopped during reconnect delay. Done reconnecting."),clearTimeout(this.tt),this.tt=void 0,this.et(),Promise.resolve()):(this.J(),this.K(),this.j=e||new Error("The connection was stopped before the hub handshake could complete."),this.connection.stop(e)))}stream(t,...e){const[n,o]=this.st(e),r=this.nt(t,e,o);let i;const s=new D;return s.cancelCallback=()=>{const t=this.it(r.invocationId);return delete this.I[r.invocationId],i.then((()=>this.rt(t)))},this.I[r.invocationId]=(t,e)=>{e?s.error(e):t&&(t.type===T.Completion?t.error?s.error(new Error(t.error)):s.complete():s.next(t.item))},i=this.rt(r).catch((t=>{s.error(t),delete this.I[r.invocationId]})),this.ot(n,i),s}X(t){return this.G(),this.connection.send(t)}rt(t){return this.X(this.C.writeMessage(t))}send(t,...e){const[n,o]=this.st(e),r=this.rt(this.ht(t,e,!0,o));return this.ot(n,r),r}invoke(t,...e){const[n,o]=this.st(e),r=this.ht(t,e,!1,o);return new Promise(((t,e)=>{this.I[r.invocationId]=(n,o)=>{o?e(o):n&&(n.type===T.Completion?n.error?e(new Error(n.error)):t(n.result):e(new Error(`Unexpected message type: ${n.type}`)))};const o=this.rt(r).catch((t=>{e(t),delete this.I[r.invocationId]}));this.ot(n,o)}))}on(t,e){t&&e&&(t=t.toLowerCase(),this._[t]||(this._[t]=[]),-1===this._[t].indexOf(e)&&this._[t].push(e))}off(t,e){if(!t)return;t=t.toLowerCase();const n=this._[t];if(n)if(e){const o=n.indexOf(e);-1!==o&&(n.splice(o,1),0===n.length&&delete this._[t])}else delete this._[t]}onclose(t){t&&this.H.push(t)}onreconnecting(t){t&&this.D.push(t)}onreconnected(t){t&&this.A.push(t)}P(e){if(this.J(),this.U||(e=this.ct(e),this.U=!0),e){const n=this.C.parseMessages(e,this.u);for(const e of n)switch(e.type){case T.Invocation:this.at(e);break;case T.StreamItem:case T.Completion:{const t=this.I[e.invocationId];t&&(e.type===T.Completion&&delete this.I[e.invocationId],t(e));break}case T.Ping:break;case T.Close:{this.u.log(t.Information,"Close message received from server.");const n=e.error?new Error("Server returned an error on close: "+e.error):void 0;!0===e.allowReconnect?this.connection.stop(n):this.Y=this.Z(n);break}default:this.u.log(t.Warning,`Invalid message type: ${e.type}.`)}}this.V()}ct(e){let n,o;try{[o,n]=this.k.parseHandshakeResponse(e)}catch(e){const n="Error parsing handshake response: "+e;this.u.log(t.Error,n);const o=new Error(n);throw this.B(o),o}if(n.error){const e="Server returned handshake error: "+n.error;this.u.log(t.Error,e);const o=new Error(e);throw this.B(o),o}return this.u.log(t.Debug,"Server handshake complete."),this.F(),o}G(){this.connection.features.inherentKeepAlive||(this.$=(new Date).getTime()+this.keepAliveIntervalInMilliseconds,this.K())}V(){if(!(this.connection.features&&this.connection.features.inherentKeepAlive||(this.lt=setTimeout((()=>this.serverTimeout()),this.serverTimeoutInMilliseconds),void 0!==this.ut))){let t=this.$-(new Date).getTime();t<0&&(t=0),this.ut=setTimeout((async()=>{if(this.L===P.Connected)try{await this.X(this.q)}catch{this.K()}}),t)}}serverTimeout(){this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."))}at(e){const n=this._[e.target.toLowerCase()];if(n){try{n.forEach((t=>t.apply(this,e.arguments)))}catch(n){this.u.log(t.Error,`A callback for the method ${e.target.toLowerCase()} threw error '${n}'.`)}if(e.invocationId){const e="Server requested a response, which is not supported in this version of the client.";this.u.log(t.Error,e),this.Y=this.Z(new Error(e))}}else this.u.log(t.Warning,`No client method with the name '${e.target}' found.`)}T(e){this.u.log(t.Debug,`HubConnection.connectionClosed(${e}) called while in state ${this.L}.`),this.j=this.j||e||new Error("The underlying connection was closed before the hub handshake could complete."),this.F&&this.F(),this.dt(e||new Error("Invocation canceled due to the underlying connection being closed.")),this.J(),this.K(),this.L===P.Disconnecting?this.et(e):this.L===P.Connected&&this.S?this.ft(e):this.L===P.Connected&&this.et(e)}et(e){if(this.N){this.L=P.Disconnected,this.N=!1;try{this.H.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onclose callback called with error '${e}' threw error '${n}'.`)}}}async ft(e){const n=Date.now();let o=0,r=void 0!==e?e:new Error("Attempting to reconnect due to a unknown error."),i=this.wt(o++,0,r);if(null===i)return this.u.log(t.Debug,"Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."),void this.et(e);if(this.L=P.Reconnecting,e?this.u.log(t.Information,`Connection reconnecting because of error '${e}'.`):this.u.log(t.Information,"Connection reconnecting."),0!==this.D.length){try{this.D.forEach((t=>t.apply(this,[e])))}catch(n){this.u.log(t.Error,`An onreconnecting callback called with error '${e}' threw error '${n}'.`)}if(this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state in onreconnecting callback. Done reconnecting.")}for(;null!==i;){if(this.u.log(t.Information,`Reconnect attempt number ${o} will start in ${i} ms.`),await new Promise((t=>{this.tt=setTimeout(t,i)})),this.tt=void 0,this.L!==P.Reconnecting)return void this.u.log(t.Debug,"Connection left the reconnecting state during reconnect delay. Done reconnecting.");try{if(await this.W(),this.L=P.Connected,this.u.log(t.Information,"HubConnection reconnected successfully."),0!==this.A.length)try{this.A.forEach((t=>t.apply(this,[this.connection.connectionId])))}catch(e){this.u.log(t.Error,`An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`)}return}catch(e){if(this.u.log(t.Information,`Reconnect attempt failed because of error '${e}'.`),this.L!==P.Reconnecting)return this.u.log(t.Debug,`Connection moved to the '${this.L}' from the reconnecting state during reconnect attempt. Done reconnecting.`),void(this.L===P.Disconnecting&&this.et());r=e instanceof Error?e:new Error(e.toString()),i=this.wt(o++,Date.now()-n,r)}}this.u.log(t.Information,`Reconnect retries have been exhausted after ${Date.now()-n} ms and ${o} failed attempts. Connection disconnecting.`),this.et()}wt(e,n,o){try{return this.S.nextRetryDelayInMilliseconds({elapsedMilliseconds:n,previousRetryCount:e,retryReason:o})}catch(o){return this.u.log(t.Error,`IRetryPolicy.nextRetryDelayInMilliseconds(${e}, ${n}) threw error '${o}'.`),null}}dt(t){const e=this.I;this.I={},Object.keys(e).forEach((n=>{(0,e[n])(null,t)}))}K(){this.ut&&(clearTimeout(this.ut),this.ut=void 0)}J(){this.lt&&clearTimeout(this.lt)}ht(t,e,n,o){if(n)return 0!==o.length?{arguments:e,streamIds:o,target:t,type:T.Invocation}:{arguments:e,target:t,type:T.Invocation};{const n=this.R;return this.R++,0!==o.length?{arguments:e,invocationId:n.toString(),streamIds:o,target:t,type:T.Invocation}:{arguments:e,invocationId:n.toString(),target:t,type:T.Invocation}}}ot(t,e){if(0!==t.length){e||(e=Promise.resolve());for(const n in t)t[n].subscribe({complete:()=>{e=e.then((()=>this.rt(this.gt(n))))},error:t=>{let o;o=t instanceof Error?t.message:t&&t.toString?t.toString():"Unknown error",e=e.then((()=>this.rt(this.gt(n,o))))},next:t=>{e=e.then((()=>this.rt(this.yt(n,t))))}})}}st(t){const e=[],n=[];for(let o=0;o<t.length;o++){const r=t[o];if(this.bt(r)){const i=this.R;this.R++,e[i]=r,n.push(i.toString()),t.splice(o,1)}}return[e,n]}bt(t){return t&&t.subscribe&&"function"==typeof t.subscribe}nt(t,e,n){const o=this.R;return this.R++,0!==n.length?{arguments:e,invocationId:o.toString(),streamIds:n,target:t,type:T.StreamInvocation}:{arguments:e,invocationId:o.toString(),target:t,type:T.StreamInvocation}}it(t){return{invocationId:t,type:T.CancelInvocation}}yt(t,e){return{invocationId:t,item:e,type:T.StreamItem}}gt(t,e,n){return e?{error:e,invocationId:t,type:T.Completion}:{invocationId:t,result:n,type:T.Completion}}}const R=[0,2e3,1e4,3e4,null];class x{constructor(t){this.vt=void 0!==t?[...t,null]:R}nextRetryDelayInMilliseconds(t){return this.vt[t.previousRetryCount]}}class H{}var N,W;H.Authorization="Authorization",H.Cookie="Cookie",function(t){t[t.None=0]="None",t[t.WebSockets=1]="WebSockets",t[t.ServerSentEvents=2]="ServerSentEvents",t[t.LongPolling=4]="LongPolling"}(N||(N={})),function(t){t[t.Text=1]="Text",t[t.Binary=2]="Binary"}(W||(W={}));class j{constructor(){this.Et=!1,this.onabort=null}abort(){this.Et||(this.Et=!0,this.onabort&&this.onabort())}get signal(){return this}get aborted(){return this.Et}}class A{constructor(t,e,n,o,r,i){this.v=t,this.$t=e,this.u=n,this.Ct=new j,this.St=o,this.kt=r,this.Pt=i,this.Tt=!1,this.onreceive=null,this.onclose=null}get pollAborted(){return this.Ct.aborted}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.It=e,this.u.log(t.Trace,"(LongPolling transport) Connecting."),n===W.Binary&&"undefined"!=typeof XMLHttpRequest&&"string"!=typeof(new XMLHttpRequest).responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");const[r,i]=b(),s={[r]:i,...this.Pt},c={abortSignal:this.Ct.signal,headers:s,timeout:1e5,withCredentials:this.kt};n===W.Binary&&(c.responseType="arraybuffer");const a=await this._t();this.Ht(c,a);const h=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${h}.`);const u=await this.v.get(h,c);200!==u.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${u.statusCode}.`),this.Dt=new o(u.statusText||"",u.statusCode),this.Tt=!1):this.Tt=!0,this.At=this.Rt(this.It,c)}async _t(){return this.$t?await this.$t():null}Ht(t,e){t.headers||(t.headers={}),e?t.headers[H.Authorization]=`Bearer ${e}`:t.headers[H.Authorization]&&delete t.headers[H.Authorization]}async Rt(e,n){try{for(;this.Tt;){const i=await this._t();this.Ht(n,i);try{const r=`${e}&_=${Date.now()}`;this.u.log(t.Trace,`(LongPolling transport) polling: ${r}.`);const i=await this.v.get(r,n);204===i.statusCode?(this.u.log(t.Information,"(LongPolling transport) Poll terminated by server."),this.Tt=!1):200!==i.statusCode?(this.u.log(t.Error,`(LongPolling transport) Unexpected response code: ${i.statusCode}.`),this.Dt=new o(i.statusText||"",i.statusCode),this.Tt=!1):i.content?(this.u.log(t.Trace,`(LongPolling transport) data received. ${d(i.content,this.St)}.`),this.onreceive&&this.onreceive(i.content)):this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing.")}catch(e){this.Tt?e instanceof r?this.u.log(t.Trace,"(LongPolling transport) Poll timed out, reissuing."):(this.Dt=e,this.Tt=!1):this.u.log(t.Trace,`(LongPolling transport) Poll errored after shutdown: ${e.message}`)}}}finally{this.u.log(t.Trace,"(LongPolling transport) Polling complete."),this.pollAborted||this.Ut()}}async send(t){return this.Tt?p(this.u,"LongPolling",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}async stop(){this.u.log(t.Trace,"(LongPolling transport) Stopping polling."),this.Tt=!1,this.Ct.abort();try{await this.At,this.u.log(t.Trace,`(LongPolling transport) sending DELETE request to ${this.It}.`);const e={},[n,o]=b();e[n]=o;const r={headers:{...e,...this.Pt},withCredentials:this.kt},i=await this._t();this.Ht(r,i),await this.v.delete(this.It,r),this.u.log(t.Trace,"(LongPolling transport) DELETE request sent.")}finally{this.u.log(t.Trace,"(LongPolling transport) Stop finished."),this.Ut()}}Ut(){if(this.onclose){let e="(LongPolling transport) Firing onclose event.";this.Dt&&(e+=" Error: "+this.Dt),this.u.log(t.Trace,e),this.onclose(this.Dt)}}}class q{constructor(t,e,n,o,r,i,s){this.v=t,this.$t=e,this.u=n,this.St=o,this.kt=i,this.xt=r,this.Pt=s,this.onreceive=null,this.onclose=null}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(SSE transport) Connecting."),this.It=e,this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i,s=!1;if(n===W.Text){if(u.isBrowser||u.isWebWorker)i=new this.xt(e,{withCredentials:this.kt});else{const t=this.v.getCookieString(e),n={};n.Cookie=t;const[o,r]=b();n[o]=r,i=new this.xt(e,{withCredentials:this.kt,headers:{...n,...this.Pt}})}try{i.onmessage=e=>{if(this.onreceive)try{this.u.log(t.Trace,`(SSE transport) data received. ${d(e.data,this.St)}.`),this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onerror=t=>{s?this.Lt():r(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."))},i.onopen=()=>{this.u.log(t.Information,`SSE connected to ${this.It}`),this.Nt=i,s=!0,o()}}catch(t){return void r(t)}}else r(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"))}))}async send(t){return this.Nt?p(this.u,"SSE",this.v,this.It,this.$t,t,this.St,this.kt,this.Pt):Promise.reject(new Error("Cannot send until the transport is connected"))}stop(){return this.Lt(),Promise.resolve()}Lt(t){this.Nt&&(this.Nt.close(),this.Nt=void 0,this.onclose&&this.onclose(t))}}class B{constructor(t,e,n,o,r,i){this.u=n,this.$t=e,this.St=o,this.qt=r,this.v=t,this.onreceive=null,this.onclose=null,this.Pt=i}async connect(e,n){if(l.isRequired(e,"url"),l.isRequired(n,"transferFormat"),l.isIn(n,W,"transferFormat"),this.u.log(t.Trace,"(WebSockets transport) Connecting."),this.$t){const t=await this.$t();t&&(e+=(e.indexOf("?")<0?"?":"&")+`access_token=${encodeURIComponent(t)}`)}return new Promise(((o,r)=>{let i;e=e.replace(/^http/,"ws");const s=this.v.getCookieString(e);let c=!1;if(u.isNode){const t={},[n,o]=b();t[n]=o,s&&(t[H.Cookie]=`${s}`),i=new this.qt(e,void 0,{headers:{...t,...this.Pt}})}i||(i=new this.qt(e)),n===W.Binary&&(i.binaryType="arraybuffer"),i.onopen=n=>{this.u.log(t.Information,`WebSocket connected to ${e}.`),this.Mt=i,c=!0,o()},i.onerror=e=>{let n=null;n="undefined"!=typeof ErrorEvent&&e instanceof ErrorEvent?e.error:"There was an error with the transport",this.u.log(t.Information,`(WebSockets transport) ${n}.`)},i.onmessage=e=>{if(this.u.log(t.Trace,`(WebSockets transport) data received. ${d(e.data,this.St)}.`),this.onreceive)try{this.onreceive(e.data)}catch(t){return void this.Lt(t)}},i.onclose=t=>{if(c)this.Lt(t);else{let e=null;e="undefined"!=typeof ErrorEvent&&t instanceof ErrorEvent?t.error:"WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.",r(new Error(e))}}}))}send(e){return this.Mt&&this.Mt.readyState===this.qt.OPEN?(this.u.log(t.Trace,`(WebSockets transport) sending data. ${d(e,this.St)}.`),this.Mt.send(e),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){return this.Mt&&this.Lt(void 0),Promise.resolve()}Lt(e){this.Mt&&(this.Mt.onclose=()=>{},this.Mt.onmessage=()=>{},this.Mt.onerror=()=>{},this.Mt.close(),this.Mt=void 0),this.u.log(t.Trace,"(WebSockets transport) socket closed."),this.onclose&&(!this.Ot(e)||!1!==e.wasClean&&1e3===e.code?e instanceof Error?this.onclose(e):this.onclose():this.onclose(new Error(`WebSocket closed with status code: ${e.code} (${e.reason||"no reason given"}).`)))}Ot(t){return t&&"boolean"==typeof t.wasClean&&"number"==typeof t.code}}class O{constructor(e,n={}){var o;if(this.Wt=()=>{},this.features={},this.jt=1,l.isRequired(e,"url"),this.u=void 0===(o=n.logger)?new w(t.Information):null===o?a.instance:void 0!==o.log?o:new w(o),this.baseUrl=this.Ft(e),(n=n||{}).logMessageContent=void 0!==n.logMessageContent&&n.logMessageContent,"boolean"!=typeof n.withCredentials&&void 0!==n.withCredentials)throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");n.withCredentials=void 0===n.withCredentials||n.withCredentials;let r=null,i=null;if(u.isNode){const t=require;r=t("ws"),i=t("eventsource")}u.isNode||"undefined"==typeof WebSocket||n.WebSocket?u.isNode&&!n.WebSocket&&r&&(n.WebSocket=r):n.WebSocket=WebSocket,u.isNode||"undefined"==typeof EventSource||n.EventSource?u.isNode&&!n.EventSource&&void 0!==i&&(n.EventSource=i):n.EventSource=EventSource,this.v=n.httpClient||new $(this.u),this.L="Disconnected",this.N=!1,this.Bt=n,this.onreceive=null,this.onclose=null}async start(e){if(e=e||W.Binary,l.isIn(e,W,"transferFormat"),this.u.log(t.Debug,`Starting connection with transfer format '${W[e]}'.`),"Disconnected"!==this.L)return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));if(this.L="Connecting",this.Xt=this.W(e),await this.Xt,"Disconnecting"===this.L){const e="Failed to start the HttpConnection before stop() was called.";return this.u.log(t.Error,e),await this.Y,Promise.reject(new Error(e))}if("Connected"!==this.L){const e="HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";return this.u.log(t.Error,e),Promise.reject(new Error(e))}this.N=!0}send(t){return"Connected"!==this.L?Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")):(this.Jt||(this.Jt=new U(this.transport)),this.Jt.send(t))}async stop(e){return"Disconnected"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnected state.`),Promise.resolve()):"Disconnecting"===this.L?(this.u.log(t.Debug,`Call to HttpConnection.stop(${e}) ignored because the connection is already in the disconnecting state.`),this.Y):(this.L="Disconnecting",this.Y=new Promise((t=>{this.Wt=t})),await this.Z(e),void await this.Y)}async Z(e){this.Vt=e;try{await this.Xt}catch(t){}if(this.transport){try{await this.transport.stop()}catch(e){this.u.log(t.Error,`HttpConnection.transport.stop() threw error '${e}'.`),this.zt()}this.transport=void 0}else this.u.log(t.Debug,"HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.")}async W(e){let n=this.baseUrl;this.$t=this.Bt.accessTokenFactory;try{if(this.Bt.skipNegotiation){if(this.Bt.transport!==N.WebSockets)throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");this.transport=this.Gt(N.WebSockets),await this.Kt(n,e)}else{let t=null,o=0;do{if(t=await this.Qt(n),"Disconnecting"===this.L||"Disconnected"===this.L)throw new Error("The connection was stopped during negotiation.");if(t.error)throw new Error(t.error);if(t.ProtocolVersion)throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");if(t.url&&(n=t.url),t.accessToken){const e=t.accessToken;this.$t=()=>e}o++}while(t.url&&o<100);if(100===o&&t.url)throw new Error("Negotiate redirection limit exceeded.");await this.Yt(n,this.Bt.transport,t,e)}this.transport instanceof A&&(this.features.inherentKeepAlive=!0),"Connecting"===this.L&&(this.u.log(t.Debug,"The HttpConnection connected successfully."),this.L="Connected")}catch(e){return this.u.log(t.Error,"Failed to start the connection: "+e),this.L="Disconnected",this.transport=void 0,this.Wt(),Promise.reject(e)}}async Qt(e){const n={};if(this.$t){const t=await this.$t();t&&(n[H.Authorization]=`Bearer ${t}`)}const[r,i]=b();n[r]=i;const s=this.Zt(e);this.u.log(t.Debug,`Sending negotiation request: ${s}.`);try{const t=await this.v.post(s,{content:"",headers:{...n,...this.Bt.headers},withCredentials:this.Bt.withCredentials});if(200!==t.statusCode)return Promise.reject(new Error(`Unexpected status code returned from negotiate '${t.statusCode}'`));const e=JSON.parse(t.content);return(!e.negotiateVersion||e.negotiateVersion<1)&&(e.connectionToken=e.connectionId),e}catch(e){let n="Failed to complete negotiation with the server: "+e;return e instanceof o&&404===e.statusCode&&(n+=" Either this is not a SignalR endpoint or there is a proxy blocking the connection."),this.u.log(t.Error,n),Promise.reject(new Error(n))}}te(t,e){return e?t+(-1===t.indexOf("?")?"?":"&")+`id=${e}`:t}async Yt(e,n,o,r){let i=this.te(e,o.connectionToken);if(this.ee(n))return this.u.log(t.Debug,"Connection was provided an instance of ITransport, using that directly."),this.transport=n,await this.Kt(i,r),void(this.connectionId=o.connectionId);const s=[],c=o.availableTransports||[];let a=o;for(const o of c){const c=this.se(o,n,r);if(c instanceof Error)s.push(`${o.transport} failed: ${c}`);else if(this.ee(c)){if(this.transport=c,!a){try{a=await this.Qt(e)}catch(t){return Promise.reject(t)}i=this.te(e,a.connectionToken)}try{return await this.Kt(i,r),void(this.connectionId=a.connectionId)}catch(e){if(this.u.log(t.Error,`Failed to start the transport '${o.transport}': ${e}`),a=void 0,s.push(`${o.transport} failed: ${e}`),"Connecting"!==this.L){const e="Failed to select transport before stop() was called.";return this.u.log(t.Debug,e),Promise.reject(new Error(e))}}}}return s.length>0?Promise.reject(new Error(`Unable to connect to the server with any of the available transports. ${s.join(" ")}`)):Promise.reject(new Error("None of the transports supported by the client are supported by the server."))}Gt(t){switch(t){case N.WebSockets:if(!this.Bt.WebSocket)throw new Error("'WebSocket' is not supported in your environment.");return new B(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.WebSocket,this.Bt.headers||{});case N.ServerSentEvents:if(!this.Bt.EventSource)throw new Error("'EventSource' is not supported in your environment.");return new q(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.EventSource,this.Bt.withCredentials,this.Bt.headers||{});case N.LongPolling:return new A(this.v,this.$t,this.u,this.Bt.logMessageContent||!1,this.Bt.withCredentials,this.Bt.headers||{});default:throw new Error(`Unknown transport: ${t}.`)}}Kt(t,e){return this.transport.onreceive=this.onreceive,this.transport.onclose=t=>this.zt(t),this.transport.connect(t,e)}se(e,n,o){const r=N[e.transport];if(null==r)return this.u.log(t.Debug,`Skipping transport '${e.transport}' because it is not supported by this client.`),new Error(`Skipping transport '${e.transport}' because it is not supported by this client.`);if(!function(t,e){return!t||0!=(e&t)}(n,r))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it was disabled by the client.`),new Error(`'${N[r]}' is disabled by the client.`);if(!(e.transferFormats.map((t=>W[t])).indexOf(o)>=0))return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it does not support the requested transfer format '${W[o]}'.`),new Error(`'${N[r]}' does not support ${W[o]}.`);if(r===N.WebSockets&&!this.Bt.WebSocket||r===N.ServerSentEvents&&!this.Bt.EventSource)return this.u.log(t.Debug,`Skipping transport '${N[r]}' because it is not supported in your environment.'`),new Error(`'${N[r]}' is not supported in your environment.`);this.u.log(t.Debug,`Selecting transport '${N[r]}'.`);try{return this.Gt(r)}catch(t){return t}}ee(t){return t&&"object"==typeof t&&"connect"in t}zt(e){if(this.u.log(t.Debug,`HttpConnection.stopConnection(${e}) called while in state ${this.L}.`),this.transport=void 0,e=this.Vt||e,this.Vt=void 0,"Disconnected"!==this.L){if("Connecting"===this.L)throw this.u.log(t.Warning,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is still in the connecting state.`),new Error(`HttpConnection.stopConnection(${e}) was called while the connection is still in the connecting state.`);if("Disconnecting"===this.L&&this.Wt(),e?this.u.log(t.Error,`Connection disconnected with error '${e}'.`):this.u.log(t.Information,"Connection disconnected."),this.Jt&&(this.Jt.stop().catch((e=>{this.u.log(t.Error,`TransportSendQueue.stop() threw error '${e}'.`)})),this.Jt=void 0),this.connectionId=void 0,this.L="Disconnected",this.N){this.N=!1;try{this.onclose&&this.onclose(e)}catch(n){this.u.log(t.Error,`HttpConnection.onclose(${e}) threw error '${n}'.`)}}}else this.u.log(t.Debug,`Call to HttpConnection.stopConnection(${e}) was ignored because the connection is already in the disconnected state.`)}Ft(e){if(0===e.lastIndexOf("https://",0)||0===e.lastIndexOf("http://",0))return e;if(!u.isBrowser||!window.document)throw new Error(`Cannot resolve '${e}'.`);const n=window.document.createElement("a");return n.href=e,this.u.log(t.Information,`Normalizing '${e}' to '${n.href}'.`),n.href}Zt(t){const e=t.indexOf("?");let n=t.substring(0,-1===e?t.length:e);return"/"!==n[n.length-1]&&(n+="/"),n+="negotiate",n+=-1===e?"":t.substring(e),-1===n.indexOf("negotiateVersion")&&(n+=-1===e?"?":"&",n+="negotiateVersion="+this.jt),n}}class U{constructor(t){this.ne=t,this.ie=[],this.re=!0,this.oe=new M,this.he=new M,this.ce=this.ae()}send(t){return this.le(t),this.he||(this.he=new M),this.he.promise}stop(){return this.re=!1,this.oe.resolve(),this.ce}le(t){if(this.ie.length&&typeof this.ie[0]!=typeof t)throw new Error(`Expected data to be of type ${typeof this.ie} but was of type ${typeof t}`);this.ie.push(t),this.oe.resolve()}async ae(){for(;;){if(await this.oe.promise,!this.re){this.he&&this.he.reject("Connection stopped.");break}this.oe=new M;const t=this.he;this.he=void 0;const e="string"==typeof this.ie[0]?this.ie.join(""):U.ue(this.ie);this.ie.length=0;try{await this.ne.send(e),t.resolve()}catch(e){t.reject(e)}}}static ue(t){const e=t.map((t=>t.byteLength)).reduce(((t,e)=>t+e)),n=new Uint8Array(e);let o=0;for(const e of t)n.set(new Uint8Array(e),o),o+=e.byteLength;return n.buffer}}class M{constructor(){this.promise=new Promise(((t,e)=>[this.de,this.fe]=[t,e]))}resolve(){this.de()}reject(t){this.fe(t)}}class _{constructor(){this.name="json",this.version=1,this.transferFormat=W.Text}parseMessages(e,n){if("string"!=typeof e)throw new Error("Invalid input for JSON hub protocol. Expected a string.");if(!e)return[];null===n&&(n=a.instance);const o=I.parse(e),r=[];for(const e of o){const o=JSON.parse(e);if("number"!=typeof o.type)throw new Error("Invalid payload.");switch(o.type){case T.Invocation:this.pe(o);break;case T.StreamItem:this.we(o);break;case T.Completion:this.ge(o);break;case T.Ping:case T.Close:break;default:n.log(t.Information,"Unknown message type '"+o.type+"' ignored.");continue}r.push(o)}return r}writeMessage(t){return I.write(JSON.stringify(t))}pe(t){this.ye(t.target,"Invalid payload for Invocation message."),void 0!==t.invocationId&&this.ye(t.invocationId,"Invalid payload for Invocation message.")}we(t){if(this.ye(t.invocationId,"Invalid payload for StreamItem message."),void 0===t.item)throw new Error("Invalid payload for StreamItem message.")}ge(t){if(t.result&&t.error)throw new Error("Invalid payload for Completion message.");!t.result&&t.error&&this.ye(t.error,"Invalid payload for Completion message."),this.ye(t.invocationId,"Invalid payload for Completion message.")}ye(t,e){if("string"!=typeof t||""===t)throw new Error(e)}}const F={trace:t.Trace,debug:t.Debug,info:t.Information,information:t.Information,warn:t.Warning,warning:t.Warning,error:t.Error,critical:t.Critical,none:t.None};class J{configureLogging(t){if(l.isRequired(t,"logging"),void 0!==t.log)this.logger=t;else if("string"==typeof t){const e=function(t){const e=F[t.toLowerCase()];if(void 0!==e)return e;throw new Error(`Unknown log level: ${t}`)}(t);this.logger=new w(e)}else this.logger=new w(t);return this}withUrl(t,e){return l.isRequired(t,"url"),l.isNotEmpty(t,"url"),this.url=t,this.httpConnectionOptions="object"==typeof e?{...this.httpConnectionOptions,...e}:{...this.httpConnectionOptions,transport:e},this}withHubProtocol(t){return l.isRequired(t,"protocol"),this.protocol=t,this}withAutomaticReconnect(t){if(this.reconnectPolicy)throw new Error("A reconnectPolicy has already been set.");return t?Array.isArray(t)?this.reconnectPolicy=new x(t):this.reconnectPolicy=t:this.reconnectPolicy=new x,this}build(){const t=this.httpConnectionOptions||{};if(void 0===t.logger&&(t.logger=this.logger),!this.url)throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");const e=new O(this.url,t);return L.create(e,this.logger||a.instance,this.protocol||new _,this.reconnectPolicy)}}return Uint8Array.prototype.indexOf||Object.defineProperty(Uint8Array.prototype,"indexOf",{value:Array.prototype.indexOf,writable:!0}),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:function(t,e){return new Uint8Array(Array.prototype.slice.call(this,t,e))},writable:!0}),Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach,writable:!0}),n})()},"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.signalR=e():t.signalR=e(); |
{ | ||
"name": "@microsoft/signalr", | ||
"version": "6.0.0-preview.5.21301.17", | ||
"version": "6.0.0-preview.6.21355.2", | ||
"description": "ASP.NET Core SignalR Client", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
1897777