(function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,b.signalR=a()}})(function(){return function b(c,d,e){function a(h,i){if(!d[h]){if(!c[h]){var j="function"==typeof require&&require;if(!i&&j)return j(h,!0);if(g)return g(h,!0);var k=new Error("Cannot find module '"+h+"'");throw k.code="MODULE_NOT_FOUND",k}var f=d[h]={exports:{}};c[h][0].call(f.exports,function(b){var d=c[h][1][b];return a(d?d:b)},f,f.exports,b,c,d,e)}return d[h].exports}for(var g="function"==typeof require&&require,f=0;f>=8;return c.set(a,8),c.buffer},a.parse=function(a){let b=[],c=new Uint8Array(a);for(let d=0;da;a++)e=e<<8|c[d+a];if(c.byteLength>=d+8+e)b.push(c.slice?c.slice(d+8,d+8+e):c.subarray(d+8,d+8+e));else throw new Error("Incomplete message");d=d+8+e}return b}})(e=c.BinaryMessageFormat||(c.BinaryMessageFormat={}))},{}],3:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});const d=a("./HttpError");c.HttpClient=class{get(a,b){return this.xhr("GET",a,b)}options(a,b){return this.xhr("OPTIONS",a,b)}post(a,b,c){return this.xhr("POST",a,c,b)}xhr(a,b,c,e){return new Promise((f,g)=>{let h=new XMLHttpRequest;h.open(a,b,!0),h.setRequestHeader("X-Requested-With","XMLHttpRequest"),c&&c.forEach((a,b)=>h.setRequestHeader(b,a)),h.send(e),h.onload=()=>{200<=h.status&&300>h.status?f(h.response||h.responseText):g(new d.HttpError(h.statusText,h.status))},h.onerror=()=>{g(new d.HttpError(h.statusText,h.status))}})}}},{"./HttpError":5}],4:[function(a,b,c){"use strict";var d=this&&this.__awaiter||function(a,b,c,d){return new(c||(c=Promise))(function(e,f){function g(a){try{i(d.next(a))}catch(a){f(a)}}function h(a){try{i(d["throw"](a))}catch(a){f(a)}}function i(a){a.done?e(a.value):new c(function(b){b(a.value)}).then(g,h)}i((d=d.apply(a,b||[])).next())})};Object.defineProperty(c,"__esModule",{value:!0});const e=a("./Transports"),f=a("./HttpClient"),g=a("./ILogger"),h=a("./Loggers");c.HttpConnection=class{constructor(a,b={}){this.features={},this.logger=h.LoggerFactory.createLogger(b.logging),this.url=this.resolveUrl(a),b=b||{},this.httpClient=b.httpClient||new f.HttpClient,this.connectionState=0,this.options=b}start(){return d(this,void 0,void 0,function*(){return 0==this.connectionState?(this.connectionState=1,this.startPromise=this.startInternal(),this.startPromise):Promise.reject(new Error("Cannot start a connection that is not in the 'Initial' state."))})}startInternal(){return d(this,void 0,void 0,function*(){try{let a=yield this.httpClient.options(this.url),b=JSON.parse(a);if(this.connectionId=b.connectionId,3==this.connectionState)return;this.url+=(-1==this.url.indexOf("?")?"?":"&")+`id=${this.connectionId}`,this.transport=this.createTransport(this.options.transport,b.availableTransports),this.transport.onDataReceived=this.onDataReceived,this.transport.onClosed=(a)=>this.stopConnection(!0,a);let c=2===this.features.transferMode?2:1;this.features.transferMode=yield this.transport.connect(this.url,c),this.changeState(1,2)}catch(a){throw this.logger.log(g.LogLevel.Error,"Failed to start the connection. "+a),this.connectionState=3,this.transport=null,a}})}createTransport(a,b){if(!a&&0{this.onDataReceived(a)},this.connection.onClosed=(a)=>{this.onConnectionClosed(a)},this.callbacks=new Map,this.methods=new Map,this.id=0}onDataReceived(a){let b=this.protocol.parseMessages(a);for(var c,d=0;d{a(b)}),this.callbacks.clear(),this.connectionClosedCallback&&this.connectionClosedCallback(a)}start(){return d(this,void 0,void 0,function*(){let a=2===this.protocol.type?2:1;this.connection.features.transferMode=a,yield this.connection.start();var b=this.connection.features.transferMode;yield this.connection.send(h.TextMessageFormat.write(JSON.stringify({protocol:this.protocol.name}))),this.logger.log(j.LogLevel.Information,`Using HubProtocol '${this.protocol.name}'.`),2==a&&1===b&&(this.protocol=new i.Base64EncodedHubProtocol(this.protocol))})}stop(){return this.connection.stop()}stream(a,...b){let c=this.createInvocation(a,b,!1),d=new f.Subject;this.callbacks.set(c.invocationId,(a)=>{if(3===a.type){let b=a;b.error?d.error(new Error(b.error)):b.result?d.error(new Error("Server provided a result in a completion response to a streamed invocation.")):d.complete()}else d.next(a.item)});let e=this.protocol.writeMessage(c);return this.connection.send(e).catch((a)=>{d.error(a),this.callbacks.delete(c.invocationId)}),d}send(a,...b){let c=this.createInvocation(a,b,!0),d=this.protocol.writeMessage(c);return this.connection.send(d)}invoke(a,...b){let c=this.createInvocation(a,b,!1),d=new Promise((a,b)=>{this.callbacks.set(c.invocationId,(c)=>{if(3===c.type){let d=c;d.error?b(new Error(d.error)):a(d.result)}else b(new Error("Streaming methods must be invoked using HubConnection.stream"))});let d=this.protocol.writeMessage(c);this.connection.send(d).catch((a)=>{b(a),this.callbacks.delete(c.invocationId)})});return d}on(a,b){this.methods.set(a.toLowerCase(),b)}set onClosed(a){this.connectionClosedCallback=a}createInvocation(a,b,c){let d=this.id;return this.id++,{type:1,invocationId:d.toString(),target:a,arguments:b,nonblocking:c}}}c.HubConnection=q},{"./Base64EncodedHubProtocol":1,"./Formatters":2,"./HttpConnection":4,"./ILogger":7,"./JsonHubProtocol":8,"./Loggers":9,"./Observable":10,"./Transports":11}],7:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});var d;(function(a){a[a.Trace=0]="Trace",a[a.Information=1]="Information",a[a.Warning=2]="Warning",a[a.Error=3]="Error",a[a.None=4]="None"})(d=c.LogLevel||(c.LogLevel={}))},{}],8:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});const d=a("./Formatters");c.JsonHubProtocol=class{constructor(){this.name="json",this.type=1}parseMessages(a){if(!a)return[];let b=d.TextMessageFormat.parse(a),c=[];for(var e=0;e=this.minimumLogLevel&&console.log(`${d.LogLevel[a]}: ${b}`)}}c.ConsoleLogger=f;var g;(function(a){a.createLogger=function(a){return void 0===a?new f(d.LogLevel.Information):null===a?new e:a.log?a:new f(a)}})(g=c.LoggerFactory||(c.LoggerFactory={}))},{"./ILogger":7}],10:[function(a,b,c){"use strict";Object.defineProperty(c,"__esModule",{value:!0});c.Subject=class{constructor(){this.observers=[]}next(a){for(let b of this.observers)b.next(a)}error(a){for(let b of this.observers)b.error(a)}complete(){for(let a of this.observers)a.complete()}subscribe(a){this.observers.push(a)}}},{}],11:[function(a,b,c){"use strict";function d(a,b,c){return e(this,void 0,void 0,function*(){yield a.post(b,c,i)})}var e=this&&this.__awaiter||function(a,b,c,d){return new(c||(c=Promise))(function(e,f){function g(a){try{i(d.next(a))}catch(a){f(a)}}function h(a){try{i(d["throw"](a))}catch(a){f(a)}}function i(a){a.done?e(a.value):new c(function(b){b(a.value)}).then(g,h)}i((d=d.apply(a,b||[])).next())})};Object.defineProperty(c,"__esModule",{value:!0});const f=a("./HttpError"),g=a("./ILogger");var h;(function(a){a[a.WebSockets=0]="WebSockets",a[a.ServerSentEvents=1]="ServerSentEvents",a[a.LongPolling=2]="LongPolling"})(h=c.TransportType||(c.TransportType={}));c.WebSocketTransport=class{constructor(a){this.logger=a}connect(a,b){return new Promise((c,d)=>{a=a.replace(/^http/,"ws");let e=new WebSocket(a);2==b&&(e.binaryType="arraybuffer"),e.onopen=()=>{this.logger.log(g.LogLevel.Information,`WebSocket connected to ${a}`),this.webSocket=e,c(b)},e.onerror=()=>{d()},e.onmessage=(a)=>{this.logger.log(g.LogLevel.Trace,`(WebSockets transport) data received: ${a.data}`),this.onDataReceived&&this.onDataReceived(a.data)},e.onclose=(a)=>{this.onClosed&&this.webSocket&&(!1===a.wasClean||1e3!==a.code?this.onClosed(new Error(`Websocket closed with status code: ${a.code} (${a.reason})`)):this.onClosed())}})}send(a){return this.webSocket&&this.webSocket.readyState===WebSocket.OPEN?(this.webSocket.send(a),Promise.resolve()):Promise.reject("WebSocket is not in the OPEN state")}stop(){this.webSocket&&(this.webSocket.close(),this.webSocket=null)}};c.ServerSentEventsTransport=class{constructor(a,b){this.httpClient=a,this.logger=b}connect(a){return"undefined"==typeof EventSource&&Promise.reject("EventSource not supported by the browser."),this.url=a,new Promise((a,b)=>{let c=new EventSource(this.url);try{c.onmessage=(a)=>{if(this.onDataReceived)try{this.logger.log(g.LogLevel.Trace,`(SSE transport) data received: ${a.data}`),this.onDataReceived(a.data)}catch(a){return void(this.onClosed&&this.onClosed(a))}},c.onerror=(a)=>{b(),this.eventSource&&this.onClosed&&this.onClosed(new Error(a.message||"Error occurred"))},c.onopen=()=>{this.logger.log(g.LogLevel.Information,`SSE connected to ${this.url}`),this.eventSource=c,a(1)}}catch(a){return Promise.reject(a)}})}send(a){return e(this,void 0,void 0,function*(){return d(this.httpClient,this.url,a)})}stop(){this.eventSource&&(this.eventSource.close(),this.eventSource=null)}};c.LongPollingTransport=class{constructor(a,b){this.httpClient=a,this.logger=b}connect(a,b){if(this.url=a,this.shouldPoll=!0,2===b&&"string"!=typeof new XMLHttpRequest().responseType)throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");return this.poll(this.url,b),Promise.resolve(b)}poll(a,b){if(!this.shouldPoll)return;let c=new XMLHttpRequest;c.onload=()=>{if(200==c.status){if(this.onDataReceived)try{let a=1===b?c.responseText:c.response;a?(this.logger.log(g.LogLevel.Trace,`(LongPolling transport) data received: ${a}`),this.onDataReceived(a)):this.logger.log(g.LogLevel.Information,"(LongPolling transport) timed out")}catch(a){return void(this.onClosed&&this.onClosed(a))}this.poll(a,b)}else 204==this.pollXhr.status?this.onClosed&&this.onClosed():this.onClosed&&this.onClosed(new f.HttpError(c.statusText,c.status))},c.onerror=()=>{this.onClosed&&this.onClosed(new Error("Sending HTTP request failed."))},c.ontimeout=()=>{this.poll(a,b)},this.pollXhr=c,this.pollXhr.open("GET",`${a}&_=${Date.now()}`,!0),2===b&&(this.pollXhr.responseType="arraybuffer"),this.pollXhr.timeout=1.2e5,this.pollXhr.send()}send(a){return e(this,void 0,void 0,function*(){return d(this.httpClient,this.url,a)})}stop(){this.shouldPoll=!1,this.pollXhr&&(this.pollXhr.abort(),this.pollXhr=null)}};const i=new Map},{"./HttpError":5,"./ILogger":7}]},{},[6])(6)});