vendor: 8,112 bytes, lines 1-151
1(function webpackUniversalModuleDefinition(root, factory) { 2 if(typeof exports === 'object' && typeof module === 'object') 3 module.exports = factory(); 4 else if(typeof define === 'function' && define.amd) 5 define([], factory); 6 else if(typeof exports === 'object') 7 exports["signalR"] = factory(); 8 else 9 root["signalR"] = factory(); 10})(window, function() { 11return /******/ (function(modules) { // webpackBootstrap 12/******/ // The module cache 13/******/ var installedModules = {}; 14/******/ 15/******/ // The require function 16/******/ function __webpack_require__(moduleId) { 17/******/ 18/******/ // Check if module is in cache 19/******/ if(installedModules[moduleId]) { 20/******/ return installedModules[moduleId].exports; 21/******/ } 22/******/ // Create a new module (and put it into the cache) 23/******/ var module = installedModules[moduleId] = { 24/******/ i: moduleId, 25/******/ l: false, 26/******/ exports: {} 27/******/ }; 28/******/ 29/******/ // Execute the module function 30/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31/******/ 32/******/ // Flag the module as loaded 33/******/ module.l = true; 34/******/ 35/******/ // Return the exports of the module 36/******/ return module.exports; 37/******/ } 38/******/ 39/******/ 40/******/ // expose the modules object (__webpack_modules__) 41/******/ __webpack_require__.m = modules; 42/******/ 43/******/ // expose the module cache 44/******/ __webpack_require__.c = installedModules; 45/******/ 46/******/ // define getter function for harmony exports 47/******/ __webpack_require__.d = function(exports, name, getter) { 48/******/ if(!__webpack_require__.o(exports, name)) { 49/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); 50/******/ } 51/******/ }; 52/******/ 53/******/ // define __esModule on exports 54/******/ __webpack_require__.r = function(exports) { 55/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 56/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 57/******/ } 58/******/ Object.defineProperty(exports, '__esModule', { value: true }); 59/******/ }; 60/******/ 61/******/ // create a fake namespace object 62/******/ // mode & 1: value is a module id, require it 63/******/ // mode & 2: merge all properties of value into the ns 64/******/ // mode & 4: return value when already ns object 65/******/ // mode & 8|1: behave like require 66/******/ __webpack_require__.t = function(value, mode) { 67/******/ if(mode & 1) value = __webpack_require__(value); 68/******/ if(mode & 8) return value; 69/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; 70/******/ var ns = Object.create(null); 71/******/ __webpack_require__.r(ns); 72/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); 73/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); 74/******/ return ns; 75/******/ }; 76/******/ 77/******/ // getDefaultExport function for compatibility with non-harmony modules 78/******/ __webpack_require__.n = function(module) { 79/******/ var getter = module && module.__esModule ? 80/******/ function getDefault() { return module['default']; } : 81/******/ function getModuleExports() { return module; }; 82/******/ __webpack_require__.d(getter, 'a', getter); 83/******/ return getter; 84/******/ }; 85/******/ 86/******/ // Object.prototype.hasOwnProperty.call 87/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 88/******/ 89/******/ // __webpack_public_path__ 90/******/ __webpack_require__.p = ""; 91/******/ 92/******/ 93/******/ // Load entry module and return exports 94/******/ return __webpack_require__(__webpack_require__.s = 0); 95/******/ }) 96/************************************************************************/ 97/******/ ([ 98/* 0 */ 99/***/ (function(module, __webpack_exports__, __webpack_require__) { 100 101"use strict"; 102__webpack_require__.r(__webpack_exports__); 103/* harmony import */ var es6_promise_dist_es6_promise_auto_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); 104/* harmony import */ var es6_promise_dist_es6_promise_auto_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(es6_promise_dist_es6_promise_auto_js__WEBPACK_IMPORTED_MODULE_0__); 105/* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3); 106/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "VERSION", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["VERSION"]; }); 107 108/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AbortError", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["AbortError"]; }); 109 110/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpError", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HttpError"]; }); 111 112/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TimeoutError", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["TimeoutError"]; }); 113 114/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpClient", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HttpClient"]; }); 115 116/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpResponse", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HttpResponse"]; }); 117 118/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DefaultHttpClient", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["DefaultHttpClient"]; }); 119 120/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnection", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HubConnection"]; }); 121 122/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnectionState", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HubConnectionState"]; }); 123 124/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnectionBuilder", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HubConnectionBuilder"]; }); 125 126/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MessageType", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["MessageType"]; }); 127 128/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LogLevel", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["LogLevel"]; }); 129 130/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpTransportType", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["HttpTransportType"]; }); 131 132/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransferFormat", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["TransferFormat"]; }); 133 134/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "NullLogger", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["NullLogger"]; }); 135 136/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "JsonHubProtocol", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["JsonHubProtocol"]; }); 137 138/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Subject", function() { return _index__WEBPACK_IMPORTED_MODULE_1__["Subject"]; }); 139 140// Copyright (c) .NET Foundation. All rights reserved. 141// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 142// This is where we add any polyfills we'll need for the browser. It is the entry module for browser-specific builds. 143 144// Copy from Array.prototype into Uint8Array to polyfill on IE. It's OK because the implementations of indexOf and slice use properties 145// that exist on Uint8Array with the same name, and JavaScript is magic. 146// We make them 'writable' because the Buffer polyfill messes with it as well. 147if (!Uint8Array.prototype.indexOf) { 148 Object.defineProperty(Uint8Array.prototype, "indexOf", { 149 value: Array.prototype.indexOf, 150 writable: true, 151 });
152} 153if (!Uint8Array.prototype.slice) { 154 Object.defineProperty(Uint8Array.prototype, "slice", { 155 // wrap the slice in Uint8Array so it looks like a Uint8Array.slice call 156 // tslint:disable-next-line:object-literal-shorthand 157 value: function (start, end) { return new Uint8Array(Array.prototype.slice.call(this, start, end)); }
vendor: 13,379 bytes, lines 157-719
157, 158 writable: true, 159 }); 160} 161if (!Uint8Array.prototype.forEach) { 162 Object.defineProperty(Uint8Array.prototype, "forEach", { 163 value: Array.prototype.forEach, 164 writable: true, 165 }); 166} 167 168 169 170/***/ }), 171/* 1 */ 172/***/ (function(module, exports, __webpack_require__) { 173 174/* WEBPACK VAR INJECTION */(function(global) {var require;/*! 175 * @overview es6-promise - a tiny implementation of Promises/A+. 176 * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) 177 * @license Licensed under MIT license 178 * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE 179 * @version v4.2.2+97478eb6 180 */ 181 182(function (global, factory) { 183 true ? module.exports = factory() : 184 undefined; 185}(this, (function () { 'use strict'; 186 187function objectOrFunction(x) { 188 var type = typeof x; 189 return x !== null && (type === 'object' || type === 'function'); 190} 191 192function isFunction(x) { 193 return typeof x === 'function'; 194} 195 196 197 198var _isArray = void 0; 199if (Array.isArray) { 200 _isArray = Array.isArray; 201} else { 202 _isArray = function (x) { 203 return Object.prototype.toString.call(x) === '[object Array]'; 204 }; 205} 206 207var isArray = _isArray; 208 209var len = 0; 210var vertxNext = void 0; 211var customSchedulerFn = void 0; 212 213var asap = function asap(callback, arg) { 214 queue[len] = callback; 215 queue[len + 1] = arg; 216 len += 2; 217 if (len === 2) { 218 // If len is 2, that means that we need to schedule an async flush. 219 // If additional callbacks are queued before the queue is flushed, they 220 // will be processed by this flush that we are scheduling. 221 if (customSchedulerFn) { 222 customSchedulerFn(flush); 223 } else { 224 scheduleFlush(); 225 } 226 } 227}; 228 229function setScheduler(scheduleFn) { 230 customSchedulerFn = scheduleFn; 231} 232 233function setAsap(asapFn) { 234 asap = asapFn; 235} 236 237var browserWindow = typeof window !== 'undefined' ? window : undefined; 238var browserGlobal = browserWindow || {}; 239var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; 240var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; 241 242// test for web worker but not in IE10 243var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; 244 245// node 246function useNextTick() { 247 // node version 0.10.x displays a deprecation warning when nextTick is used recursively 248 // see https://github.com/cujojs/when/issues/410 for details 249 return function () { 250 return process.nextTick(flush); 251 }; 252} 253 254// vertx 255function useVertxTimer() { 256 if (typeof vertxNext !== 'undefined') { 257 return function () { 258 vertxNext(flush); 259 }; 260 } 261 262 return useSetTimeout(); 263} 264 265function useMutationObserver() { 266 var iterations = 0; 267 var observer = new BrowserMutationObserver(flush); 268 var node = document.createTextNode(''); 269 observer.observe(node, { characterData: true }); 270 271 return function () { 272 node.data = iterations = ++iterations % 2; 273 }; 274} 275 276// web worker 277function useMessageChannel() { 278 var channel = new MessageChannel(); 279 channel.port1.onmessage = flush; 280 return function () { 281 return channel.port2.postMessage(0); 282 }; 283} 284 285function useSetTimeout() { 286 // Store setTimeout reference so es6-promise will be unaffected by 287 // other code modifying setTimeout (like sinon.useFakeTimers()) 288 var globalSetTimeout = setTimeout; 289 return function () { 290 return globalSetTimeout(flush, 1); 291 }; 292} 293 294var queue = new Array(1000); 295function flush() { 296 for (var i = 0; i < len; i += 2) { 297 var callback = queue[i]; 298 var arg = queue[i + 1]; 299 300 callback(arg); 301 302 queue[i] = undefined; 303 queue[i + 1] = undefined; 304 } 305 306 len = 0; 307} 308 309function attemptVertx() { 310 try { 311 var r = require; 312 var vertx = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'vertx'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())); 313 vertxNext = vertx.runOnLoop || vertx.runOnContext; 314 return useVertxTimer(); 315 } catch (e) { 316 return useSetTimeout(); 317 } 318} 319 320var scheduleFlush = void 0; 321// Decide what async method to use to triggering processing of queued callbacks: 322if (isNode) { 323 scheduleFlush = useNextTick(); 324} else if (BrowserMutationObserver) { 325 scheduleFlush = useMutationObserver(); 326} else if (isWorker) { 327 scheduleFlush = useMessageChannel(); 328} else if (browserWindow === undefined && "function" === 'function') { 329 scheduleFlush = attemptVertx(); 330} else { 331 scheduleFlush = useSetTimeout(); 332} 333 334function then(onFulfillment, onRejection) { 335 var parent = this; 336 337 var child = new this.constructor(noop); 338 339 if (child[PROMISE_ID] === undefined) { 340 makePromise(child); 341 } 342 343 var _state = parent._state; 344 345 346 if (_state) { 347 var callback = arguments[_state - 1]; 348 asap(function () { 349 return invokeCallback(_state, child, callback, parent._result); 350 }); 351 } else { 352 subscribe(parent, child, onFulfillment, onRejection); 353 } 354 355 return child; 356} 357 358/** 359 `Promise.resolve` returns a promise that will become resolved with the 360 passed `value`. It is shorthand for the following: 361 362 ```javascript 363 let promise = new Promise(function(resolve, reject){ 364 resolve(1); 365 }); 366 367 promise.then(function(value){ 368 // value === 1 369 }); 370 ``` 371 372 Instead of writing the above, your code now simply becomes the following: 373 374 ```javascript 375 let promise = Promise.resolve(1); 376 377 promise.then(function(value){ 378 // value === 1 379 }); 380 ``` 381 382 @method resolve 383 @static 384 @param {Any} value value that the returned promise will be resolved with 385 Useful for tooling. 386 @return {Promise} a promise that will become fulfilled with the given 387 `value` 388*/ 389function resolve$1(object) { 390 /*jshint validthis:true */ 391 var Constructor = this; 392 393 if (object && typeof object === 'object' && object.constructor === Constructor) { 394 return object; 395 } 396 397 var promise = new Constructor(noop); 398 resolve(promise, object); 399 return promise; 400} 401 402var PROMISE_ID = Math.random().toString(36).substring(16); 403 404function noop() {} 405 406var PENDING = void 0; 407var FULFILLED = 1; 408var REJECTED = 2; 409 410var GET_THEN_ERROR = new ErrorObject(); 411 412function selfFulfillment() { 413 return new TypeError("You cannot resolve a promise with itself"); 414} 415 416function cannotReturnOwn() { 417 return new TypeError('A promises callback cannot return that same promise.'); 418} 419 420function getThen(promise) { 421 try { 422 return promise.then; 423 } catch (error) { 424 GET_THEN_ERROR.error = error; 425 return GET_THEN_ERROR; 426 } 427} 428 429function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { 430 try { 431 then$$1.call(value, fulfillmentHandler, rejectionHandler); 432 } catch (e) { 433 return e; 434 } 435} 436 437function handleForeignThenable(promise, thenable, then$$1) { 438 asap(function (promise) { 439 var sealed = false; 440 var error = tryThen(then$$1, thenable, function (value) { 441 if (sealed) { 442 return; 443 } 444 sealed = true; 445 if (thenable !== value) { 446 resolve(promise, value); 447 } else { 448 fulfill(promise, value); 449 } 450 }, function (reason) { 451 if (sealed) { 452 return; 453 } 454 sealed = true; 455 456 reject(promise, reason); 457 }, 'Settle: ' + (promise._label || ' unknown promise')); 458 459 if (!sealed && error) { 460 sealed = true; 461 reject(promise, error); 462 } 463 }, promise); 464} 465 466function handleOwnThenable(promise, thenable) { 467 if (thenable._state === FULFILLED) { 468 fulfill(promise, thenable._result); 469 } else if (thenable._state === REJECTED) { 470 reject(promise, thenable._result); 471 } else { 472 subscribe(thenable, undefined, function (value) { 473 return resolve(promise, value); 474 }, function (reason) { 475 return reject(promise, reason); 476 }); 477 } 478} 479 480function handleMaybeThenable(promise, maybeThenable, then$$1) { 481 if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) { 482 handleOwnThenable(promise, maybeThenable); 483 } else { 484 if (then$$1 === GET_THEN_ERROR) { 485 reject(promise, GET_THEN_ERROR.error); 486 GET_THEN_ERROR.error = null; 487 } else if (then$$1 === undefined) { 488 fulfill(promise, maybeThenable); 489 } else if (isFunction(then$$1)) { 490 handleForeignThenable(promise, maybeThenable, then$$1); 491 } else { 492 fulfill(promise, maybeThenable); 493 } 494 } 495} 496 497function resolve(promise, value) { 498 if (promise === value) { 499 reject(promise, selfFulfillment()); 500 } else if (objectOrFunction(value)) { 501 handleMaybeThenable(promise, value, getThen(value)); 502 } else { 503 fulfill(promise, value); 504 } 505} 506 507function publishRejection(promise) { 508 if (promise._onerror) { 509 promise._onerror(promise._result); 510 } 511 512 publish(promise); 513} 514 515function fulfill(promise, value) { 516 if (promise._state !== PENDING) { 517 return; 518 } 519 520 promise._result = value; 521 promise._state = FULFILLED; 522 523 if (promise._subscribers.length !== 0) { 524 asap(publish, promise); 525 } 526} 527 528function reject(promise, reason) { 529 if (promise._state !== PENDING) { 530 return; 531 } 532 promise._state = REJECTED; 533 promise._result = reason; 534 535 asap(publishRejection, promise); 536} 537 538function subscribe(parent, child, onFulfillment, onRejection) { 539 var _subscribers = parent._subscribers; 540 var length = _subscribers.length; 541 542 543 parent._onerror = null; 544 545 _subscribers[length] = child; 546 _subscribers[length + FULFILLED] = onFulfillment; 547 _subscribers[length + REJECTED] = onRejection; 548 549 if (length === 0 && parent._state) { 550 asap(publish, parent); 551 } 552} 553 554function publish(promise) { 555 var subscribers = promise._subscribers; 556 var settled = promise._state; 557 558 if (subscribers.length === 0) { 559 return; 560 } 561 562 var child = void 0, 563 callback = void 0, 564 detail = promise._result; 565 566 for (var i = 0; i < subscribers.length; i += 3) { 567 child = subscribers[i]; 568 callback = subscribers[i + settled]; 569 570 if (child) { 571 invokeCallback(settled, child, callback, detail); 572 } else { 573 callback(detail); 574 } 575 } 576 577 promise._subscribers.length = 0; 578} 579 580function ErrorObject() { 581 this.error = null; 582} 583 584var TRY_CATCH_ERROR = new ErrorObject(); 585 586function tryCatch(callback, detail) { 587 try { 588 return callback(detail); 589 } catch (e) { 590 TRY_CATCH_ERROR.error = e; 591 return TRY_CATCH_ERROR; 592 } 593} 594 595function invokeCallback(settled, promise, callback, detail) { 596 var hasCallback = isFunction(callback), 597 value = void 0, 598 error = void 0, 599 succeeded = void 0, 600 failed = void 0; 601 602 if (hasCallback) { 603 value = tryCatch(callback, detail); 604 605 if (value === TRY_CATCH_ERROR) { 606 failed = true; 607 error = value.error; 608 value.error = null; 609 } else { 610 succeeded = true; 611 } 612 613 if (promise === value) { 614 reject(promise, cannotReturnOwn()); 615 return; 616 } 617 } else { 618 value = detail; 619 succeeded = true; 620 } 621 622 if (promise._state !== PENDING) { 623 // noop 624 } else if (hasCallback && succeeded) { 625 resolve(promise, value); 626 } else if (failed) { 627 reject(promise, error); 628 } else if (settled === FULFILLED) { 629 fulfill(promise, value); 630 } else if (settled === REJECTED) { 631 reject(promise, value); 632 } 633} 634 635function initializePromise(promise, resolver) { 636 try { 637 resolver(function resolvePromise(value) { 638 resolve(promise, value); 639 }, function rejectPromise(reason) { 640 reject(promise, reason); 641 }); 642 } catch (e) { 643 reject(promise, e); 644 } 645} 646 647var id = 0; 648function nextId() { 649 return id++; 650} 651 652function makePromise(promise) { 653 promise[PROMISE_ID] = id++; 654 promise._state = undefined; 655 promise._result = undefined; 656 promise._subscribers = []; 657} 658 659function validationError() { 660 return new Error('Array Methods must be provided an Array'); 661} 662 663function validationError() { 664 return new Error('Array Methods must be provided an Array'); 665} 666 667var Enumerator = function () { 668 function Enumerator(Constructor, input) { 669 this._instanceConstructor = Constructor; 670 this.promise = new Constructor(noop); 671 672 if (!this.promise[PROMISE_ID]) { 673 makePromise(this.promise); 674 } 675 676 if (isArray(input)) { 677 this.length = input.length; 678 this._remaining = input.length; 679 680 this._result = new Array(this.length); 681 682 if (this.length === 0) { 683 fulfill(this.promise, this._result); 684 } else { 685 this.length = this.length || 0; 686 this._enumerate(input); 687 if (this._remaining === 0) { 688 fulfill(this.promise, this._result); 689 } 690 } 691 } else { 692 reject(this.promise, validationError()); 693 } 694 } 695 696 Enumerator.prototype._enumerate = function _enumerate(input) { 697 for (var i = 0; this._state === PENDING && i < input.length; i++) { 698 this._eachEntry(input[i], i); 699 } 700 }; 701 702 Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { 703 var c = this._instanceConstructor; 704 var resolve$$1 = c.resolve; 705 706 707 if (resolve$$1 === resolve$1) { 708 var _then = getThen(entry); 709 710 if (_then === then && entry._state !== PENDING) { 711 this._settledAt(entry._state, i, entry._result); 712 } else if (typeof _then !== 'function') { 713 this._remaining--; 714 this._result[i] = entry; 715 } else if (c === Promise$2) { 716 var promise = new c(noop); 717 handleMaybeThenable(promise, entry, _then); 718 this._willSettleAt(promise, i); 719 } else {
vendor: 5,984 bytes, lines 720-942
720 this._willSettleAt(new c(function (resolve$$1) { 721 return resolve$$1(entry); 722 }), i); 723 } 724 } else { 725 this._willSettleAt(resolve$$1(entry), i); 726 } 727 }; 728 729 Enumerator.prototype._settledAt = function _settledAt(state, i, value) { 730 var promise = this.promise; 731 732 733 if (promise._state === PENDING) { 734 this._remaining--; 735 736 if (state === REJECTED) { 737 reject(promise, value); 738 } else { 739 this._result[i] = value; 740 } 741 } 742 743 if (this._remaining === 0) { 744 fulfill(promise, this._result); 745 } 746 }; 747 748 Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { 749 var enumerator = this; 750 751 subscribe(promise, undefined, function (value) { 752 return enumerator._settledAt(FULFILLED, i, value); 753 }, function (reason) { 754 return enumerator._settledAt(REJECTED, i, reason); 755 }); 756 }; 757 758 return Enumerator; 759}(); 760 761/** 762 `Promise.all` accepts an array of promises, and returns a new promise which 763 is fulfilled with an array of fulfillment values for the passed promises, or 764 rejected with the reason of the first passed promise to be rejected. It casts all 765 elements of the passed iterable to promises as it runs this algorithm. 766 767 Example: 768 769 ```javascript 770 let promise1 = resolve(1); 771 let promise2 = resolve(2); 772 let promise3 = resolve(3); 773 let promises = [ promise1, promise2, promise3 ]; 774 775 Promise.all(promises).then(function(array){ 776 // The array here would be [ 1, 2, 3 ]; 777 }); 778 ``` 779 780 If any of the `promises` given to `all` are rejected, the first promise 781 that is rejected will be given as an argument to the returned promises's 782 rejection handler. For example: 783 784 Example: 785 786 ```javascript 787 let promise1 = resolve(1); 788 let promise2 = reject(new Error("2")); 789 let promise3 = reject(new Error("3")); 790 let promises = [ promise1, promise2, promise3 ]; 791 792 Promise.all(promises).then(function(array){ 793 // Code here never runs because there are rejected promises! 794 }, function(error) { 795 // error.message === "2" 796 }); 797 ``` 798 799 @method all 800 @static 801 @param {Array} entries array of promises 802 @param {String} label optional string for labeling the promise. 803 Useful for tooling. 804 @return {Promise} promise that is fulfilled when all `promises` have been 805 fulfilled, or rejected if any of them become rejected. 806 @static 807*/ 808function all(entries) { 809 return new Enumerator(this, entries).promise; 810} 811 812/** 813 `Promise.race` returns a new promise which is settled in the same way as the 814 first passed promise to settle. 815 816 Example: 817 818 ```javascript 819 let promise1 = new Promise(function(resolve, reject){ 820 setTimeout(function(){ 821 resolve('promise 1'); 822 }, 200); 823 }); 824 825 let promise2 = new Promise(function(resolve, reject){ 826 setTimeout(function(){ 827 resolve('promise 2'); 828 }, 100); 829 }); 830 831 Promise.race([promise1, promise2]).then(function(result){ 832 // result === 'promise 2' because it was resolved before promise1 833 // was resolved. 834 }); 835 ``` 836 837 `Promise.race` is deterministic in that only the state of the first 838 settled promise matters. For example, even if other promises given to the 839 `promises` array argument are resolved, but the first settled promise has 840 become rejected before the other promises became fulfilled, the returned 841 promise will become rejected: 842 843 ```javascript 844 let promise1 = new Promise(function(resolve, reject){ 845 setTimeout(function(){ 846 resolve('promise 1'); 847 }, 200); 848 }); 849 850 let promise2 = new Promise(function(resolve, reject){ 851 setTimeout(function(){ 852 reject(new Error('promise 2')); 853 }, 100); 854 }); 855 856 Promise.race([promise1, promise2]).then(function(result){ 857 // Code here never runs 858 }, function(reason){ 859 // reason.message === 'promise 2' because promise 2 became rejected before 860 // promise 1 became fulfilled 861 }); 862 ``` 863 864 An example real-world use case is implementing timeouts: 865 866 ```javascript 867 Promise.race([ajax('foo.json'), timeout(5000)]) 868 ``` 869 870 @method race 871 @static 872 @param {Array} promises array of promises to observe 873 Useful for tooling. 874 @return {Promise} a promise which settles in the same way as the first passed 875 promise to settle. 876*/ 877function race(entries) { 878 /*jshint validthis:true */ 879 var Constructor = this; 880 881 if (!isArray(entries)) { 882 return new Constructor(function (_, reject) { 883 return reject(new TypeError('You must pass an array to race.')); 884 }); 885 } else { 886 return new Constructor(function (resolve, reject) { 887 var length = entries.length; 888 for (var i = 0; i < length; i++) { 889 Constructor.resolve(entries[i]).then(resolve, reject); 890 } 891 }); 892 } 893} 894 895/** 896 `Promise.reject` returns a promise rejected with the passed `reason`. 897 It is shorthand for the following: 898 899 ```javascript 900 let promise = new Promise(function(resolve, reject){ 901 reject(new Error('WHOOPS')); 902 }); 903 904 promise.then(function(value){ 905 // Code here doesn't run because the promise is rejected! 906 }, function(reason){ 907 // reason.message === 'WHOOPS' 908 }); 909 ``` 910 911 Instead of writing the above, your code now simply becomes the following: 912 913 ```javascript 914 let promise = Promise.reject(new Error('WHOOPS')); 915 916 promise.then(function(value){ 917 // Code here doesn't run because the promise is rejected! 918 }, function(reason){ 919 // reason.message === 'WHOOPS' 920 }); 921 ``` 922 923 @method reject 924 @static 925 @param {Any} reason value that the returned promise will be rejected with. 926 Useful for tooling. 927 @return {Promise} a promise rejected with the given `reason`. 928*/ 929function reject$1(reason) { 930 /*jshint validthis:true */ 931 var Constructor = this; 932 var promise = new Constructor(noop); 933 reject(promise, reason); 934 return promise; 935} 936 937function needsResolver() { 938 throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); 939} 940 941function needsNew() { 942 throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object c
vendor: 5,964 bytes, lines 942-1131
942onstructor cannot be called as a function."); 943} 944 945/** 946 Promise objects represent the eventual result of an asynchronous operation. The 947 primary way of interacting with a promise is through its `then` method, which 948 registers callbacks to receive either a promise's eventual value or the reason 949 why the promise cannot be fulfilled. 950 951 Terminology 952 ----------- 953 954 - `promise` is an object or function with a `then` method whose behavior conforms to this specification. 955 - `thenable` is an object or function that defines a `then` method. 956 - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). 957 - `exception` is a value that is thrown using the throw statement. 958 - `reason` is a value that indicates why a promise was rejected. 959 - `settled` the final resting state of a promise, fulfilled or rejected. 960 961 A promise can be in one of three states: pending, fulfilled, or rejected. 962 963 Promises that are fulfilled have a fulfillment value and are in the fulfilled 964 state. Promises that are rejected have a rejection reason and are in the 965 rejected state. A fulfillment value is never a thenable. 966 967 Promises can also be said to *resolve* a value. If this value is also a 968 promise, then the original promise's settled state will match the value's 969 settled state. So a promise that *resolves* a promise that rejects will 970 itself reject, and a promise that *resolves* a promise that fulfills will 971 itself fulfill. 972 973 974 Basic Usage: 975 ------------ 976 977 ```js 978 let promise = new Promise(function(resolve, reject) { 979 // on success 980 resolve(value); 981 982 // on failure 983 reject(reason); 984 }); 985 986 promise.then(function(value) { 987 // on fulfillment 988 }, function(reason) { 989 // on rejection 990 }); 991 ``` 992 993 Advanced Usage: 994 --------------- 995 996 Promises shine when abstracting away asynchronous interactions such as 997 `XMLHttpRequest`s. 998 999 ```js 1000 function getJSON(url) { 1001 return new Promise(function(resolve, reject){ 1002 let xhr = new XMLHttpRequest(); 1003 1004 xhr.open('GET', url); 1005 xhr.onreadystatechange = handler; 1006 xhr.responseType = 'json'; 1007 xhr.setRequestHeader('Accept', 'application/json'); 1008 xhr.send(); 1009 1010 function handler() { 1011 if (this.readyState === this.DONE) { 1012 if (this.status === 200) { 1013 resolve(this.response); 1014 } else { 1015 reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); 1016 } 1017 } 1018 }; 1019 }); 1020 } 1021 1022 getJSON('/posts.json').then(function(json) { 1023 // on fulfillment 1024 }, function(reason) { 1025 // on rejection 1026 }); 1027 ``` 1028 1029 Unlike callbacks, promises are great composable primitives. 1030 1031 ```js 1032 Promise.all([ 1033 getJSON('/posts'), 1034 getJSON('/comments') 1035 ]).then(function(values){ 1036 values[0] // => postsJSON 1037 values[1] // => commentsJSON 1038 1039 return values; 1040 }); 1041 ``` 1042 1043 @class Promise 1044 @param {Function} resolver 1045 Useful for tooling. 1046 @constructor 1047*/ 1048 1049var Promise$2 = function () { 1050 function Promise(resolver) { 1051 this[PROMISE_ID] = nextId(); 1052 this._result = this._state = undefined; 1053 this._subscribers = []; 1054 1055 if (noop !== resolver) { 1056 typeof resolver !== 'function' && needsResolver(); 1057 this instanceof Promise ? initializePromise(this, resolver) : needsNew(); 1058 } 1059 } 1060 1061 /** 1062 The primary way of interacting with a promise is through its `then` method, 1063 which registers callbacks to receive either a promise's eventual value or the 1064 reason why the promise cannot be fulfilled. 1065 ```js 1066 findUser().then(function(user){ 1067 // user is available 1068 }, function(reason){ 1069 // user is unavailable, and you are given the reason why 1070 }); 1071 ``` 1072 Chaining 1073 -------- 1074 The return value of `then` is itself a promise. This second, 'downstream' 1075 promise is resolved with the return value of the first promise's fulfillment 1076 or rejection handler, or rejected if the handler throws an exception. 1077 ```js 1078 findUser().then(function (user) { 1079 return user.name; 1080 }, function (reason) { 1081 return 'default name'; 1082 }).then(function (userName) { 1083 // If `findUser` fulfilled, `userName` will be the user's name, otherwise it 1084 // will be `'default name'` 1085 }); 1086 findUser().then(function (user) { 1087 throw new Error('Found user, but still unhappy'); 1088 }, function (reason) { 1089 throw new Error('`findUser` rejected and we're unhappy'); 1090 }).then(function (value) { 1091 // never reached 1092 }, function (reason) { 1093 // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. 1094 // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. 1095 }); 1096 ``` 1097 If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. 1098 ```js 1099 findUser().then(function (user) { 1100 throw new PedagogicalException('Upstream error'); 1101 }).then(function (value) { 1102 // never reached 1103 }).then(function (value) { 1104 // never reached 1105 }, function (reason) { 1106 // The `PedgagocialException` is propagated all the way down to here 1107 }); 1108 ``` 1109 Assimilation 1110 ------------ 1111 Sometimes the value you want to propagate to a downstream promise can only be 1112 retrieved asynchronously. This can be achieved by returning a promise in the 1113 fulfillment or rejection handler. The downstream promise will then be pending 1114 until the returned promise is settled. This is called *assimilation*. 1115 ```js 1116 findUser().then(function (user) { 1117 return findCommentsByAuthor(user); 1118 }).then(function (comments) { 1119 // The user's comments are now available 1120 }); 1121 ``` 1122 If the assimliated promise rejects, then the downstream promise will also reject. 1123 ```js 1124 findUser().then(function (user) { 1125 return findCommentsByAuthor(user); 1126 }).then(function (comments) { 1127 // If `findCommentsByAuthor` fulfills, we'll have the value here 1128 }, function (reason) { 1129 // If `findCommentsByAuthor` rejects, we'll have the reason here 1130 }); 1131 ```
vendor: 5,621 bytes, lines 1132-1402
1132 Simple Example 1133 -------------- 1134 Synchronous Example 1135 ```javascript 1136 let result; 1137 try { 1138 result = findResult(); 1139 // success 1140 } catch(reason) { 1141 // failure 1142 } 1143 ``` 1144 Errback Example 1145 ```js 1146 findResult(function(result, err){ 1147 if (err) { 1148 // failure 1149 } else { 1150 // success 1151 } 1152 }); 1153 ``` 1154 Promise Example; 1155 ```javascript 1156 findResult().then(function(result){ 1157 // success 1158 }, function(reason){ 1159 // failure 1160 }); 1161 ``` 1162 Advanced Example 1163 -------------- 1164 Synchronous Example 1165 ```javascript 1166 let author, books; 1167 try { 1168 author = findAuthor(); 1169 books = findBooksByAuthor(author); 1170 // success 1171 } catch(reason) { 1172 // failure 1173 } 1174 ``` 1175 Errback Example 1176 ```js 1177 function foundBooks(books) { 1178 } 1179 function failure(reason) { 1180 } 1181 findAuthor(function(author, err){ 1182 if (err) { 1183 failure(err); 1184 // failure 1185 } else { 1186 try { 1187 findBoooksByAuthor(author, function(books, err) { 1188 if (err) { 1189 failure(err); 1190 } else { 1191 try { 1192 foundBooks(books); 1193 } catch(reason) { 1194 failure(reason); 1195 } 1196 } 1197 }); 1198 } catch(error) { 1199 failure(err); 1200 } 1201 // success 1202 } 1203 }); 1204 ``` 1205 Promise Example; 1206 ```javascript 1207 findAuthor(). 1208 then(findBooksByAuthor). 1209 then(function(books){ 1210 // found books 1211 }).catch(function(reason){ 1212 // something went wrong 1213 }); 1214 ``` 1215 @method then 1216 @param {Function} onFulfilled 1217 @param {Function} onRejected 1218 Useful for tooling. 1219 @return {Promise} 1220 */ 1221 1222 /** 1223 `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same 1224 as the catch block of a try/catch statement. 1225 ```js 1226 function findAuthor(){ 1227 throw new Error('couldn't find that author'); 1228 } 1229 // synchronous 1230 try { 1231 findAuthor(); 1232 } catch(reason) { 1233 // something went wrong 1234 } 1235 // async with promises 1236 findAuthor().catch(function(reason){ 1237 // something went wrong 1238 }); 1239 ``` 1240 @method catch 1241 @param {Function} onRejection 1242 Useful for tooling. 1243 @return {Promise} 1244 */ 1245 1246 1247 Promise.prototype.catch = function _catch(onRejection) { 1248 return this.then(null, onRejection); 1249 }; 1250 1251 /** 1252 `finally` will be invoked regardless of the promise's fate just as native 1253 try/catch/finally behaves 1254 1255 Synchronous example: 1256 1257 ```js 1258 findAuthor() { 1259 if (Math.random() > 0.5) { 1260 throw new Error(); 1261 } 1262 return new Author(); 1263 } 1264 1265 try { 1266 return findAuthor(); // succeed or fail 1267 } catch(error) { 1268 return findOtherAuther(); 1269 } finally { 1270 // always runs 1271 // doesn't affect the return value 1272 } 1273 ``` 1274 1275 Asynchronous example: 1276 1277 ```js 1278 findAuthor().catch(function(reason){ 1279 return findOtherAuther(); 1280 }).finally(function(){ 1281 // author was either found, or not 1282 }); 1283 ``` 1284 1285 @method finally 1286 @param {Function} callback 1287 @return {Promise} 1288 */ 1289 1290 1291 Promise.prototype.finally = function _finally(callback) { 1292 var promise = this; 1293 var constructor = promise.constructor; 1294 1295 return promise.then(function (value) { 1296 return constructor.resolve(callback()).then(function () { 1297 return value; 1298 }); 1299 }, function (reason) { 1300 return constructor.resolve(callback()).then(function () { 1301 throw reason; 1302 }); 1303 }); 1304 }; 1305 1306 return Promise; 1307}(); 1308 1309Promise$2.prototype.then = then; 1310Promise$2.all = all; 1311Promise$2.race = race; 1312Promise$2.resolve = resolve$1; 1313Promise$2.reject = reject$1; 1314Promise$2._setScheduler = setScheduler; 1315Promise$2._setAsap = setAsap; 1316Promise$2._asap = asap; 1317 1318/*global self*/ 1319function polyfill() { 1320 var local = void 0; 1321 1322 if (typeof global !== 'undefined') { 1323 local = global; 1324 } else if (typeof self !== 'undefined') { 1325 local = self; 1326 } else { 1327 try { 1328 local = Function('return this')(); 1329 } catch (e) { 1330 throw new Error('polyfill failed because global object is unavailable in this environment'); 1331 } 1332 } 1333 1334 var P = local.Promise; 1335 1336 if (P) { 1337 var promiseToString = null; 1338 try { 1339 promiseToString = Object.prototype.toString.call(P.resolve()); 1340 } catch (e) { 1341 // silently ignored 1342 } 1343 1344 if (promiseToString === '[object Promise]' && !P.cast) { 1345 return; 1346 } 1347 } 1348 1349 local.Promise = Promise$2; 1350} 1351 1352// Strange compat.. 1353Promise$2.polyfill = polyfill; 1354Promise$2.Promise = Promise$2; 1355 1356Promise$2.polyfill(); 1357 1358return Promise$2; 1359 1360}))); 1361 1362 1363 1364//# sourceMappingURL=es6-promise.auto.map 1365 1366/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(2))) 1367 1368/***/ }), 1369/* 2 */ 1370/***/ (function(module, exports) { 1371 1372var g; 1373 1374// This works in non-strict mode 1375g = (function() { 1376 return this; 1377})(); 1378 1379try { 1380 // This works if eval is allowed (see CSP) 1381 g = g || new Function("return this")(); 1382} catch (e) { 1383 // This works if the window reference is available 1384 if (typeof window === "object") g = window; 1385} 1386 1387// g can still be undefined, but nothing to do about it... 1388// We return undefined, instead of nothing here, so it's 1389// easier to handle this case. if(!global) { ...} 1390 1391module.exports = g; 1392 1393 1394/***/ }), 1395/* 3 */ 1396/***/ (function(module, __webpack_exports__, __webpack_require__) { 1397 1398"use strict"; 1399__webpack_require__.r(__webpack_exports__); 1400/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "VERSION", function() { return VERSION; }); 1401/* harmony import */ var _Errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); 1402/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "
vendor: 12,518 bytes, lines 1402-1655
1402AbortError", function() { return _Errors__WEBPACK_IMPORTED_MODULE_0__["AbortError"]; }); 1403 1404/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpError", function() { return _Errors__WEBPACK_IMPORTED_MODULE_0__["HttpError"]; }); 1405 1406/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TimeoutError", function() { return _Errors__WEBPACK_IMPORTED_MODULE_0__["TimeoutError"]; }); 1407 1408/* harmony import */ var _HttpClient__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5); 1409/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpClient", function() { return _HttpClient__WEBPACK_IMPORTED_MODULE_1__["HttpClient"]; }); 1410 1411/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpResponse", function() { return _HttpClient__WEBPACK_IMPORTED_MODULE_1__["HttpResponse"]; }); 1412 1413/* harmony import */ var _DefaultHttpClient__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6); 1414/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DefaultHttpClient", function() { return _DefaultHttpClient__WEBPACK_IMPORTED_MODULE_2__["DefaultHttpClient"]; }); 1415 1416/* harmony import */ var _HubConnection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10); 1417/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnection", function() { return _HubConnection__WEBPACK_IMPORTED_MODULE_3__["HubConnection"]; }); 1418 1419/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnectionState", function() { return _HubConnection__WEBPACK_IMPORTED_MODULE_3__["HubConnectionState"]; }); 1420 1421/* harmony import */ var _HubConnectionBuilder__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(17); 1422/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HubConnectionBuilder", function() { return _HubConnectionBuilder__WEBPACK_IMPORTED_MODULE_4__["HubConnectionBuilder"]; }); 1423 1424/* harmony import */ var _IHubProtocol__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(15); 1425/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "MessageType", function() { return _IHubProtocol__WEBPACK_IMPORTED_MODULE_5__["MessageType"]; }); 1426 1427/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(9); 1428/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LogLevel", function() { return _ILogger__WEBPACK_IMPORTED_MODULE_6__["LogLevel"]; }); 1429 1430/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(20); 1431/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "HttpTransportType", function() { return _ITransport__WEBPACK_IMPORTED_MODULE_7__["HttpTransportType"]; }); 1432 1433/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransferFormat", function() { return _ITransport__WEBPACK_IMPORTED_MODULE_7__["TransferFormat"]; }); 1434 1435/* harmony import */ var _Loggers__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(14); 1436/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "NullLogger", function() { return _Loggers__WEBPACK_IMPORTED_MODULE_8__["NullLogger"]; }); 1437 1438/* harmony import */ var _JsonHubProtocol__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(25); 1439/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "JsonHubProtocol", function() { return _JsonHubProtocol__WEBPACK_IMPORTED_MODULE_9__["JsonHubProtocol"]; }); 1440 1441/* harmony import */ var _Subject__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(16); 1442/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Subject", function() { return _Subject__WEBPACK_IMPORTED_MODULE_10__["Subject"]; }); 1443 1444// Copyright (c) .NET Foundation. All rights reserved. 1445// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1446// Version token that will be replaced by the prepack command 1447/** The version of the SignalR client. */ 1448var VERSION = "3.1.7"; 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462/***/ }), 1463/* 4 */ 1464/***/ (function(module, __webpack_exports__, __webpack_require__) { 1465 1466"use strict"; 1467__webpack_require__.r(__webpack_exports__); 1468/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HttpError", function() { return HttpError; }); 1469/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TimeoutError", function() { return TimeoutError; }); 1470/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AbortError", function() { return AbortError; }); 1471// Copyright (c) .NET Foundation. All rights reserved. 1472// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1473var __extends = (undefined && undefined.__extends) || (function () { 1474 var extendStatics = Object.setPrototypeOf || 1475 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 1476 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 1477 return function (d, b) { 1478 extendStatics(d, b); 1479 function __() { this.constructor = d; } 1480 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1481 }; 1482})(); 1483/** Error thrown when an HTTP request fails. */ 1484var HttpError = /** @class */ (function (_super) { 1485 __extends(HttpError, _super); 1486 /** Constructs a new instance of {@link @microsoft/signalr.HttpError}. 1487 * 1488 * @param {string} errorMessage A descriptive error message. 1489 * @param {number} statusCode The HTTP status code represented by this error. 1490 */ 1491 function HttpError(errorMessage, statusCode) { 1492 var _newTarget = this.constructor; 1493 var _this = this; 1494 var trueProto = _newTarget.prototype; 1495 _this = _super.call(this, errorMessage) || this; 1496 _this.statusCode = statusCode; 1497 // Workaround issue in Typescript compiler 1498 // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 1499 _this.__proto__ = trueProto; 1500 return _this; 1501 } 1502 return HttpError; 1503}(Error)); 1504 1505/** Error thrown when a timeout elapses. */ 1506var TimeoutError = /** @class */ (function (_super) { 1507 __extends(TimeoutError, _super); 1508 /** Constructs a new instance of {@link @microsoft/signalr.TimeoutError}. 1509 * 1510 * @param {string} errorMessage A descriptive error message. 1511 */ 1512 function TimeoutError(errorMessage) { 1513 var _newTarget = this.constructor; 1514 if (errorMessage === void 0) { errorMessage = "A timeout occurred."; } 1515 var _this = this; 1516 var trueProto = _newTarget.prototype; 1517 _this = _super.call(this, errorMessage) || this; 1518 // Workaround issue in Typescript compiler 1519 // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 1520 _this.__proto__ = trueProto; 1521 return _this; 1522 } 1523 return TimeoutError; 1524}(Error)); 1525 1526/** Error thrown when an action is aborted. */ 1527var AbortError = /** @class */ (function (_super) { 1528 __extends(AbortError, _super); 1529 /** Constructs a new instance of {@link AbortError}. 1530 * 1531 * @param {string} errorMessage A descriptive error message. 1532 */ 1533 function AbortError(errorMessage) { 1534 var _newTarget = this.constructor; 1535 if (errorMessage === void 0) { errorMessage = "An abort occurred."; } 1536 var _this = this; 1537 var trueProto = _newTarget.prototype; 1538 _this = _super.call(this, errorMessage) || this; 1539 // Workaround issue in Typescript compiler 1540 // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 1541 _this.__proto__ = trueProto; 1542 return _this; 1543 } 1544 return AbortError; 1545}(Error)); 1546 1547 1548 1549/***/ }), 1550/* 5 */ 1551/***/ (function(module, __webpack_exports__, __webpack_require__) { 1552 1553"use strict"; 1554__webpack_require__.r(__webpack_exports__); 1555/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HttpResponse", function() { return HttpResponse; }); 1556/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HttpClient", function() { return HttpClient; }); 1557// Copyright (c) .NET Foundation. All rights reserved. 1558// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1559var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { 1560 for (var s, i = 1, n = arguments.length; i < n; i++) { 1561 s = arguments[i]; 1562 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) 1563 t[p] = s[p]; 1564 } 1565 return t; 1566}; 1567/** Represents an HTTP response. */ 1568var HttpResponse = /** @class */ (function () { 1569 function HttpResponse(statusCode, statusText, content) { 1570 this.statusCode = statusCode; 1571 this.statusText = statusText; 1572 this.content = content; 1573 } 1574 return HttpResponse; 1575}()); 1576 1577/** Abstraction over an HTTP client. 1578 * 1579 * This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms. 1580 */ 1581var HttpClient = /** @class */ (function () { 1582 function HttpClient() { 1583 } 1584 HttpClient.prototype.get = function (url, options) { 1585 return this.send(__assign({}, options, { method: "GET", url: url })); 1586 }; 1587 HttpClient.prototype.post = function (url, options) { 1588 return this.send(__assign({}, options, { method: "POST", url: url })); 1589 }; 1590 HttpClient.prototype.delete = function (url, options) { 1591 return this.send(__assign({}, options, { method: "DELETE", url: url })); 1592 }; 1593 /** Gets all cookies that apply to the specified URL. 1594 * 1595 * @param url The URL that the cookies are valid for. 1596 * @returns {string} A string containing all the key-value cookie pairs for the specified URL. 1597 */ 1598 // @ts-ignore 1599 HttpClient.prototype.getCookieString = function (url) { 1600 return ""; 1601 }; 1602 return HttpClient; 1603}()); 1604 1605 1606 1607/***/ }), 1608/* 6 */ 1609/***/ (function(module, __webpack_exports__, __webpack_require__) { 1610 1611"use strict"; 1612__webpack_require__.r(__webpack_exports__); 1613/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DefaultHttpClient", function() { return DefaultHttpClient; }); 1614/* harmony import */ var _Errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); 1615/* harmony import */ var _HttpClient__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5); 1616/* harmony import */ var _NodeHttpClient__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7); 1617/* harmony import */ var _XhrHttpClient__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8); 1618// Copyright (c) .NET Foundation. All rights reserved. 1619// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1620var __extends = (undefined && undefined.__extends) || (function () { 1621 var extendStatics = Object.setPrototypeOf || 1622 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 1623 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 1624 return function (d, b) { 1625 extendStatics(d, b); 1626 function __() { this.constructor = d; } 1627 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1628 }; 1629})(); 1630 1631 1632 1633 1634/** Default implementation of {@link @microsoft/signalr.HttpClient}. */ 1635var DefaultHttpClient = /** @class */ (function (_super) { 1636 __extends(DefaultHttpClient, _super); 1637 /** Creates a new instance of the {@link @microsoft/signalr.DefaultHttpClient}, using the provided {@link @microsoft/signalr.ILogger} to log messages. */ 1638 function DefaultHttpClient(logger) { 1639 var _this = _super.call(this) || this; 1640 if (typeof XMLHttpRequest !== "undefined") { 1641 _this.httpClient = new _XhrHttpClient__WEBPACK_IMPORTED_MODULE_3__["XhrHttpClient"](logger); 1642 } 1643 else { 1644 _this.httpClient = new _NodeHttpClient__WEBPACK_IMPORTED_MODULE_2__["NodeHttpClient"](logger); 1645 } 1646 return _this; 1647 } 1648 /** @inheritDoc */ 1649 DefaultHttpClient.prototype.send = function (request) { 1650 // Check that abort was not signaled before calling send 1651 if (request.abortSignal && request.abortSignal.aborted) { 1652 return Promise.reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["AbortError"]()); 1653 } 1654 if (!request.method) { 1655 return Promise.reject(new Error("No method defined."));
1656 } 1657 if (!request.url) { 1658 return Promise.reject(new Error("No url defined.")); 1659 } 1660 return this.httpClient.send(request); 1661 }; 1662 DefaultHttpClient.prototype.getCookieString = function (url) { 1663 return this.httpClient.getCookieString(url); 1664 }; 1665 return DefaultHttpClient; 1666}(_HttpClient__WEBPACK_IMPORTED_MODULE_1__["HttpClient"])); 1667 1668 1669 1670/***/ }), 1671/* 7 */ 1672/***/ (function(module, __webpack_exports__, __webpack_require__) { 1673 1674"use strict"; 1675__webpack_require__.r(__webpack_exports__); 1676/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NodeHttpClient", function() { return NodeHttpClient; }); 1677/* harmony import */ var _HttpClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5); 1678// Copyright (c) .NET Foundation. All rights reserved. 1679// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1680var __extends = (undefined && undefined.__extends) || (function () { 1681 var extendStatics = Object.setPrototypeOf || 1682 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 1683 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 1684 return function (d, b) { 1685 extendStatics(d, b); 1686 function __() { this.constructor = d; } 1687 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1688 }; 1689})(); 1690// This is an empty implementation of the NodeHttpClient that will be included in browser builds so the output file will be smaller 1691 1692/** @private */ 1693var NodeHttpClient = /** @class */ (function (_super) { 1694 __extends(NodeHttpClient, _super); 1695 // @ts-ignore: Need ILogger to compile, but unused variables generate errors 1696 function NodeHttpClient(logger) { 1697 return _super.call(this) || this; 1698 } 1699 NodeHttpClient.prototype.send = function () { 1700 return Promise.reject(new Error("If using Node either provide an XmlHttpRequest polyfill or consume the cjs or esm script instead of the browser/signalr.js one.")); 1701 }; 1702 return NodeHttpClient; 1703}(_HttpClient__WEBPACK_IMPORTED_MODULE_0__["HttpClient"])); 1704 1705 1706 1707/***/ }), 1708/* 8 */ 1709/***/ (function(module, __webpack_exports__, __webpack_require__) { 1710 1711"use strict"; 1712__webpack_require__.r(__webpack_exports__); 1713/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "XhrHttpClient", function() { return XhrHttpClient; }); 1714/* harmony import */ var _Errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); 1715/* harmony import */ var _HttpClient__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5); 1716/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9); 1717// Copyright (c) .NET Foundation. All rights reserved. 1718// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1719var __extends = (undefined && undefined.__extends) || (function () { 1720 var extendStatics = Object.setPrototypeOf || 1721 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 1722 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; 1723 return function (d, b) { 1724 extendStatics(d, b); 1725 function __() { this.constructor = d; } 1726 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 1727 }; 1728})(); 1729 1730 1731 1732var XhrHttpClient = /** @class */ (function (_super) { 1733 __extends(XhrHttpClient, _super); 1734 function XhrHttpClient(logger) { 1735 var _this = _super.call(this) || this; 1736 _this.logger = logger; 1737 return _this; 1738 } 1739 /** @inheritDoc */ 1740 XhrHttpClient.prototype.send = function (request) { 1741 var _this = this; 1742 // Check that abort was not signaled before calling send 1743 if (request.abortSignal && request.abortSignal.aborted) { 1744 return Promise.reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["AbortError"]()); 1745 } 1746 if (!request.method) { 1747 return Promise.reject(new Error("No method defined."));
vendor: 6,015 bytes, lines 1748-1859
1748 } 1749 if (!request.url) { 1750 return Promise.reject(new Error("No url defined.")); 1751 } 1752 return new Promise(function (resolve, reject) { 1753 var xhr = new XMLHttpRequest(); 1754 xhr.open(request.method, request.url, true); 1755 xhr.withCredentials = true; 1756 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); 1757 // Explicitly setting the Content-Type header for React Native on Android platform. 1758 xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); 1759 var headers = request.headers; 1760 if (headers) { 1761 Object.keys(headers) 1762 .forEach(function (header) { 1763 xhr.setRequestHeader(header, headers[header]); 1764 }); 1765 } 1766 if (request.responseType) { 1767 xhr.responseType = request.responseType; 1768 } 1769 if (request.abortSignal) { 1770 request.abortSignal.onabort = function () { 1771 xhr.abort(); 1772 reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["AbortError"]()); 1773 }; 1774 } 1775 if (request.timeout) { 1776 xhr.timeout = request.timeout; 1777 } 1778 xhr.onload = function () { 1779 if (request.abortSignal) { 1780 request.abortSignal.onabort = null; 1781 } 1782 if (xhr.status >= 200 && xhr.status < 300) { 1783 resolve(new _HttpClient__WEBPACK_IMPORTED_MODULE_1__["HttpResponse"](xhr.status, xhr.statusText, xhr.response || xhr.responseText)); 1784 } 1785 else { 1786 reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["HttpError"](xhr.statusText, xhr.status)); 1787 } 1788 }; 1789 xhr.onerror = function () { 1790 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Warning, "Error from HTTP request. " + xhr.status + ": " + xhr.statusText + "."); 1791 reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["HttpError"](xhr.statusText, xhr.status)); 1792 }; 1793 xhr.ontimeout = function () { 1794 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Warning, "Timeout from HTTP request."); 1795 reject(new _Errors__WEBPACK_IMPORTED_MODULE_0__["TimeoutError"]()); 1796 }; 1797 xhr.send(request.content || ""); 1798 }); 1799 }; 1800 return XhrHttpClient; 1801}(_HttpClient__WEBPACK_IMPORTED_MODULE_1__["HttpClient"])); 1802 1803 1804 1805/***/ }), 1806/* 9 */ 1807/***/ (function(module, __webpack_exports__, __webpack_require__) { 1808 1809"use strict"; 1810__webpack_require__.r(__webpack_exports__); 1811/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LogLevel", function() { return LogLevel; }); 1812// Copyright (c) .NET Foundation. All rights reserved. 1813// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1814// These values are designed to match the ASP.NET Log Levels since that's the pattern we're emulating here. 1815/** Indicates the severity of a log message. 1816 * 1817 * Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc. 1818 */ 1819var LogLevel; 1820(function (LogLevel) { 1821 /** Log level for very low severity diagnostic messages. */ 1822 LogLevel[LogLevel["Trace"] = 0] = "Trace"; 1823 /** Log level for low severity diagnostic messages. */ 1824 LogLevel[LogLevel["Debug"] = 1] = "Debug"; 1825 /** Log level for informational diagnostic messages. */ 1826 LogLevel[LogLevel["Information"] = 2] = "Information"; 1827 /** Log level for diagnostic messages that indicate a non-fatal problem. */ 1828 LogLevel[LogLevel["Warning"] = 3] = "Warning"; 1829 /** Log level for diagnostic messages that indicate a failure in the current operation. */ 1830 LogLevel[LogLevel["Error"] = 4] = "Error"; 1831 /** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */ 1832 LogLevel[LogLevel["Critical"] = 5] = "Critical"; 1833 /** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */ 1834 LogLevel[LogLevel["None"] = 6] = "None"; 1835})(LogLevel || (LogLevel = {})); 1836 1837 1838/***/ }), 1839/* 10 */ 1840/***/ (function(module, __webpack_exports__, __webpack_require__) { 1841 1842"use strict"; 1843__webpack_require__.r(__webpack_exports__); 1844/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HubConnectionState", function() { return HubConnectionState; }); 1845/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HubConnection", function() { return HubConnection; }); 1846/* harmony import */ var _HandshakeProtocol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11); 1847/* harmony import */ var _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15); 1848/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9); 1849/* harmony import */ var _Subject__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(16); 1850/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(13); 1851// Copyright (c) .NET Foundation. All rights reserved. 1852// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 1853var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 1854 return new (P || (P = Promise))(function (resolve, reject) { 1855 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 1856 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 1857 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 1858 step((generator = generator.apply(thisArg, _arguments || [])).next()); 1859 });
1860}; 1861var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 1862 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 1863 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 1864 function verb(n) { return function (v) { return step([n, v]); }; } 1865 function step(op) { 1866 if (f) throw new TypeError("Generator is already executing."); 1867 while (_) try { 1868 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 1869 if (y = 0, t) op = [op[0] & 2, t.value]; 1870 switch (op[0]) { 1871 case 0: case 1: t = op; break; 1872 case 4: _.label++; return { value: op[1], done: false }; 1873 case 5: _.label++; y = op[1]; op = [0]; continue; 1874 case 7: op = _.ops.pop(); _.trys.pop(); continue; 1875 default: 1876 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 1877 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 1878 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 1879 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 1880 if (t[2]) _.ops.pop(); 1881 _.trys.pop(); continue; 1882 } 1883 op = body.call(thisArg, _); 1884 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 1885 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 1886 } 1887}; 1888 1889 1890 1891 1892 1893var DEFAULT_TIMEOUT_IN_MS = 30 * 1000; 1894var DEFAULT_PING_INTERVAL_IN_MS = 15 * 1000; 1895/** Describes the current state of the {@link HubConnection} to the server. */ 1896var HubConnectionState; 1897(function (HubConnectionState) { 1898 /** The hub connection is disconnected. */ 1899 HubConnectionState["Disconnected"] = "Disconnected"; 1900 /** The hub connection is connecting. */ 1901 HubConnectionState["Connecting"] = "Connecting"; 1902 /** The hub connection is connected. */ 1903 HubConnectionState["Connected"] = "Connected"; 1904 /** The hub connection is disconnecting. */ 1905 HubConnectionState["Disconnecting"] = "Disconnecting"; 1906 /** The hub connection is reconnecting. */ 1907 HubConnectionState["Reconnecting"] = "Reconnecting"; 1908})(HubConnectionState || (HubConnectionState = {})); 1909/** Represents a connection to a SignalR Hub. */ 1910var HubConnection = /** @class */ (function () { 1911 function HubConnection(connection, logger, protocol, reconnectPolicy) { 1912 var _this = this; 1913 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isRequired(connection, "connection"); 1914 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isRequired(logger, "logger"); 1915 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isRequired(protocol, "protocol"); 1916 this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS; 1917 this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS; 1918 this.logger = logger; 1919 this.protocol = protocol; 1920 this.connection = connection; 1921 this.reconnectPolicy = reconnectPolicy; 1922 this.handshakeProtocol = new _HandshakeProtocol__WEBPACK_IMPORTED_MODULE_0__["HandshakeProtocol"](); 1923 this.connection.onreceive = function (data) { return _this.processIncomingData(data); }; 1924 this.connection.onclose = function (error) { return _this.connectionClosed(error); }; 1925 this.callbacks = {}; 1926 this.methods = {}; 1927 this.closedCallbacks = []; 1928 this.reconnectingCallbacks = []; 1929 this.reconnectedCallbacks = []; 1930 this.invocationId = 0; 1931 this.receivedHandshakeResponse = false; 1932 this.connectionState = HubConnectionState.Disconnected; 1933 this.connectionStarted = false; 1934 this.cachedPingMessage = this.protocol.writeMessage({ type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Ping });
1935 } 1936 /** @internal */ 1937 // Using a public static factory method means we can have a private constructor and an _internal_ 1938 // create method that can be used by HubConnectionBuilder. An "internal" constructor would just 1939 // be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a 1940 // public parameter-less constructor. 1941 HubConnection.create = function (connection, logger, protocol, reconnectPolicy) { 1942 return new HubConnection(connection, logger, protocol, reconnectPolicy); 1943 }; 1944 Object.defineProperty(HubConnection.prototype, "state", { 1945 /** Indicates the state of the {@link HubConnection} to the server. */ 1946 get: function () { 1947 return this.connectionState; 1948 }, 1949 enumerable: true, 1950 configurable: true 1951 }); 1952 Object.defineProperty(HubConnection.prototype, "connectionId", { 1953 /** Represents the connection id of the {@link HubConnection} on the server. The connection id will be null when the connection is either 1954 * in the disconnected state or if the negotiation step was skipped. 1955 */ 1956 get: function () { 1957 return this.connection ? (this.connection.connectionId || null) : null; 1958 }, 1959 enumerable: true, 1960 configurable: true 1961 }); 1962 Object.defineProperty(HubConnection.prototype, "baseUrl", { 1963 /** Indicates the url of the {@link HubConnection} to the server. */ 1964 get: function () { 1965 return this.connection.baseUrl || ""; 1966 }, 1967 /** 1968 * Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or 1969 * Reconnecting states. 1970 * @param {string} url The url to connect to. 1971 */ 1972 set: function (url) { 1973 if (this.connectionState !== HubConnectionState.Disconnected && this.connectionState !== HubConnectionState.Reconnecting) { 1974 throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url."); 1975 } 1976 if (!url) { 1977 throw new Error("The HubConnection url must be a valid url."); 1978 } 1979 this.connection.baseUrl = url; 1980 }, 1981 enumerable: true, 1982 configurable: true 1983 }); 1984 /** Starts the connection. 1985 * 1986 * @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error. 1987 */ 1988 HubConnection.prototype.start = function () { 1989 this.startPromise = this.startWithStateTransitions(); 1990 return this.startPromise; 1991 }; 1992 HubConnection.prototype.startWithStateTransitions = function () { 1993 return __awaiter(this, void 0, void 0, function () { 1994 var e_1; 1995 return __generator(this, function (_a) { 1996 switch (_a.label) { 1997 case 0: 1998 if (this.connectionState !== HubConnectionState.Disconnected) { 1999 return [2 /*return*/, Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."))]; 2000 } 2001 this.connectionState = HubConnectionState.Connecting; 2002 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Starting HubConnection."); 2003 _a.label = 1; 2004 case 1: 2005 _a.trys.push([1, 3, , 4]); 2006 return [4 /*yield*/, this.startInternal()]; 2007 case 2: 2008 _a.sent(); 2009 this.connectionState = HubConnectionState.Connected; 2010 this.connectionStarted = true; 2011 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "HubConnection connected successfully."); 2012 return [3 /*break*/, 4]; 2013 case 3: 2014 e_1 = _a.sent(); 2015 this.connectionState = HubConnectionState.Disconnected; 2016 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "HubConnection failed to start successfully because of error '" + e_1 + "'."); 2017 return [2 /*return*/, Promise.reject(e_1)]; 2018 case 4: return [2 /*return*/]; 2019 } 2020 }); 2021 }); 2022 }; 2023 HubConnection.prototype.startInternal = function () { 2024 return __awaiter(this, void 0, void 0, function () { 2025 var handshakePromise, handshakeRequest, e_2; 2026 var _this = this; 2027 return __generator(this, function (_a) { 2028 switch (_a.label) { 2029 case 0: 2030 this.stopDuringStartError = undefined; 2031 this.receivedHandshakeResponse = false; 2032 handshakePromise = new Promise(function (resolve, reject) { 2033 _this.handshakeResolver = resolve; 2034 _this.handshakeRejecter = reject; 2035 }); 2036 return [4 /*yield*/, this.connection.start(this.protocol.transferFormat)]; 2037 case 1: 2038 _a.sent(); 2039 _a.label = 2; 2040 case 2: 2041 _a.trys.push([2, 5, , 7]); 2042 handshakeRequest = { 2043 protocol: this.protocol.name, 2044 version: this.protocol.version, 2045 }; 2046 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Sending handshake request."); 2047 return [4 /*yield*/, this.sendMessage(this.handshakeProtocol.writeHandshakeRequest
2047(handshakeRequest))]; 2048 case 3: 2049 _a.sent(); 2050 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Using HubProtocol '" + this.protocol.name + "'."); 2051 // defensively cleanup timeout in case we receive a message from the server before we finish start 2052 this.cleanupTimeout(); 2053 this.resetTimeoutPeriod(); 2054 this.resetKeepAliveInterval(); 2055 return [4 /*yield*/, handshakePromise]; 2056 case 4: 2057 _a.sent(); 2058 // It's important to check the stopDuringStartError instead of just relying on the handshakePromise 2059 // being rejected on close, because this continuation can run after both the handshake completed successfully 2060 // and the connection was closed. 2061 if (this.stopDuringStartError) { 2062 // It's important to throw instead of returning a rejected promise, because we don't want to allow any state 2063 // transitions to occur between now and the calling code observing the exceptions. Returning a rejected promise 2064 // will cause the calling continuation to get scheduled to run later. 2065 throw this.stopDuringStartError; 2066 } 2067 return [3 /*break*/, 7]; 2068 case 5: 2069 e_2 = _a.sent(); 2070 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Hub handshake failed with error '" + e_2 + "' during start(). Stopping HubConnection."); 2071 this.cleanupTimeout(); 2072 this.cleanupPingTimer(); 2073 // HttpConnection.stop() should not complete until after the onclose callback is invoked. 2074 // This will transition the HubConnection to the disconnected state before HttpConnection.stop() completes. 2075 return [4 /*yield*/, this.connection.stop(e_2)]; 2076 case 6: 2077 // HttpConnection.stop() should not complete until after the onclose callback is invoked. 2078 // This will transition the HubConnection to the disconnected state before HttpConnection.stop() completes. 2079 _a.sent(); 2080 throw e_2; 2081 case 7: return [2 /*return*/]; 2082 } 2083 }); 2084 }); 2085 }; 2086 /** Stops the connection. 2087 * 2088 * @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. 2089 */ 2090 HubConnection.prototype.stop = function () { 2091 return __awaiter(this, void 0, void 0, function () { 2092 var startPromise, e_3; 2093 return __generator(this, function (_a) { 2094 switch (_a.label) { 2095 case 0: 2096 startPromise = this.startPromise; 2097 this.stopPromise = this.stopInternal(); 2098 return [4 /*yield*/, this.stopPromise]; 2099 case 1: 2100 _a.sent(); 2101 _a.label = 2; 2102 case 2: 2103 _a.trys.push([2, 4, , 5]); 2104 // Awaiting undefined continues immediately 2105 return [4 /*yield*/, startPromise]; 2106 case 3: 2107 // Awaiting undefined continues immediately 2108 _a.sent(); 2109 return [3 /*break*/, 5]; 2110 case 4: 2111 e_3 = _a.sent(); 2112 return [3 /*break*/, 5]; 2113 case 5: return [2 /*return*/]; 2114 } 2115 }); 2116 }); 2117 }; 2118 HubConnection.prototype.stopInternal = function (error) { 2119 if (this.connectionState === HubConnectionState.Disconnected) { 2120 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Call to HubConnection.stop("
2120+ error + ") ignored because it is already in the disconnected state."); 2121 return Promise.resolve(); 2122 } 2123 if (this.connectionState === HubConnectionState.Disconnecting) { 2124 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Call to HttpConnection.stop(" + error + ") ignored because the connection is already in the disconnecting state."); 2125 return this.stopPromise; 2126 } 2127 this.connectionState = HubConnectionState.Disconnecting; 2128 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Stopping HubConnection."); 2129 if (this.reconnectDelayHandle) { 2130 // We're in a reconnect delay which means the underlying connection is currently already stopped. 2131 // Just clear the handle to stop the reconnect loop (which no one is waiting on thankfully) and 2132 // fire the onclose callbacks. 2133 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Connection stopped during reconnect delay. Done reconnecting."); 2134 clearTimeout(this.reconnectDelayHandle); 2135 this.reconnectDelayHandle = undefined; 2136 this.completeClose(); 2137 return Promise.resolve(); 2138 } 2139 this.cleanupTimeout(); 2140 this.cleanupPingTimer(); 2141 this.stopDuringStartError = error || new Error("The connection was stopped before the hub handshake could complete."); 2142 // HttpConnection.stop() should not complete until after either HttpConnection.start() fails 2143 // or the onclose callback is invoked. The onclose callback will transition the HubConnection 2144 // to the disconnected state if need be before HttpConnection.stop() completes. 2145 return this.connection.stop(error); 2146 }; 2147 /** Invokes a streaming hub method on the server using the specified name and arguments. 2148 * 2149 * @typeparam T The type of the items returned by the server. 2150 * @param {string} methodName The name of the server method to invoke. 2151 * @param {any[]} args The arguments used to invoke the server method. 2152 * @returns {IStreamResult<T>} An object that yields results from the server as they are received. 2153 */ 2154 HubConnection.prototype.stream = function (methodName) { 2155 var _this = this; 2156 var args = []; 2157 for (var _i = 1; _i < arguments.length; _i++) { 2158 args[_i - 1] = arguments[_i]; 2159 } 2160 var _a = this.replaceStreamingParams(args), streams = _a[0], streamIds = _a[1]; 2161 var invocationDescriptor = this.createStreamInvocation(methodName, args, streamIds); 2162 var promiseQueue; 2163 var subject = new _Subject__WEBPACK_IMPORTED_MODULE_3__["Subject"](); 2164 subject.cancelCallback = function () { 2165 var cancelInvocation = _this.createCancelInvocation(invocationDescriptor.invocationId); 2166 delete _this.callbacks[invocationDescriptor.invocationId]; 2167 return promiseQueue.then(function () { 2168 return _this.sendWithProtocol(cancelInvocation); 2169 }); 2170 }; 2171 this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { 2172 if (error) { 2173 subject.error(error); 2174 return; 2175 } 2176 else if (invocationEvent) { 2177 // invocationEvent will not be null when an error is not passed to the callback 2178 if (invocationEvent.type === _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion) { 2179 if (invocationEvent.error) { 2180 subject.error(new Error(invocationEvent.error)); 2181 } 2182 else { 2183 subject.complete(); 2184 } 2185 } 2186 else { 2187 subject.next((invocationEvent.item)); 2188 } 2189 } 2190 }; 2191 promiseQueue = this.sendWithProtocol(invocationDescriptor) 2192 .catch(function (e) { 2193 subject.error(e); 2194 delete _this.callbacks[invocationDescriptor.invocationId]; 2195 });
2196 this.launchStreams(streams, promiseQueue); 2197 return subject; 2198 }; 2199 HubConnection.prototype.sendMessage = function (message) { 2200 this.resetKeepAliveInterval(); 2201 return this.connection.send(message); 2202 }; 2203 /** 2204 * Sends a js object to the server. 2205 * @param message The js object to serialize and send. 2206 */ 2207 HubConnection.prototype.sendWithProtocol = function (message) { 2208 return this.sendMessage(this.protocol.writeMessage(message)); 2209 }; 2210 /** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. 2211 * 2212 * The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still 2213 * be processing the invocation. 2214 * 2215 * @param {string} methodName The name of the server method to invoke. 2216 * @param {any[]} args The arguments used to invoke the server method. 2217 * @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. 2218 */ 2219 HubConnection.prototype.send = function (methodName) { 2220 var args = []; 2221 for (var _i = 1; _i < arguments.length; _i++) { 2222 args[_i - 1] = arguments[_i]; 2223 } 2224 var _a = this.replaceStreamingParams(args), streams = _a[0], streamIds = _a[1]; 2225 var sendPromise = this.sendWithProtocol(this.createInvocation(methodName, args, true, streamIds)); 2226 this.launchStreams(streams, sendPromise); 2227 return sendPromise; 2228 }; 2229 /** Invokes a hub method on the server using the specified name and arguments. 2230 * 2231 * The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise 2232 * resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of 2233 * resolving the Promise. 2234 * 2235 * @typeparam T The expected return type. 2236 * @param {string} methodName The name of the server method to invoke. 2237 * @param {any[]} args The arguments used to invoke the server method. 2238 * @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error. 2239 */ 2240 HubConnection.prototype.invoke = function (methodName) { 2241 var _this = this; 2242 var args = []; 2243 for (var _i = 1; _i < arguments.length; _i++) { 2244 args[_i - 1] = arguments[_i]; 2245 } 2246 var _a = this.replaceStreamingParams(args), streams = _a[0], streamIds = _a[1]; 2247 var invocationDescriptor = this.createInvocation(methodName, args, false, streamIds); 2248 var p = new Promise(function (resolve, reject) { 2249 // invocationId will always have a value for a non-blocking invocation 2250 _this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { 2251 if (error) { 2252 reject(error); 2253 return; 2254 } 2255 else if (invocationEvent) { 2256 // invocationEvent will not be null when an error is not passed to the callback 2257 if (invocationEvent.type === _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion) { 2258 if (invocationEvent.error) { 2259 reject(new Error(invocationEvent.error)); 2260 } 2261 else { 2262 resolve(invocationEvent.result); 2263 } 2264 } 2265 else { 2266 reject(new Error("Unexpected message type: " + invocationEvent.type)); 2267 } 2268 } 2269 }; 2270 var promiseQueue = _this.sendWithProtocol(invocationDescriptor) 2271 .catch(function (e) { 2272 reject(e); 2273 // invocationId will always have a value for a non-blocking invocation 2274 delete _this.callbacks[invocationDescriptor.invocationId]; 2275 });
2276 _this.launchStreams(streams, promiseQueue); 2277 }); 2278 return p; 2279 }; 2280 /** Registers a handler that will be invoked when the hub method with the specified method name is invoked. 2281 * 2282 * @param {string} methodName The name of the hub method to define. 2283 * @param {Function} newMethod The handler that will be raised when the hub method is invoked. 2284 */ 2285 HubConnection.prototype.on = function (methodName, newMethod) { 2286 if (!methodName || !newMethod) { 2287 return; 2288 } 2289 methodName = methodName.toLowerCase(); 2290 if (!this.methods[methodName]) { 2291 this.methods[methodName] = []; 2292 } 2293 // Preventing adding the same handler multiple times. 2294 if (this.methods[methodName].indexOf(newMethod) !== -1) { 2295 return; 2296 } 2297 this.methods[methodName].push(newMethod); 2298 }; 2299 HubConnection.prototype.off = function (methodName, method) { 2300 if (!methodName) { 2301 return; 2302 } 2303 methodName = methodName.toLowerCase(); 2304 var handlers = this.methods[methodName]; 2305 if (!handlers) { 2306 return; 2307 } 2308 if (method) { 2309 var removeIdx = handlers.indexOf(method); 2310 if (removeIdx !== -1) { 2311 handlers.splice(removeIdx, 1); 2312 if (handlers.length === 0) { 2313 delete this.methods[methodName]; 2314 } 2315 } 2316 } 2317 else { 2318 delete this.methods[methodName]; 2319 } 2320 }; 2321 /** Registers a handler that will be invoked when the connection is closed. 2322 * 2323 * @param {Function} callback The handler that will be invoked when the connection is closed. Optionally receives a single argument containing the error that caused the connection to close (if any). 2324 */ 2325 HubConnection.prototype.onclose = function (callback) { 2326 if (callback) { 2327 this.closedCallbacks.push(callback); 2328 } 2329 }; 2330 /** Registers a handler that will be invoked when the connection starts reconnecting. 2331 * 2332 * @param {Function} callback The handler that will be invoked when the connection starts reconnecting. Optionally receives a single argument containing the error that caused the connection to start reconnecting (if any). 2333 */ 2334 HubConnection.prototype.onreconnecting = function (callback) { 2335 if (callback) { 2336 this.reconnectingCallbacks.push(callback); 2337 } 2338 }; 2339 /** Registers a handler that will be invoked when the connection successfully reconnects. 2340 * 2341 * @param {Function} callback The handler that will be invoked when the connection successfully reconnects. 2342 */ 2343 HubConnection.prototype.onreconnected = function (callback) { 2344 if (callback) { 2345 this.reconnectedCallbacks.push(callback); 2346 } 2347 }; 2348 HubConnection.prototype.processIncomingData = function (data) { 2349 this.cleanupTimeout(); 2350 if (!this.receivedHandshakeResponse) { 2351 data = this.processHandshakeResponse(data); 2352 this.receivedHandshakeResponse = true; 2353 } 2354 // Data may have all been read when processing handshake response 2355 if (data) { 2356 // Parse the messages 2357 var messages = this.protocol.parseMessages(data, this.logger); 2358 for (var _i = 0, messages_1 = messages; _i < messages_1.length; _i++) { 2359 var message = messages_1[_i]; 2360 switch (message.type) { 2361 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Invocation: 2362 this.invokeClientMethod(message); 2363 break; 2364 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].StreamItem: 2365 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion: 2366 var callback = this.callbacks[message.invocationId]; 2367 if (callback) { 2368 if (message.type === _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion) { 2369 delete this.callbacks[message.invocationId]; 2370 } 2371 callback(message); 2372 } 2373 break; 2374 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Ping: 2375 // Don't care about pings 2376 break; 2377 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Close: 2378 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Close message received from server."); 2379 var error = message.error ? new Error("Server returned an error on close: " + message.error) : undefined; 2380 if (message.allowReconnect === true) { 2381 // It feels wrong not to await connection.stop() here, but processIncomingData is called as part of an onreceive callback which is not async, 2382 // this is already the behavior for serverTimeout(), and HttpConnection.Stop() should catch and log all possible exceptions. 2383 // tslint:disable-next-line:no-floating-promises 2384 this.connection.stop(error); 2385 } 2386 else { 2387 // We cannot await stopInternal() here, but subsequent calls to stop() will await this if stopInternal() is still ongoing. 2388 this.stopPromise = this.stopInternal(error); 2389 } 2390 break; 2391 default: 2392 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Warning, "Invalid message type: " + message.type + "."); 2393 break; 2394 } 2395 } 2396 } 2397 this.resetTimeoutPeriod(); 2398 }; 2399 HubConnection.prototype.processHandshakeResponse = function (data) { 2400 var _a; 2401 var responseMessage; 2402 var remainingData; 2403 try { 2404 _a = this.handshakeProtocol.parseHandshakeResponse(data), remainingData = _a[0], responseMessage = _a[1]; 2405 } 2406 catch (e) { 2407 var message = "Error parsing handshake response: " + e; 2408 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, message); 2409 var error = new Error(message); 2410 this.handshakeRejecter(error); 2411 throw error; 2412 } 2413 if (responseMessage.error) { 2414 var message = "Server returned handshake error: " + responseMessage.error; 2415 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, message); 2416 var error = new Error(message); 2417 this.handshakeRejecter(error); 2418 throw error; 2419 } 2420 else { 2421 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Server handshake complete."); 2422 } 2423 this.handshakeResolver(); 2424 return remainingData; 2425 }; 2426 HubConnection.prototype.resetKeepAliveInterval = function () { 2427 var _this = this; 2428 this.cleanupPingTimer(); 2429 this.pingServerHandle = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () { 2430 var _a; 2431 return __generator(this, function (_b) { 2432 switch (_b.label) { 2433 case 0: 2434 if (!(this.connectionState === HubConnectionState.Connected)) return [3 /*break*/, 4]; 2435 _b.label = 1; 2436 case 1: 2437 _b.trys.push([1, 3, , 4]); 2438 return [4 /*yield*/, this.sendMessage(this.cachedPingMessage)]; 2439 case 2: 2440 _b.sent(); 2441 return [3 /*break*/, 4]; 2442 case 3: 2443 _a = _b.sent(); 2444 // We don't care about the error. It should be seen elsewhere in the client. 2445 // The connection is probably in a bad or closed state now, cleanup the timer so it stops triggering 2446 this.cleanupPingTimer(); 2447 return [3 /*break*/, 4]; 2448 case 4: return [2 /*return*/]; 2449 } 2450 }); 2451 }); }, this.keepAliveIntervalInMilliseconds); 2452 }; 2453 HubConnection.prototype.resetTimeoutPeriod = function () { 2454 var _this = this; 2455 if (!this.connection.features || !this.connection.features.inherentKeepAlive) { 2456 // Set the timeout timer 2457 this.timeoutHandle = setTimeout(function () { return _this.serverTimeout(); }, this.serverTimeoutInMilliseconds); 2458 } 2459 }; 2460 HubConnection.prototype.serverTimeout = function () { 2461 // The server hasn't talked to us in a while. It doesn't like us anymore ... :( 2462 // Terminate the connection, but we don't need to wait on the promise. This could trigger reconnecting. 2463 // tslint:disable-next-line:no-floating-promises 2464 this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server.")); 2465 }; 2466 HubConnection.prototype.invokeClientMethod = function (invocationMessage) { 2467 var _this = this; 2468 var methods = this.methods[invocationMessage.target.toLowerCase()]; 2469 if (methods) { 2470 try { 2471 methods.forEach(function (m) { return m.apply(_this, invocationMessage.arguments); }); 2472 } 2473 catch (e) { 2474 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "A callback for the method " + invocationMessage.target.toLowerCase() + " threw error '" + e + "'."); 2475 } 2476 if (invocationMessage.invocationId) { 2477 // This is not supported in v1. So we return an error to avoid blocking the server waiting for the response. 2478 var message = "Server requested a response, which is not supported in this version of the client."; 2479 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, message); 2480 // We don't want to wait on the stop itself. 2481 this.stopPromise = this.stopInternal(new Error(message)); 2482 } 2483 } 2484 else { 2485 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Warning, "No client method with the name '" + invocationMessage.target + "' found."); 2486 } 2487 }; 2488 HubConnection.prototype.connectionClosed = function (error) { 2489 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "HubConnection.connectionClosed(" + error + ") called while in state " + this.connectionState + "."); 2490 // Triggering this.handshakeRejecter is insufficient because it c
vendor: 1,338 bytes, lines 2490-2511
2490ould already be resolved without the continuation having run yet. 2491 this.stopDuringStartError = this.stopDuringStartError || error || new Error("The underlying connection was closed before the hub handshake could complete."); 2492 // If the handshake is in progress, start will be waiting for the handshake promise, so we complete it. 2493 // If it has already completed, this should just noop. 2494 if (this.handshakeResolver) { 2495 this.handshakeResolver(); 2496 } 2497 this.cancelCallbacksWithError(error || new Error("Invocation canceled due to the underlying connection being closed.")); 2498 this.cleanupTimeout(); 2499 this.cleanupPingTimer(); 2500 if (this.connectionState === HubConnectionState.Disconnecting) { 2501 this.completeClose(error); 2502 } 2503 else if (this.connectionState === HubConnectionState.Connected && this.reconnectPolicy) { 2504 // tslint:disable-next-line:no-floating-promises 2505 this.reconnect(error); 2506 } 2507 else if (this.connectionState === HubConnectionState.Connected) { 2508 this.completeClose(error); 2509 } 2510 // If none of the above if conditions were true were called the HubConnection must be in either: 2511 // 1. The Connecting state in which case the handshakeResolver will c
2511omplete it and stopDuringStartError will fail it. 2512 // 2. The Reconnecting state in which case the handshakeResolver will complete it and stopDuringStartError will fail the current reconnect attempt 2513 // and potentially continue the reconnect() loop. 2514 // 3. The Disconnected state in which case we're already done. 2515 }; 2516 HubConnection.prototype.completeClose = function (error) { 2517 var _this = this; 2518 if (this.connectionStarted) { 2519 this.connectionState = HubConnectionState.Disconnected; 2520 this.connectionStarted = false; 2521 try { 2522 this.closedCallbacks.forEach(function (c) { return c.apply(_this, [error]); }); 2523 } 2524 catch (e) { 2525 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "An onclose callback called with error '" + error + "' threw error '" + e + "'."); 2526 } 2527 } 2528 }; 2529 HubConnection.prototype.reconnect = function (error) { 2530 return __awaiter(this, void 0, void 0, function () { 2531 var reconnectStartTime, previousReconnectAttempts, retryError, nextRetryDelay, e_4; 2532 var _this = this; 2533 return __generator(this, function (_a) { 2534 switch (_a.label) { 2535 case 0: 2536 reconnectStartTime = Date.now(); 2537 previousReconnectAttempts = 0; 2538 retryError = error !== undefined ? error : new Error("Attempting to reconnect due to a unknown error."); 2539 nextRetryDelay = this.getNextRetryDelay(previousReconnectAttempts++, 0, retryError); 2540 if (nextRetryDelay === null) { 2541 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt."); 2542 this.completeClose(error); 2543 return [2 /*return*/]; 2544 } 2545 this.connectionState = HubConnectionState.Reconnecting; 2546 if (error) { 2547 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Connection reconnecting because of error '" + error + "'."); 2548 } 2549 else { 2550 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Connection reconnecting."); 2551 } 2552 if (this.onreconnecting) { 2553 try { 2554 this.reconnectingCallbacks.forEach(function (c) { return c.apply(_this, [error]); }); 2555 } 2556 catch (e) { 2557 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "An onreconnecting callback called with error '" + error + "' threw error '" + e + "'."); 2558 } 2559 // Exit early if an onreconnecting callback called connection.stop(). 2560 if (this.connectionState !== HubConnectionState.Reconnecting) { 2561 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Connection left the reconnecting state in onreconnecting callback. Done reconnecting."); 2562 return [2 /*return*/]; 2563 } 2564 } 2565 _a.label = 1; 2566 case 1: 2567 if (!(nextRetryDelay !== null)) return [3 /*break*/, 7]; 2568 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Reconnect attempt number " + previousReconnectAttempts + " will start in " + nextRetryDelay + " ms."); 2569 return [4 /*yield*/, new Promise(function (resolve) { 2570 _this.reconnectDelayHandle = setTimeout(resolve, nextRetryDelay); 2571 })]; 2572 case 2: 2573 _a.sent(); 2574 this.reconnectDelayHandle = undefined; 2575 if (this.connectionState !== HubConnectionState.Reconnecting) { 2576 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Connection left the reconnecting state during reconnect delay. Done reconnecting."); 2577 return [2 /*return*/]; 2578 } 2579 _a.label = 3; 2580 case 3: 2581 _a.trys.push([3, 5, , 6]); 2582 return [4 /*yield*/, this.startInternal()]; 2583 case 4: 2584 _a.sent(); 2585 this.connectionState = HubConnectionState.Connected; 2586 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "HubConnection reconnected successfully."); 2587 if (this.onreconnected) { 2588 try { 2589 this.reconnectedCallbacks.forEach(function (c) { return c.apply(_this, [_this.connection.connectionId]); }); 2590 } 2591 catch (e) { 2592 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "An onreconnected callback called with connectionId '" + this.connection.connectionId + "; threw error '" + e + "'."); 2593 } 2594 } 2595 return [2 /*return*/]; 2596 case 5: 2597 e_4 = _a.sent(); 2598 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Reconnect attempt failed because of error '" + e_4 + "'."); 2599 if (this.connectionState !== HubConnectionState.Reconnecting) { 2600 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Debug, "Connection left the reconnecting state during reconnect attempt. Done reconnecting."); 2601 return [2 /*return*/]; 2602 } 2603 retryError = e_4 instanceof Error ? e_4 : new Error(e_4.toString()); 2604 nextRetryDelay = this.getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError); 2605 return [3 /*break*/, 6]; 2606 case 6: return [3 /*break*/, 1]; 2607 case 7: 2608 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "Reconnect retries have been exhausted after " + (Date.now() - reconnectStartTime) + " ms and " + previousReconnectAttempts + " failed attempts. Connection disconnecting."); 2609 this.completeClose(); 2610 return [2 /*return*/]; 2611 } 2612 }); 2613 }); 2614 }; 2615 HubConnection.prototype.getNextRetryDelay = function (previousRetryCount, elapsedMilliseconds, retryReason) { 2616 try { 2617 return this.reconnectPolicy.nextRetryDelayInMilliseconds({ 2618 elapsedMilliseconds: elapsedMilliseconds, 2619 previousRetryCount: previousRetryCount, 2620 retryReason: retryReason, 2621 }); 2622 } 2623 catch (e) { 2624 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "IRetryPolicy.nextRetryDelayInMilliseconds(" + previousRetryCount + ", " + elapsedMilliseconds + ") threw error '" + e + "'."); 2625 return null; 2626 } 2627 }; 2628 HubConnection.prototype.cancelCallbacksWithError = function (error) { 2629 var callbacks = this.callbacks; 2630 this.callbacks = {}; 2631 Object.keys(callbacks) 2632 .forEach(function (key) { 2633 var callback = callbacks[key]; 2634 callback(null, error); 2635 }); 2636 }; 2637 HubConnection.prototype.cleanupPingTimer = function () { 2638 if (this.pingServerHandle) { 2639 clearTimeout(this.pingServerHandle); 2640 } 2641 }; 2642 HubConnection.prototype.cleanupTimeout = function () { 2643 if (this.timeoutHandle) { 2644 clearTimeout(this.timeoutHandle); 2645 } 2646 }; 2647 HubConnection.prototype.createInvocation = function (methodName, args, nonblocking, streamIds) { 2648 if (nonblocking) { 2649 return { 2650 arguments: args, 2651 streamIds: streamIds, 2652 target: methodName, 2653 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Invocation, 2654 }; 2655 } 2656 else { 2657 var invocationId = this.invocationId; 2658 this.invocationId++; 2659 return { 2660 arguments: args, 2661 invocationId: invocationId.toString(), 2662 streamIds: streamIds, 2663 target: methodName, 2664 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Invocation, 2665 }; 2666 } 2667 }; 2668 HubConnection.prototype.launchStreams = function (streams, promiseQueue) { 2669 var _this = this; 2670 if (streams.length === 0) { 2671 return; 2672 } 2673 // Synchronize stream data so they arrive in-order on the server 2674 if (!promiseQueue) { 2675 promiseQueue = Promise.resolve(); 2676 } 2677 var _loop_1 = function (streamId) { 2678 streams[streamId].subscribe({ 2679 complete: function () { 2680 promiseQueue = promiseQueue.then(function () { return _this.sendWithProtocol(_this.createCompletionMessage(streamId)); }); 2681 }, 2682 error: function (err) { 2683 var message; 2684 if (err instanceof Error) { 2685 message = err.message; 2686 } 2687 else if (err && err.toString) { 2688 message = err.toString(); 2689 } 2690 else { 2691 message = "Unknown error"; 2692 } 2693 promiseQueue = promiseQueue.then(function () { return _this.sendWithProtocol(_this.createCompletionMessage(streamId, message)); }); 2694 }, 2695 next: function (item) { 2696 promiseQueue = promiseQueue.then(function () { return _this.sendWithProtocol(_this.createStreamItemMessage(streamId, item)); }); 2697 }, 2698 }); 2699 }; 2700 // We want to iterate over the keys, since the keys are the stream ids 2701 // tslint:disable-next-line:forin 2702 for (var streamId in streams) { 2703 _loop_1(streamId); 2704 } 2705 }; 2706 HubConnection.prototype.replaceStreamingParams = function (args) { 2707 var streams = []; 2708 var streamIds = []; 2709 for (var i = 0; i < args.length; i++) { 2710 var argument = args[i];
vendor: 9,101 bytes, lines 2711-2893
2711 if (this.isObservable(argument)) { 2712 var streamId = this.invocationId; 2713 this.invocationId++; 2714 // Store the stream for later use 2715 streams[streamId] = argument; 2716 streamIds.push(streamId.toString()); 2717 // remove stream from args 2718 args.splice(i, 1); 2719 } 2720 } 2721 return [streams, streamIds]; 2722 }; 2723 HubConnection.prototype.isObservable = function (arg) { 2724 // This allows other stream implementations to just work (like rxjs) 2725 return arg && arg.subscribe && typeof arg.subscribe === "function"; 2726 }; 2727 HubConnection.prototype.createStreamInvocation = function (methodName, args, streamIds) { 2728 var invocationId = this.invocationId; 2729 this.invocationId++; 2730 return { 2731 arguments: args, 2732 invocationId: invocationId.toString(), 2733 streamIds: streamIds, 2734 target: methodName, 2735 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].StreamInvocation, 2736 }; 2737 }; 2738 HubConnection.prototype.createCancelInvocation = function (id) { 2739 return { 2740 invocationId: id, 2741 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].CancelInvocation, 2742 }; 2743 }; 2744 HubConnection.prototype.createStreamItemMessage = function (id, item) { 2745 return { 2746 invocationId: id, 2747 item: item, 2748 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].StreamItem, 2749 }; 2750 }; 2751 HubConnection.prototype.createCompletionMessage = function (id, error, result) { 2752 if (error) { 2753 return { 2754 error: error, 2755 invocationId: id, 2756 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion, 2757 }; 2758 } 2759 return { 2760 invocationId: id, 2761 result: result, 2762 type: _IHubProtocol__WEBPACK_IMPORTED_MODULE_1__["MessageType"].Completion, 2763 }; 2764 }; 2765 return HubConnection; 2766}()); 2767 2768 2769 2770/***/ }), 2771/* 11 */ 2772/***/ (function(module, __webpack_exports__, __webpack_require__) { 2773 2774"use strict"; 2775__webpack_require__.r(__webpack_exports__); 2776/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HandshakeProtocol", function() { return HandshakeProtocol; }); 2777/* harmony import */ var _TextMessageFormat__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(12); 2778/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13); 2779// Copyright (c) .NET Foundation. All rights reserved. 2780// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 2781 2782 2783/** @private */ 2784var HandshakeProtocol = /** @class */ (function () { 2785 function HandshakeProtocol() { 2786 } 2787 // Handshake request is always JSON 2788 HandshakeProtocol.prototype.writeHandshakeRequest = function (handshakeRequest) { 2789 return _TextMessageFormat__WEBPACK_IMPORTED_MODULE_0__["TextMessageFormat"].write(JSON.stringify(handshakeRequest)); 2790 }; 2791 HandshakeProtocol.prototype.parseHandshakeResponse = function (data) { 2792 var responseMessage; 2793 var messageData; 2794 var remainingData; 2795 if (Object(_Utils__WEBPACK_IMPORTED_MODULE_1__["isArrayBuffer"])(data) || (typeof Buffer !== "undefined" && data instanceof Buffer)) { 2796 // Format is binary but still need to read JSON text from handshake response 2797 var binaryData = new Uint8Array(data); 2798 var separatorIndex = binaryData.indexOf(_TextMessageFormat__WEBPACK_IMPORTED_MODULE_0__["TextMessageFormat"].RecordSeparatorCode); 2799 if (separatorIndex === -1) { 2800 throw new Error("Message is incomplete."); 2801 } 2802 // content before separator is handshake response 2803 // optional content after is additional messages 2804 var responseLength = separatorIndex + 1; 2805 messageData = String.fromCharCode.apply(null, binaryData.slice(0, responseLength)); 2806 remainingData = (binaryData.byteLength > responseLength) ? binaryData.slice(responseLength).buffer : null; 2807 } 2808 else { 2809 var textData = data; 2810 var separatorIndex = textData.indexOf(_TextMessageFormat__WEBPACK_IMPORTED_MODULE_0__["TextMessageFormat"].RecordSeparator); 2811 if (separatorIndex === -1) { 2812 throw new Error("Message is incomplete."); 2813 } 2814 // content before separator is handshake response 2815 // optional content after is additional messages 2816 var responseLength = separatorIndex + 1; 2817 messageData = textData.substring(0, responseLength); 2818 remainingData = (textData.length > responseLength) ? textData.substring(responseLength) : null; 2819 } 2820 // At this point we should have just the single handshake message 2821 var messages = _TextMessageFormat__WEBPACK_IMPORTED_MODULE_0__["TextMessageFormat"].parse(messageData); 2822 var response = JSON.parse(messages[0]); 2823 if (response.type) { 2824 throw new Error("Expected a handshake response from the server."); 2825 } 2826 responseMessage = response; 2827 // multiple messages could have arrived with handshake 2828 // return additional data to be parsed as usual, or null if all parsed 2829 return [remainingData, responseMessage]; 2830 }; 2831 return HandshakeProtocol; 2832}()); 2833 2834 2835 2836/***/ }), 2837/* 12 */ 2838/***/ (function(module, __webpack_exports__, __webpack_require__) { 2839 2840"use strict"; 2841__webpack_require__.r(__webpack_exports__); 2842/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TextMessageFormat", function() { return TextMessageFormat; }); 2843// Copyright (c) .NET Foundation. All rights reserved. 2844// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 2845// Not exported from index 2846/** @private */ 2847var TextMessageFormat = /** @class */ (function () { 2848 function TextMessageFormat() { 2849 } 2850 TextMessageFormat.write = function (output) { 2851 return "" + output + TextMessageFormat.RecordSeparator; 2852 }; 2853 TextMessageFormat.parse = function (input) { 2854 if (input[input.length - 1] !== TextMessageFormat.RecordSeparator) { 2855 throw new Error("Message is incomplete."); 2856 } 2857 var messages = input.split(TextMessageFormat.RecordSeparator); 2858 messages.pop(); 2859 return messages; 2860 }; 2861 TextMessageFormat.RecordSeparatorCode = 0x1e; 2862 TextMessageFormat.RecordSeparator = String.fromCharCode(TextMessageFormat.RecordSeparatorCode); 2863 return TextMessageFormat; 2864}()); 2865 2866 2867 2868/***/ }), 2869/* 13 */ 2870/***/ (function(module, __webpack_exports__, __webpack_require__) { 2871 2872"use strict"; 2873__webpack_require__.r(__webpack_exports__); 2874/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Arg", function() { return Arg; }); 2875/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Platform", function() { return Platform; }); 2876/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDataDetail", function() { return getDataDetail; }); 2877/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "formatArrayBuffer", function() { return formatArrayBuffer; }); 2878/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isArrayBuffer", function() { return isArrayBuffer; }); 2879/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sendMessage", function() { return sendMessage; }); 2880/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "createLogger", function() { return createLogger; }); 2881/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SubjectSubscription", function() { return SubjectSubscription; }); 2882/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ConsoleLogger", function() { return ConsoleLogger; }); 2883/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); 2884/* harmony import */ var _Loggers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14); 2885// Copyright (c) .NET Foundation. All rights reserved. 2886// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 2887var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 2888 return new (P || (P = Promise))(function (resolve, reject) { 2889 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 2890 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 2891 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 2892 step((generator = generator.apply(thisArg, _arguments || [])).next()); 2893 });
2894}; 2895var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 2896 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 2897 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 2898 function verb(n) { return function (v) { return step([n, v]); }; } 2899 function step(op) { 2900 if (f) throw new TypeError("Generator is already executing."); 2901 while (_) try { 2902 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 2903 if (y = 0, t) op = [op[0] & 2, t.value]; 2904 switch (op[0]) { 2905 case 0: case 1: t = op; break; 2906 case 4: _.label++; return { value: op[1], done: false }; 2907 case 5: _.label++; y = op[1]; op = [0]; continue; 2908 case 7: op = _.ops.pop(); _.trys.pop(); continue; 2909 default: 2910 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 2911 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 2912 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 2913 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 2914 if (t[2]) _.ops.pop(); 2915 _.trys.pop(); continue; 2916 } 2917 op = body.call(thisArg, _); 2918 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 2919 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 2920 } 2921}; 2922 2923 2924/** @private */ 2925var Arg = /** @class */ (function () { 2926 function Arg() { 2927 } 2928 Arg.isRequired = function (val, name) { 2929 if (val === null || val === undefined) { 2930 throw new Error("The '" + name + "' argument is required."); 2931 } 2932 }; 2933 Arg.isIn = function (val, values, name) { 2934 // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself. 2935 if (!(val in values)) { 2936 throw new Error("Unknown " + name + " value: " + val + "."); 2937 } 2938 }; 2939 return Arg; 2940}()); 2941 2942/** @private */ 2943var Platform = /** @class */ (function () { 2944 function Platform() { 2945 } 2946 Object.defineProperty(Platform, "isBrowser", { 2947 get: function () { 2948 return typeof window === "object"; 2949 }, 2950 enumerable: true, 2951 configurable: true 2952 }); 2953 Object.defineProperty(Platform, "isWebWorker", { 2954 get: function () { 2955 return typeof self === "object" && "importScripts" in self; 2956 }, 2957 enumerable: true, 2958 configurable: true 2959 }); 2960 Object.defineProperty(Platform, "isNode", { 2961 get: function () { 2962 return !this.isBrowser && !this.isWebWorker; 2963 }, 2964 enumerable: true, 2965 configurable: true 2966 }); 2967 return Platform; 2968}()); 2969 2970/** @private */ 2971function getDataDetail(data, includeContent) { 2972 var detail = ""; 2973 if (isArrayBuffer(data)) { 2974 detail = "Binary data of length " + data.byteLength; 2975 if (includeContent) { 2976 detail += ". Content: '" + formatArrayBuffer(data) + "'"; 2977 } 2978 } 2979 else if (typeof data === "string") { 2980 detail = "String data of length " + data.length; 2981 if (includeContent) { 2982 detail += ". Content: '" + data + "'"; 2983 } 2984 } 2985 return detail; 2986} 2987/** @private */ 2988function formatArrayBuffer(data) { 2989 var view = new Uint8Array(data); 2990 // Uint8Array.map only supports returning another Uint8Array? 2991 var str = ""; 2992 view.forEach(function (num) { 2993 var pad = num < 16 ? "0" : ""; 2994 str += "0x" + pad + num.toString(16) + " "; 2995 }); 2996 // Trim of trailing space. 2997 return str.substr(0, str.length - 1); 2998} 2999// Also in signalr-protocol-msgpack/Utils.ts 3000/** @private */ 3001function isArrayBuffer(val) { 3002 return val && typeof ArrayBuffer !== "undefined" && 3003 (val instanceof ArrayBuffer || 3004 // Sometimes we get an ArrayBuffer that doesn't satisfy instanceof 3005 (val.constructor && val.constructor.name === "ArrayBuffer")); 3006} 3007/** @private */ 3008function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent) { 3009 return __awaiter(this, void 0, void 0, function () { 3010 var _a, headers, token, responseType, response; 3011 return __generator(this, function (_b) { 3012 switch (_b.label) { 3013 case 0: 3014 if (!accessTokenFactory) return [3 /*break*/, 2]; 3015 return [4 /*yield*/, accessTokenFactory()]; 3016 case 1: 3017 token = _b.sent(); 3018 if (token) { 3019 headers = (_a = {}, 3020 _a["Authorization"] = "Bearer " + token, 3021 _a); 3022 } 3023 _b.label = 2; 3024 case 2: 3025 logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(" + transportName + " transport) sending data. " + getDataDetail(content, logMessageContent) + "."); 3026 responseType = isArrayBuffer(content) ? "arraybuffer" : "text"; 3027 return [4 /*yield*/, httpClient.post(url, { 3028 content: content, 3029 headers: headers, 3030 responseType: responseType, 3031 })]; 3032 case 3: 3033 response = _b.sent(); 3034 logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(" + transportName + " transport) request complete. Response status: " + response.statusCode + "."); 3035 return [2 /*return*/]; 3036 } 3037 }); 3038 });
vendor: 10,882 bytes, lines 3039-3278
3039} 3040/** @private */ 3041function createLogger(logger) { 3042 if (logger === undefined) { 3043 return new ConsoleLogger(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Information); 3044 } 3045 if (logger === null) { 3046 return _Loggers__WEBPACK_IMPORTED_MODULE_1__["NullLogger"].instance; 3047 } 3048 if (logger.log) { 3049 return logger; 3050 } 3051 return new ConsoleLogger(logger); 3052} 3053/** @private */ 3054var SubjectSubscription = /** @class */ (function () { 3055 function SubjectSubscription(subject, observer) { 3056 this.subject = subject; 3057 this.observer = observer; 3058 } 3059 SubjectSubscription.prototype.dispose = function () { 3060 var index = this.subject.observers.indexOf(this.observer); 3061 if (index > -1) { 3062 this.subject.observers.splice(index, 1); 3063 } 3064 if (this.subject.observers.length === 0 && this.subject.cancelCallback) { 3065 this.subject.cancelCallback().catch(function (_) { }); 3066 } 3067 }; 3068 return SubjectSubscription; 3069}()); 3070 3071/** @private */ 3072var ConsoleLogger = /** @class */ (function () { 3073 function ConsoleLogger(minimumLogLevel) { 3074 this.minimumLogLevel = minimumLogLevel; 3075 this.outputConsole = console; 3076 } 3077 ConsoleLogger.prototype.log = function (logLevel, message) { 3078 if (logLevel >= this.minimumLogLevel) { 3079 switch (logLevel) { 3080 case _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Critical: 3081 case _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Error: 3082 this.outputConsole.error("[" + new Date().toISOString() + "] " + _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"][logLevel] + ": " + message); 3083 break; 3084 case _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Warning: 3085 this.outputConsole.warn("[" + new Date().toISOString() + "] " + _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"][logLevel] + ": " + message); 3086 break; 3087 case _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Information: 3088 this.outputConsole.info("[" + new Date().toISOString() + "] " + _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"][logLevel] + ": " + message); 3089 break; 3090 default: 3091 // console.debug only goes to attached debuggers in Node, so we use console.log for Trace and Debug 3092 this.outputConsole.log("[" + new Date().toISOString() + "] " + _ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"][logLevel] + ": " + message); 3093 break; 3094 } 3095 } 3096 }; 3097 return ConsoleLogger; 3098}()); 3099 3100 3101 3102/***/ }), 3103/* 14 */ 3104/***/ (function(module, __webpack_exports__, __webpack_require__) { 3105 3106"use strict"; 3107__webpack_require__.r(__webpack_exports__); 3108/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NullLogger", function() { return NullLogger; }); 3109// Copyright (c) .NET Foundation. All rights reserved. 3110// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3111/** A logger that does nothing when log messages are sent to it. */ 3112var NullLogger = /** @class */ (function () { 3113 function NullLogger() { 3114 } 3115 /** @inheritDoc */ 3116 // tslint:disable-next-line 3117 NullLogger.prototype.log = function (_logLevel, _message) { 3118 }; 3119 /** The singleton instance of the {@link @microsoft/signalr.NullLogger}. */ 3120 NullLogger.instance = new NullLogger(); 3121 return NullLogger; 3122}()); 3123 3124 3125 3126/***/ }), 3127/* 15 */ 3128/***/ (function(module, __webpack_exports__, __webpack_require__) { 3129 3130"use strict"; 3131__webpack_require__.r(__webpack_exports__); 3132/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MessageType", function() { return MessageType; }); 3133// Copyright (c) .NET Foundation. All rights reserved. 3134// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3135/** Defines the type of a Hub Message. */ 3136var MessageType; 3137(function (MessageType) { 3138 /** Indicates the message is an Invocation message and implements the {@link @microsoft/signalr.InvocationMessage} interface. */ 3139 MessageType[MessageType["Invocation"] = 1] = "Invocation"; 3140 /** Indicates the message is a StreamItem message and implements the {@link @microsoft/signalr.StreamItemMessage} interface. */ 3141 MessageType[MessageType["StreamItem"] = 2] = "StreamItem"; 3142 /** Indicates the message is a Completion message and implements the {@link @microsoft/signalr.CompletionMessage} interface. */ 3143 MessageType[MessageType["Completion"] = 3] = "Completion"; 3144 /** Indicates the message is a Stream Invocation message and implements the {@link @microsoft/signalr.StreamInvocationMessage} interface. */ 3145 MessageType[MessageType["StreamInvocation"] = 4] = "StreamInvocation"; 3146 /** Indicates the message is a Cancel Invocation message and implements the {@link @microsoft/signalr.CancelInvocationMessage} interface. */ 3147 MessageType[MessageType["CancelInvocation"] = 5] = "CancelInvocation"; 3148 /** Indicates the message is a Ping message and implements the {@link @microsoft/signalr.PingMessage} interface. */ 3149 MessageType[MessageType["Ping"] = 6] = "Ping"; 3150 /** Indicates the message is a Close message and implements the {@link @microsoft/signalr.CloseMessage} interface. */ 3151 MessageType[MessageType["Close"] = 7] = "Close"; 3152})(MessageType || (MessageType = {})); 3153 3154 3155/***/ }), 3156/* 16 */ 3157/***/ (function(module, __webpack_exports__, __webpack_require__) { 3158 3159"use strict"; 3160__webpack_require__.r(__webpack_exports__); 3161/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Subject", function() { return Subject; }); 3162/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13); 3163// Copyright (c) .NET Foundation. All rights reserved. 3164// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3165 3166/** Stream implementation to stream items to the server. */ 3167var Subject = /** @class */ (function () { 3168 function Subject() { 3169 this.observers = []; 3170 } 3171 Subject.prototype.next = function (item) { 3172 for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { 3173 var observer = _a[_i]; 3174 observer.next(item); 3175 } 3176 }; 3177 Subject.prototype.error = function (err) { 3178 for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { 3179 var observer = _a[_i]; 3180 if (observer.error) { 3181 observer.error(err); 3182 } 3183 } 3184 }; 3185 Subject.prototype.complete = function () { 3186 for (var _i = 0, _a = this.observers; _i < _a.length; _i++) { 3187 var observer = _a[_i]; 3188 if (observer.complete) { 3189 observer.complete(); 3190 } 3191 } 3192 }; 3193 Subject.prototype.subscribe = function (observer) { 3194 this.observers.push(observer); 3195 return new _Utils__WEBPACK_IMPORTED_MODULE_0__["SubjectSubscription"](this, observer); 3196 }; 3197 return Subject; 3198}()); 3199 3200 3201 3202/***/ }), 3203/* 17 */ 3204/***/ (function(module, __webpack_exports__, __webpack_require__) { 3205 3206"use strict"; 3207__webpack_require__.r(__webpack_exports__); 3208/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HubConnectionBuilder", function() { return HubConnectionBuilder; }); 3209/* harmony import */ var _DefaultReconnectPolicy__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18); 3210/* harmony import */ var _HttpConnection__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(19); 3211/* harmony import */ var _HubConnection__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10); 3212/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9); 3213/* harmony import */ var _JsonHubProtocol__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(25); 3214/* harmony import */ var _Loggers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(14); 3215/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(13); 3216// Copyright (c) .NET Foundation. All rights reserved. 3217// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3218var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { 3219 for (var s, i = 1, n = arguments.length; i < n; i++) { 3220 s = arguments[i]; 3221 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) 3222 t[p] = s[p]; 3223 } 3224 return t; 3225}; 3226 3227 3228 3229 3230 3231 3232 3233// tslint:disable:object-literal-sort-keys 3234var LogLevelNameMapping = { 3235 trace: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Trace, 3236 debug: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Debug, 3237 info: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Information, 3238 information: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Information, 3239 warn: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Warning, 3240 warning: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Warning, 3241 error: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Error, 3242 critical: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].Critical, 3243 none: _ILogger__WEBPACK_IMPORTED_MODULE_3__["LogLevel"].None, 3244}; 3245function parseLogLevel(name) { 3246 // Case-insensitive matching via lower-casing 3247 // Yes, I know case-folding is a complicated problem in Unicode, but we only support 3248 // the ASCII strings defined in LogLevelNameMapping anyway, so it's fine -anurse. 3249 var mapping = LogLevelNameMapping[name.toLowerCase()]; 3250 if (typeof mapping !== "undefined") { 3251 return mapping; 3252 } 3253 else { 3254 throw new Error("Unknown log level: " + name); 3255 } 3256} 3257/** A builder for configuring {@link @microsoft/signalr.HubConnection} instances. */ 3258var HubConnectionBuilder = /** @class */ (function () { 3259 function HubConnectionBuilder() { 3260 } 3261 HubConnectionBuilder.prototype.configureLogging = function (logging) { 3262 _Utils__WEBPACK_IMPORTED_MODULE_6__["Arg"].isRequired(logging, "logging"); 3263 if (isLogger(logging)) { 3264 this.logger = logging; 3265 } 3266 else if (typeof logging === "string") { 3267 var logLevel = parseLogLevel(logging); 3268 this.logger = new _Utils__WEBPACK_IMPORTED_MODULE_6__["ConsoleLogger"](logLevel); 3269 } 3270 else { 3271 this.logger = new _Utils__WEBPACK_IMPORTED_MODULE_6__["ConsoleLogger"](logging); 3272 } 3273 return this; 3274 }; 3275 HubConnectionBuilder.prototype.withUrl = function (url, transportTypeOrOptions) { 3276 _Utils__WEBPACK_IMPORTED_MODULE_6__["Arg"].isRequired(url, "url"); 3277 this.url = url; 3278 // Flow-typing knows where it's at. Since HttpTransportType is a
3278number and IHttpConnectionOptions is guaranteed 3279 // to be an object, we know (as does TypeScript) this comparison is all we need to figure out which overload was called. 3280 if (typeof transportTypeOrOptions === "object") { 3281 this.httpConnectionOptions = __assign({}, this.httpConnectionOptions, transportTypeOrOptions); 3282 } 3283 else { 3284 this.httpConnectionOptions = __assign({}, this.httpConnectionOptions, { transport: transportTypeOrOptions }); 3285 } 3286 return this; 3287 }; 3288 /** Configures the {@link @microsoft/signalr.HubConnection} to use the specified Hub Protocol. 3289 * 3290 * @param {IHubProtocol} protocol The {@link @microsoft/signalr.IHubProtocol} implementation to use. 3291 */ 3292 HubConnectionBuilder.prototype.withHubProtocol = function (protocol) { 3293 _Utils__WEBPACK_IMPORTED_MODULE_6__["Arg"].isRequired(protocol, "protocol"); 3294 this.protocol = protocol; 3295 return this; 3296 }; 3297 HubConnectionBuilder.prototype.withAutomaticReconnect = function (retryDelaysOrReconnectPolicy) { 3298 if (this.reconnectPolicy) { 3299 throw new Error("A reconnectPolicy has already been set."); 3300 } 3301 if (!retryDelaysOrReconnectPolicy) { 3302 this.reconnectPolicy = new _DefaultReconnectPolicy__WEBPACK_IMPORTED_MODULE_0__["DefaultReconnectPolicy"](); 3303 } 3304 else if (Array.isArray(retryDelaysOrReconnectPolicy)) { 3305 this.reconnectPolicy = new _DefaultReconnectPolicy__WEBPACK_IMPORTED_MODULE_0__["DefaultReconnectPolicy"](retryDelaysOrReconnectPolicy); 3306 } 3307 else { 3308 this.reconnectPolicy = retryDelaysOrReconnectPolicy; 3309 } 3310 return this; 3311 }; 3312 /** Creates a {@link @microsoft/signalr.HubConnection} from the configuration options specified in this builder. 3313 * 3314 * @returns {HubConnection} The configured {@link @microsoft/signalr.HubConnection}. 3315 */ 3316 HubConnectionBuilder.prototype.build = function () { 3317 // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one 3318 // provided to configureLogger 3319 var httpConnectionOptions = this.httpConnectionOptions || {}; 3320 // If it's 'null', the user **explicitly** asked for null, don't mess with it. 3321 if (httpConnectionOptions.logger === undefined) { 3322 // If our logger is undefined or null, that's OK, the HttpConnection constructor will handle it. 3323 httpConnectionOptions.logger = this.logger; 3324 } 3325 // Now create the connection 3326 if (!this.url) { 3327 throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection."); 3328 } 3329 var connection = new _HttpConnection__WEBPACK_IMPORTED_MODULE_1__["HttpConnection"](this.url, httpConnectionOptions); 3330 return _HubConnection__WEBPACK_IMPORTED_MODULE_2__["HubConnection"].create(connection, this.logger || _Loggers__WEBPACK_IMPORTED_MODULE_5__["NullLogger"].instance, this.protocol || new _JsonHubProtocol__WEBPACK_IMPORTED_MODULE_4__["JsonHubProtocol"](), this.reconnectPolicy); 3331 }; 3332 return HubConnectionBuilder; 3333}()); 3334 3335function isLogger(logger) { 3336 return logger.log !== undefined; 3337} 3338 3339 3340/***/ }), 3341/* 18 */ 3342/***/ (function(module, __webpack_exports__, __webpack_require__) { 3343 3344"use strict"; 3345__webpack_require__.r(__webpack_exports__); 3346/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DefaultReconnectPolicy", function() { return DefaultReconnectPolicy; }); 3347// Copyright (c) .NET Foundation. All rights reserved. 3348// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3349// 0, 2, 10, 30 second delays before reconnect attempts. 3350var DEFAULT_RETRY_DELAYS_IN_MILLISECONDS = [0, 2000, 10000, 30000, null]; 3351/** @private */ 3352var DefaultReconnectPolicy = /** @class */ (function () { 3353 function DefaultReconnectPolicy(retryDelays) { 3354 this.retryDelays = retryDelays !== undefined ? retryDelays.concat([null]) : DEFAULT_RETRY_DELAYS_IN_MILLISECONDS; 3355 } 3356 DefaultReconnectPolicy.prototype.nextRetryDelayInMilliseconds = function (retr
3356yContext) { 3357 return this.retryDelays[retryContext.previousRetryCount]; 3358 }; 3359 return DefaultReconnectPolicy; 3360}()); 3361 3362 3363 3364/***/ }), 3365/* 19 */ 3366/***/ (function(module, __webpack_exports__, __webpack_require__) { 3367 3368"use strict"; 3369__webpack_require__.r(__webpack_exports__); 3370/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HttpConnection", function() { return HttpConnection; }); 3371/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TransportSendQueue", function() { return TransportSendQueue; }); 3372/* harmony import */ var _DefaultHttpClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6); 3373/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9); 3374/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20); 3375/* harmony import */ var _LongPollingTransport__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(21); 3376/* harmony import */ var _ServerSentEventsTransport__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(23); 3377/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(13); 3378/* harmony import */ var _WebSocketTransport__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(24); 3379// Copyright (c) .NET Foundation. All rights reserved. 3380// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3381var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 3382 return new (P || (P = Promise))(function (resolve, reject) { 3383 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 3384 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 3385 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 3386 step((generator = generator.apply(thisArg, _arguments || [])).next()); 3387 }); 3388}; 3389var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 3390 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 3391 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 3392 function verb(n) { return function (v) { return step([n, v]); }; } 3393 function step(op) { 3394 if (f) throw new TypeError("Generator is already executing."); 3395 while (_) try { 3396 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 3397 if (y = 0, t) op = [op[0] & 2, t.value]; 3398 switch (op[0]) { 3399 case 0: case 1: t = op; break; 3400 case 4: _.label++; return { value: op[1], done: false }; 3401 case 5: _.label++; y = op[1]; op = [0]; continue; 3402 case 7: op = _.ops.pop(); _.trys.pop(); continue; 3403 default: 3404 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 3405 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 3406 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 3407 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 3408 if (t[2]) _.ops.pop(); 3409 _.trys.pop(); continue; 3410 } 3411 op = body.call(thisArg, _); 3412 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 3413 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 3414 } 3415}; 3416 3417 3418 3419 3420 3421 3422 3423var MAX_REDIRECTS = 100; 3424var WebSocketModule = null; 3425var EventSourceModule = null; 3426if (_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isNode && "function" !== "undefined") { 3427 // In order to ignore the dynamic require in webpack builds we need to do this magic 3428 // @ts-ignore: TS doesn't know about these names 3429 var requireFunc = true ? require : undefined; 3430 WebSocketModule = requireFunc("ws"); 3431 EventSourceModule = requireFunc("eventsource"); 3432} 3433/** @private */ 3434var HttpConnection = /** @class */ (function () { 3435 function HttpConnection(url, options) { 3436 if (options === void 0) { options = {}; } 3437 this.features = {}; 3438 this.negotiateVersion = 1; 3439 _Utils__WEBPACK_IMPORTED_MODULE_5__["Arg"].isRequired(url, "url"); 3440 this.logger = Object(_Utils__WEBPACK_IMPORTED_MODULE_5__["createLogger"])(options.logger); 3441 this.baseUrl = this.resolveUrl(url); 3442 options = options || {}; 3443 options.logMessageContent = options.logMessageContent || false; 3444 if (!_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isNode && typeof WebSocket !== "undefined" && !options.WebSocket) { 3445 options.WebSocket = WebSocket; 3446 } 3447 else if (_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isNode && !
3447options.WebSocket) { 3448 if (WebSocketModule) { 3449 options.WebSocket = WebSocketModule; 3450 } 3451 } 3452 if (!_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isNode && typeof EventSource !== "undefined" && !options.EventSource) { 3453 options.EventSource = EventSource; 3454 } 3455 else if (_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isNode && !options.EventSource) { 3456 if (typeof EventSourceModule !== "undefined") { 3457 options.EventSource = EventSourceModule; 3458 } 3459 } 3460 this.httpClient = options.httpClient || new _DefaultHttpClient__WEBPACK_IMPORTED_MODULE_0__["DefaultHttpClient"](this.logger); 3461 this.connectionState = "Disconnected" /* Disconnected */; 3462 this.connectionStarted = false; 3463 this.options = options; 3464 this.onreceive = null; 3465 this.onclose = null; 3466 } 3467 HttpConnection.prototype.start = function (transferFormat) { 3468 return __awaiter(this, void 0, void 0, function () { 3469 var message, message; 3470 return __generator(this, function (_a) { 3471 switch (_a.label) { 3472 case 0: 3473 transferFormat = transferFormat || _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"].Binary; 3474 _Utils__WEBPACK_IMPORTED_MODULE_5__["Arg"].isIn(transferFormat, _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"], "transferFormat"); 3475 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Starting connection with transfer format '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"][transferFormat] + "'."); 3476 if (this.connectionState !== "Disconnected" /* Disconnected */) { 3477 return [2 /*return*/, Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."))]; 3478 } 3479 this.connectionState = "Connecting " /* Connecting */; 3480 this.startInternalPromise = this.startInternal(transferFormat); 3481 return [4 /*yield*/, this.startInternalPromise]; 3482 case 1: 3483 _a.sent(); 3484 if (!(this.connectionState === "Disconnecting" /* Disconnecting */)) return [3 /*break*/, 3]; 3485 message = "Failed to start the HttpConnection before stop() was called."; 3486 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, message); 3487 // We cannot await stopPromise inside startInternal since stopInternal awaits the startInternalPromise. 3488 return [4 /*yield*/, this.stopPromise]; 3489 case 2: 3490 // We cannot await stopPromise inside startInternal since stopInternal awaits the startInternalPromise. 3491 _a.sent(); 3492 return [2 /*return*/, Promise.reject(new Error(message))];
3493 case 3: 3494 if (this.connectionState !== "Connected" /* Connected */) { 3495 message = "HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!"; 3496 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, message); 3497 return [2 /*return*/, Promise.reject(new Error(message))]; 3498 } 3499 _a.label = 4; 3500 case 4: 3501 this.connectionStarted = true; 3502 return [2 /*return*/]; 3503 } 3504 }); 3505 }); 3506 }; 3507 HttpConnection.prototype.send = function (data) { 3508 if (this.connectionState !== "Connected" /* Connected */) { 3509 return Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State.")); 3510 } 3511 if (!this.sendQueue) { 3512 this.sendQueue = new TransportSendQueue(this.transport); 3513 } 3514 // Transport will not be null if state is connected 3515 return this.sendQueue.send(data); 3516 }; 3517 HttpConnection.prototype.stop = function (error) { 3518 return __awaiter(this, void 0, void 0, function () { 3519 var _this = this; 3520 return __generator(this, function (_a) { 3521 switch (_a.label) { 3522 case 0: 3523 if (this.connectionState === "Disconnected" /* Disconnected */) { 3524 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Call to HttpConnection.stop(" + error + ") ignored because the connection is already in the disconnected state."); 3525 return [2 /*return*/, Promise.resolve()]; 3526 } 3527 if (this.connectionState === "Disconnecting" /* Disconnecting */) { 3528 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Call to HttpConnection.stop(" + error + ") ignored because the connection is already in the disconnecting state."); 3529 return [2 /*return*/, this.stopPromise]; 3530 } 3531 this.connectionState = "Disconnecting" /* Disconnecting */; 3532 this.stopPromise = new Promise(function (resolve) { 3533 // Don't complete stop() until stopConnection() completes. 3534 _this.stopPromiseResolver = resolve; 3535 }); 3536 // stopInternal should never throw so just observe it. 3537 return [4 /*yield*/, this.stopInternal(error)]; 3538 case 1: 3539 // stopInternal should never throw so just observe it. 3540 _a.sent(); 3541 return [4 /*yield*/, this.stopPromise]; 3542 case 2: 3543 _a.sent(); 3544 return [2 /*return*/]; 3545 } 3546 }); 3547 }); 3548 }; 3549 HttpConnection.prototype.stopInternal = function (error) { 3550 return __awaiter(this, void 0, void 0, function () { 3551 var e_1, e_2; 3552 return __generator(this, function (_a) { 3553 switch (_a.label) { 3554 case 0: 3555 // Set error as soon as possible otherwise there is a race between 3556 // the transport closing and providing an error and the error from a close message 3557 // We would prefer the close message error. 3558 this.stopError = error; 3559 _a.label = 1; 3560 case 1: 3561 _a.trys.push([1, 3, , 4]); 3562 return [4 /*yield*/, this.startInternalPromise]; 3563 case 2: 3564 _a.sent(); 3565 return [3 /*break*/, 4]; 3566 case 3: 3567 e_1 = _a.sent(); 3568 return [3 /*break*/, 4]; 3569 case 4: 3570 if (!this.transport) return [3 /*break*/, 9]; 3571 _a.label = 5; 3572 case 5: 3573 _a.trys.push([5, 7, , 8]); 3574 return [4 /*yield*/, this.transport.stop()]; 3575 case 6: 3576 _a.sent(); 3577 return [3 /*break*/, 8]; 3578 case 7: 3579 e_2 = _a.sent(); 3580 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "HttpConnection.transport.stop() threw error '" + e_2 + "'."); 3581 this.stopConnection(); 3582 return [3 /*break*/, 8]; 3583 case 8: 3584 this.transport = undefined; 3585 return [3 /*break*/, 10]; 3586 case 9: 3587 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "HttpConnection.transport is undefined in HttpConnection.stop() because start() failed."); 3588 this.stopConnection(); 3589 _a.label = 10; 3590 case 10: return [2 /*return*/]; 3591 } 3592 }); 3593 }); 3594 }; 3595 HttpConnection.prototype.startInternal = function (transferFormat) { 3596 return __awaiter(this, void 0, void 0, function () { 3597 var url, negotiateResponse, redirects, _loop_1, this_1, e_3; 3598 return __generator(this, function (_a) { 3599 switch (_a.label) { 3600 case 0: 3601 url = this.baseUrl; 3602 this.accessTokenFactory = this.options.accessTokenFactory;
3603 _a.label = 1; 3604 case 1: 3605 _a.trys.push([1, 12, , 13]); 3606 if (!this.options.skipNegotiation) return [3 /*break*/, 5]; 3607 if (!(this.options.transport === _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].WebSockets)) return [3 /*break*/, 3]; 3608 // No need to add a connection ID in this case 3609 this.transport = this.constructTransport(_ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].WebSockets); 3610 // We should just call connect directly in this case. 3611 // No fallback or negotiate in this case. 3612 return [4 /*yield*/, this.startTransport(url, transferFormat)]; 3613 case 2: 3614 // We should just call connect directly in this case. 3615 // No fallback or negotiate in this case. 3616 _a.sent(); 3617 return [3 /*break*/, 4]; 3618 case 3: throw new Error("Negotiation can only be skipped when using the WebSocket transport directly."); 3619 case 4: return [3 /*break*/, 11]; 3620 case 5: 3621 negotiateResponse = null; 3622 redirects = 0; 3623 _loop_1 = function () { 3624 var accessToken_1; 3625 return __generator(this, function (_a) { 3626 switch (_a.label) { 3627 case 0: return [4 /*yield*/, this_1.getNegotiationResponse(url)]; 3628 case 1: 3629 negotiateResponse = _a.sent(); 3630 // the user tries to stop the connection when it is being started 3631 if (this_1.connectionState === "Disconnecting" /* Disconnecting */ || this_1.connectionState === "Disconnected" /* Disconnected */) { 3632 throw new Error("The connection was stopped during negotiation."); 3633 } 3634 if (negotiateResponse.error) { 3635 throw new Error(negotiateResponse.error); 3636 } 3637 if (negotiateResponse.ProtocolVersion) { 3638 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."); 3639 } 3640 if (negotiateResponse.url) { 3641 url = negotiateResponse.url; 3642 } 3643 if (negotiateResponse.accessToken) { 3644 accessToken_1 = negotiateResponse.accessToken; 3645 this_1.accessTokenFactory = function () { return accessToken_1; }; 3646 } 3647 redirects++; 3648 return [2 /*return*/]; 3649 } 3650 }); 3651 }; 3652 this_1 = this; 3653 _a.label = 6; 3654 case 6: return [5 /*yield**/, _loop_1()]; 3655 case 7: 3656 _a.sent(); 3657 _a.label = 8; 3658 case 8: 3659 if (negotiateResponse.url && redirects < MAX_REDIRECTS) return [3 /*break*/, 6]; 3660 _a.label = 9; 3661 case 9: 3662 if (redirects === MAX_REDIRECTS && negotiateResponse.url) { 3663 throw new Error("Negotiate redirection limit exceeded."); 3664 } 3665 return [4 /*yield*/, this.createTransport(url, this.options.transport, negotiateResponse, transferFormat)]; 3666 case 10: 3667 _a.sent(); 3668 _a.label = 11; 3669 case 11: 3670 if (this.transport instanceof _LongPollingTransport__WEBPACK_IMPORTED_MODULE_3__["LongPollingTransport"]) { 3671 this.features.inherentKeepAlive = true; 3672 } 3673 if (this.connectionState === "Connecting " /* Connecting */) { 3674 // Ensure the connection transitions to the connected state prior to completing this.startInternalPromise. 3675 // start() will handle the case when stop was called and startInternal exits still in the disconnecting state. 3676 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "The HttpConnection connected successfully."); 3677 this.connectionState = "Connected" /* Connected */; 3678 } 3679 return [3 /*break*/, 13]; 3680 case 12: 3681 e_3 = _a.sent(); 3682 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "Failed to start the connection: " + e_3); 3683 this.connectionState = "Disconnected" /* Disconnected */; 3684 this.transport = undefined; 3685 return [2 /*return*/, Promise.reject(e_3)]; 3686 case 13: return [2 /*return*/]; 3687 } 3688 }); 3689 }); 3690 }; 3691 HttpConnection.prototype.getNegotiationResponse = function (url) { 3692 return __awaiter(this, void 0, void 0, function () { 3693 var _a, headers, token, negotiateUrl, response, negotiateResponse, e_4; 3694 return __generator(this, function (_b) { 3695 switch (_b.label) { 3696 case 0: 3697 if (!this.accessTokenFactory) return [3 /*break*/, 2]; 3698 return [4 /*yield*/, this.accessTokenFactory()]; 3699 case 1: 3700 token = _b.sent(); 3701 if (token) { 3702 headers = (_a = {}, 3703 _a["Authorization"] = "Bearer " + token, 3704 _a); 3705 } 3706 _b.label = 2; 3707 case 2: 3708 negotiateUrl = this.resolveNegotiateUrl(url); 3709 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Sending negotiation request: " + negotiateUrl + "."); 3710 _b.label = 3; 3711 case 3: 3712 _b.trys.push([3, 5, , 6]); 3713 return [4 /*yield*/, this.httpClient.post(negotiateUrl, { 3714 content: "", 3715 headers: headers, 3716 })]; 3717 case 4: 3718 response = _b.sent(); 3719 if (response.statusCode !== 200) { 3720 return [2 /*return*/, Promise.reject(new Error("Unexpected status code returned from negotiate " + response.statusCode))]; 3721 } 3722 negotiateResponse = JSON.parse(response.content); 3723 if (!negotiateResponse.negotiateVersion || negotiateResponse.negotiateVersion < 1) { 3724 // Negotiate version 0 doesn't use connectionToken 3725 // So we set it equal to connectionId so all our logic can use connectionToken without being aware of the negotiate version 3726 negotiateResponse.connectionToken = negotiateResponse.connectionId; 3727 } 3728 return [2 /*return*/, negotiateResponse]; 3729 case 5: 3730 e_4 = _b.sent(); 3731 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "Failed to complete negotiation with the server: " + e_4); 3732 return [2 /*return*/, Promise.reject(e_4)]; 3733 case 6: return [2 /*return*/]; 3734 } 3735 }); 3736 }); 3737 }; 3738 HttpConnection.prototype.createConnectUrl = function (url, connectionToken) { 3739 if (!connectionToken) { 3740 return url; 3741 } 3742 return url + (url.indexOf("?") === -1 ? "?" : "&") + ("id=" + connectionToken); 3743 }; 3744 HttpConnection.prototype.createTransport = function (url, requestedTransport, negotiateResponse, requestedTransferFormat) { 3745 return __awaiter(this, void 0, void 0, function () { 3746 var connectUrl, transportExceptions, transports, negotiate, _i, transports_1, endpoint, transportOrError, ex_1, ex_2, message; 3747 return __generator(this, function (_a) { 3748 switch (_a.label) { 3749 case 0: 3750 connectUrl = this.createConnectUrl(url, negotiateResponse.connectionToken); 3751 if (!this.isITransport(requestedTransport)) return [3 /*break*/, 2]; 3752 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Connection was provided an instance of ITransport, using that directly."); 3753 this.transport = requestedTransport; 3754 return [4 /*yield*/, this.startTransport(connectUrl, requestedTransferFormat)]; 3755 case 1: 3756 _a.sent(); 3757 this.connectionId = negotiateResponse.connectionId; 3758 return [2 /*return*/]; 3759 case 2: 3760 transportExceptions = []; 3761 transports = negotiateResponse.availableTransports || []; 3762 negotiate = negotiateResponse; 3763 _i = 0, transports_1 = transports; 3764 _a.label = 3; 3765 case 3: 3766 if (!(_i < transports_1.length)) return [3 /*break*/, 13]; 3767 endpoint = transports_1[_i]; 3768 transportOrError = this.resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat);
3769 if (!(transportOrError instanceof Error)) return [3 /*break*/, 4]; 3770 // Store the error and continue, we don't want to cause a re-negotiate in these cases 3771 transportExceptions.push(endpoint.transport + " failed: " + transportOrError); 3772 return [3 /*break*/, 12]; 3773 case 4: 3774 if (!this.isITransport(transportOrError)) return [3 /*break*/, 12]; 3775 this.transport = transportOrError; 3776 if (!!negotiate) return [3 /*break*/, 9]; 3777 _a.label = 5; 3778 case 5: 3779 _a.trys.push([5, 7, , 8]); 3780 return [4 /*yield*/, this.getNegotiationResponse(url)]; 3781 case 6: 3782 negotiate = _a.sent(); 3783 return [3 /*break*/, 8]; 3784 case 7: 3785 ex_1 = _a.sent(); 3786 return [2 /*return*/, Promise.reject(ex_1)]; 3787 case 8: 3788 connectUrl = this.createConnectUrl(url, negotiate.connectionToken); 3789 _a.label = 9; 3790 case 9: 3791 _a.trys.push([9, 11, , 12]); 3792 return [4 /*yield*/, this.startTransport(connectUrl, requestedTransferFormat)]; 3793 case 10: 3794 _a.sent(); 3795 this.connectionId = negotiate.connectionId; 3796 return [2 /*return*/]; 3797 case 11: 3798 ex_2 = _a.sent(); 3799 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "Failed to start the transport '" + endpoint.transport + "': " + ex_2); 3800 negotiate = undefined; 3801 transportExceptions.push(endpoint.transport + " failed: " + ex_2); 3802 if (this.connectionState !== "Connecting " /* Connecting */) { 3803 message = "Failed to select transport before stop() was called."; 3804 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, message); 3805 return [2 /*return*/, Promise.reject(new Error(message))];
3806 } 3807 return [3 /*break*/, 12]; 3808 case 12: 3809 _i++; 3810 return [3 /*break*/, 3]; 3811 case 13: 3812 if (transportExceptions.length > 0) { 3813 return [2 /*return*/, Promise.reject(new Error("Unable to connect to the server with any of the available transports. " + transportExceptions.join(" ")))]; 3814 } 3815 return [2 /*return*/, Promise.reject(new Error("None of the transports supported by the client are supported by the server."))]; 3816 } 3817 }); 3818 }); 3819 }; 3820 HttpConnection.prototype.constructTransport = function (transport) { 3821 switch (transport) { 3822 case _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].WebSockets: 3823 if (!this.options.WebSocket) { 3824 throw new Error("'WebSocket' is not supported in your environment."); 3825 } 3826 return new _WebSocketTransport__WEBPACK_IMPORTED_MODULE_6__["WebSocketTransport"](this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.WebSocket); 3827 case _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].ServerSentEvents: 3828 if (!this.options.EventSource) { 3829 throw new Error("'EventSource' is not supported in your environment."); 3830 } 3831 return new _ServerSentEventsTransport__WEBPACK_IMPORTED_MODULE_4__["ServerSentEventsTransport"](this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false, this.options.EventSource); 3832 case _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].LongPolling: 3833 return new _LongPollingTransport__WEBPACK_IMPORTED_MODULE_3__["LongPollingTransport"](this.httpClient, this.accessTokenFactory, this.logger, this.options.logMessageContent || false); 3834 default: 3835 throw new Error("Unknown transport: " + transport + "."); 3836 } 3837 }; 3838 HttpConnection.prototype.startTransport = function (url, transferFormat) { 3839 var _this = this; 3840 this.transport.onreceive = this.onreceive; 3841 this.transport.onclose = function (e) { return _this.stopConnection(e); }; 3842 return this.transport.connect(url, transferFormat); 3843 }; 3844 HttpConnection.prototype.resolveTransportOrError = function (endpoint, requestedTransport, requestedTransferFormat) { 3845 var transport = _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][endpoint.transport]; 3846 if (transport === null || transport === undefined) { 3847 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Skipping transport '" + endpoint.transport + "' because it is not supported by this client."); 3848 return new Error("Skipping transport '" + endpoint.transport + "' because it is not supported by this client."); 3849 } 3850 else { 3851 if (transportMatches(requestedTransport, transport)) { 3852 var transferFormats = endpoint.transferFormats.map(function (s) { return _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"][s]; }); 3853 if (transferFormats.indexOf(requestedTransferFormat) >= 0) { 3854 if ((transport === _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].WebSockets && !this.options.WebSocket) || 3855 (transport === _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"].ServerSentEvents && !this.options.EventSource)) { 3856 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Skipping transport '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' because it is not supported in your environment.'"); 3857 return new Error("'" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' is not supported in your environment."); 3858 } 3859 else { 3860 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Selecting transport '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "'."); 3861 try {
3862 return this.constructTransport(transport); 3863 } 3864 catch (ex) { 3865 return ex; 3866 } 3867 } 3868 } 3869 else { 3870 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Skipping transport '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' because it does not support the requested transfer format '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"][requestedTransferFormat] + "'."); 3871 return new Error("'" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' does not support " + _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"][requestedTransferFormat] + "."); 3872 } 3873 } 3874 else { 3875 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Skipping transport '" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' because it was disabled by the client."); 3876 return new Error("'" + _ITransport__WEBPACK_IMPORTED_MODULE_2__["HttpTransportType"][transport] + "' is disabled by the client."); 3877 } 3878 } 3879 }; 3880 HttpConnection.prototype.isITransport = function (transport) { 3881 return transport && typeof (transport) === "object" && "connect" in transport; 3882 }; 3883 HttpConnection.prototype.stopConnection = function (error) { 3884 var _this = this; 3885 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "HttpConnection.stopConnection(" + error + ") called while in state " + this.connectionState + "."); 3886 this.transport = undefined; 3887 // If we have a stopError, it takes precedence over the error from the transport 3888 error = this.stopError || error; 3889 this.stopError = undefined; 3890 if (this.connectionState === "Disconnected" /* Disconnected */) { 3891 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Debug, "Call to HttpConnection.stopConnection(" + error + ") was ignored because the connection is already in the disconnected state."); 3892 return; 3893 } 3894 if (this.connectionState === "Connecting " /* Connecting */) { 3895 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Warning, "Call to HttpConnection.stopConnection(" + error + ") was ignored because the connection hasn't yet left the in the connecting state."); 3896 return; 3897 } 3898 if (this.connectionState === "Disconnecting" /* Disconnecting */) { 3899 // A call to stop() induced this call to stopConnection and needs to be completed. 3900 // Any stop() awaiters will be scheduled to continue after the onclose callback fires. 3901 this.stopPromiseResolver(); 3902 } 3903 if (error) { 3904 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "Connection disconnected with error '" + error + "'."); 3905 } 3906 else { 3907 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Information, "Connection disconnected."); 3908 } 3909 if (this.sendQueue) { 3910 this.sendQueue.stop().catch(function (e) { 3911 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "TransportSendQueue.stop() threw error '" + e + "'."); 3912 }); 3913 this.sendQueue = undefined; 3914 } 3915 this.connectionId = undefined; 3916 this.connectionState = "Disconnected" /* Disconnected */; 3917 if (this.connectionStarted) { 3918 this.connectionStarted = false; 3919 try { 3920 if (this.onclose) { 3921 this.onclose(error); 3922 } 3923 } 3924 catch (e) { 3925 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Error, "HttpConnection.onclose(" + error + ") threw error '" + e + "'."); 3926 } 3927 } 3928 }; 3929 HttpConnection.prototype.resolveUrl = function (url) { 3930 // startsWith is not supported in IE 3931 if (url.lastIndexOf("https://", 0) === 0 || url.lastIndexOf("http://", 0) === 0) { 3932 return url; 3933 } 3934 if (!_Utils__WEBPACK_IMPORTED_MODULE_5__["Platform"].isBrowser || !window.document) { 3935 throw new Error("Cannot resolve '" + url + "'."); 3936 } 3937 // Setting the url to the href propery of an anchor tag handles normalization 3938 // for us. There are 3 main cases. 3939 // 1. Relative path normalization e.g "b" -> "http://localhost:5000/a/b" 3940 // 2. Absolute path normalization e.g "/a/b" -> "http://localhost:5000/a/b" 3941 // 3. Networkpath reference normalization e.g "//localhost:5000/a/b" -> "http://localhost:5000/a/b" 3942 var aTag = window.document.createElement("a"); 3943 aTag.href = url; 3944 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Information, "Normalizing '" + url + "' to '" + aTag.href + "'."); 3945 return aTag.href; 3946 }; 3947 HttpConnection.prototype.resolveNegotiateUrl = function (url) { 3948 var index = url.indexOf("?"); 3949 var negotiateUrl = url.substring(0, index === -1 ? url.length : index); 3950 if (negotiateUrl[negotiateUrl.length - 1] !== "/") { 3951 negotiateUrl += "/"; 3952 } 3953 negotiateUrl += "negotiate"; 3954 negotiateUrl += index === -1 ? "" : url.substring(index); 3955 if (negotiateUrl.indexOf("negotiateVersion") === -1) { 3956 negotiateUrl += index === -1 ? "?" : "&"; 3957 negotiateUrl += "negotiateVersion=" + this.negotiateVersion; 3958 } 3959 return negotiateUrl; 3960 }; 3961 return HttpConnection; 3962}()); 3963 3964function transportMatches(requestedTransport, actualTransport) { 3965 return !requestedTransport || ((actualTransport & requestedTransport) !== 0); 3966} 3967/** @private */ 3968var TransportSendQueue = /** @class */ (function () { 3969 function TransportSendQueue(transport) { 3970 this.transport = transport; 3971 this.buffer = []; 3972 this.executing = true; 3973 this.sendBufferedData = new PromiseSource(); 3974 this.transportResult = new PromiseSource(); 3975 this.sendLoopPromise = this.sendLoop(); 3976 } 3977 TransportSendQueue.prototype.send = function (data) { 3978 this.bufferData(data); 3979 if (!this.transportResult) { 3980 this.transportResult = new PromiseSource(); 3981 } 3982 return this.transportResult.promise; 3983 }; 3984 TransportSendQueue.prototype.stop = function () { 3985 this.executing = false; 3986 this.sendBufferedData.resolve(); 3987 return this.sendLoopPromise; 3988 }; 3989 TransportSendQueue.prototype.bufferData = function (data) { 3990 if (this.buffer.length && typeof (this.buffer[0]) !== typeof (data)) { 3991 throw new Error("Expected data to be of type " + typeof (this.buffer) + " but was of type " + typeof (data)); 3992 } 3993 this.buffer.push(data); 3994 this.sendBufferedData.resolve(); 3995 }; 3996 TransportSendQueue.prototype.sendLoop = function () { 3997 return __awaiter(this, void 0, void 0, function () { 3998 var transportResult, data, error_1; 3999 return __generator(this, function (_a) { 4000 switch (_a.label) { 4001 case 0: 4002 if (false) {} 4003 return [4 /*yield*/, this.sendBufferedData.promise]; 4004 case 1: 4005 _a.sent(); 4006 if (!this.executing) { 4007 if (this.transportResult) { 4008 this.transportResult.reject("Connection stopped."); 4009 } 4010 return [3 /*break*/, 6]; 4011 } 4012 this.sendBufferedData = new PromiseSource(); 4013 transportResult = this.transportResult; 4014 this.transportResult = undefined; 4015 data = typeof (this.buffer[0]) === "string" ? 4016 this.buffer.join("") : 4017 TransportSendQueue.concatBuffers(this.buffer); 4018 this.buffer.length = 0; 4019 _a.label = 2; 4020 case 2: 4021 _a.trys.push([2, 4, , 5]); 4022 return [4 /*yield*/, this.transport.send(data)]; 4023 case 3: 4024 _a.sent(); 4025 transportResult.resolve(); 4026 return [3 /*break*/, 5]; 4027 case 4: 4028 error_1 = _a.sent(); 4029 transportResult.reject(error_1); 4030 return [3 /*break*/, 5]; 4031 case 5: return [3 /*break*/, 0]; 4032 case 6: return [2 /*return*/]; 4033 } 4034 }); 4035 }); 4036 }; 4037 TransportSendQueue.concatBuffers = function (arrayBuffers) { 4038 var totalLength = arrayBuffers.map(function (b) { return b.byteLength; }).reduce(function (a, b) { return a + b; }); 4039 var result = new Uint8Array(totalLength); 4040 var offset = 0; 4041 for (var _i = 0, arrayBuffers_1 = arrayBuffers; _i < arrayBuffers_1.length; _i++) { 4042 var item = arrayBuffers_1[_i]; 4043 result.set(new Uint8Array(item), offset); 4044 offset += item.byteLength; 4045 } 4046 return result; 4047 }; 4048 return TransportSendQueue; 4049}()); 4050 4051var PromiseSource = /** @class */ (function () { 4052 function PromiseSource() { 4053 var _this = this; 4054 this.promise = new Promise(function (resolve, reject) { 4055 var _a; 4056 return _a = [resolve, reject], _this.resolver = _a[0], _this.rejecter = _a[1], _a; 4057 }); 4058 } 4059 PromiseSource.prototype.resolve = function () { 4060 this.resolver(); 4061 }; 4062 PromiseSource.prototype.reject = function (reason) { 4063 this.rejecter(reason); 4064 }; 4065 return PromiseSource; 4066}()); 4067 4068 4069/***/ }), 4070/* 20 */ 4071/***/ (function(module, __webpack_exports__, __webpack_require__) { 4072 4073"use strict"; 4074__webpack_require__.r(__webpack_exports__); 4075/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "HttpTransportType", function() { return HttpTransportType; }); 4076/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TransferFormat", function() { return TransferFormat; }); 4077// Copyright (c) .NET Foundation. All rights reserved. 4078// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4079// This will be treated as a bit flag in the future, so we keep it using power-of-two values. 4080/** Specifies a specific HTTP transport type. */ 4081var HttpTransportType; 4082(function (HttpTransportType) { 4083 /** Specifies no transport preference. */ 4084 HttpTransportType[HttpTransportType["None"] = 0] = "None"; 4085 /** Specifies the WebSockets transport. */ 4086 HttpTransportType[HttpTransportType["WebSockets"] = 1] = "WebSockets"; 4087 /** Specifies the Server-Sent Events transport. */ 4088 HttpTransportType[HttpTransportType["ServerSentEvents"] = 2] = "ServerSentEvents"; 4089 /** Specifies the Long Polling transport. */ 4090 HttpTransportType[HttpTransportType["LongPolling"] = 4] = "LongPolling"; 4091})(HttpTransportType || (HttpTransportType = {})); 4092/** Specifies the transfer format for a connection. */ 4093var TransferFormat; 4094(function (TransferFormat) { 4095 /** Specifies that only text data will be transmitted over the connection. */ 4096 TransferFormat[TransferFormat["Text"] = 1] = "Text"; 4097 /** Specifies that binary data will be transmitted over the connection. */ 4098 TransferFormat[TransferFormat["Binary"] = 2] = "Binary"; 4099})(TransferFormat || (TransferFormat = {})); 4100 4101 4102/***/ }), 4103/* 21 */ 4104/***/ (function(module, __webpack_exports__, __webpack_require__) { 4105 4106"use strict"; 4107__webpack_require__.r(__webpack_exports__); 4108/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LongPollingTransport", function() { return LongPollingTransport; }); 4109/* harmony import */ var _AbortController__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(22); 4110/* harmony import */ var _Errors__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4); 4111/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9); 4112/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(20); 4113/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(13); 4114// Copyright (c) .NET Foundation. All rights reserved. 4115// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4116var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 4117 return new (P || (P = Promise))(function (resolve, reject) { 4118 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 4119 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 4120 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 4121 step((generator = generator.apply(thisArg, _arguments || [])).next()); 4122 });
vendor: 4,302 bytes, lines 4123-4194
4123}; 4124var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 4125 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 4126 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 4127 function verb(n) { return function (v) { return step([n, v]); }; } 4128 function step(op) { 4129 if (f) throw new TypeError("Generator is already executing."); 4130 while (_) try { 4131 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 4132 if (y = 0, t) op = [op[0] & 2, t.value]; 4133 switch (op[0]) { 4134 case 0: case 1: t = op; break; 4135 case 4: _.label++; return { value: op[1], done: false }; 4136 case 5: _.label++; y = op[1]; op = [0]; continue; 4137 case 7: op = _.ops.pop(); _.trys.pop(); continue; 4138 default: 4139 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 4140 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 4141 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 4142 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 4143 if (t[2]) _.ops.pop(); 4144 _.trys.pop(); continue; 4145 } 4146 op = body.call(thisArg, _); 4147 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 4148 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 4149 } 4150}; 4151 4152 4153 4154 4155 4156// Not exported from 'index', this type is internal. 4157/** @private */ 4158var LongPollingTransport = /** @class */ (function () { 4159 function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent) { 4160 this.httpClient = httpClient; 4161 this.accessTokenFactory = accessTokenFactory; 4162 this.logger = logger; 4163 this.pollAbort = new _AbortController__WEBPACK_IMPORTED_MODULE_0__["AbortController"](); 4164 this.logMessageContent = logMessageContent; 4165 this.running = false; 4166 this.onreceive = null; 4167 this.onclose = null; 4168 } 4169 Object.defineProperty(LongPollingTransport.prototype, "pollAborted", { 4170 // This is an internal type, not exported from 'index' so this is really just internal. 4171 get: function () { 4172 return this.pollAbort.aborted; 4173 }, 4174 enumerable: true, 4175 configurable: true 4176 }); 4177 LongPollingTransport.prototype.connect = function (url, transferFormat) { 4178 return __awaiter(this, void 0, void 0, function () { 4179 var pollOptions, token, pollUrl, response; 4180 return __generator(this, function (_a) { 4181 switch (_a.label) { 4182 case 0: 4183 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isRequired(url, "url"); 4184 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isRequired(transferFormat, "transferFormat"); 4185 _Utils__WEBPACK_IMPORTED_MODULE_4__["Arg"].isIn(transferFormat, _ITransport__WEBPACK_IMPORTED_MODULE_3__["TransferFormat"], "transferFormat"); 4186 this.url = url; 4187 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Connecting."); 4188 // Allow binary format on Node and Browsers that support binary content (indicated by the presence of responseType property) 4189 if (transferFormat === _ITransport__WEBPACK_IMPORTED_MODULE_3__["TransferFormat"].Binary && 4190 (typeof XMLHttpRequest !== "undefined" && typeof new XMLHttpRequest().responseType !== "string")) { 4191 throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported."); 4192 } 4193 pollOptions = { 4194 abortSignal: this.pollAbort.signal,
4195 headers: {}, 4196 timeout: 100000, 4197 }; 4198 if (transferFormat === _ITransport__WEBPACK_IMPORTED_MODULE_3__["TransferFormat"].Binary) { 4199 pollOptions.responseType = "arraybuffer"; 4200 } 4201 return [4 /*yield*/, this.getAccessToken()]; 4202 case 1: 4203 token = _a.sent(); 4204 this.updateHeaderToken(pollOptions, token); 4205 pollUrl = url + "&_=" + Date.now(); 4206 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) polling: " + pollUrl + "."); 4207 return [4 /*yield*/, this.httpClient.get(pollUrl, pollOptions)]; 4208 case 2: 4209 response = _a.sent(); 4210 if (response.statusCode !== 200) { 4211 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + "."); 4212 // Mark running as false so that the poll immediately ends and runs the close logic 4213 this.closeError = new _Errors__WEBPACK_IMPORTED_MODULE_1__["HttpError"](response.statusText || "", response.statusCode); 4214 this.running = false; 4215 } 4216 else { 4217 this.running = true; 4218 } 4219 this.receiving = this.poll(this.url, pollOptions); 4220 return [2 /*return*/]; 4221 } 4222 }); 4223 }); 4224 }; 4225 LongPollingTransport.prototype.getAccessToken = function () { 4226 return __awaiter(this, void 0, void 0, function () { 4227 return __generator(this, function (_a) { 4228 switch (_a.label) { 4229 case 0: 4230 if (!this.accessTokenFactory) return [3 /*break*/, 2]; 4231 return [4 /*yield*/, this.accessTokenFactory()]; 4232 case 1: return [2 /*return*/, _a.sent()]; 4233 case 2: return [2 /*return*/, null]; 4234 } 4235 }); 4236 }); 4237 }; 4238 LongPollingTransport.prototype.updateHeaderToken = function (request, token) { 4239 if (!request.headers) { 4240 request.headers = {}; 4241 } 4242 if (token) { 4243 // tslint:disable-next-line:no-string-literal 4244 request.headers["Authorization"] = "Bearer " + token; 4245 return; 4246 } 4247 // tslint:disable-next-line:no-string-literal 4248 if (request.headers["Authorization"]) { 4249 // tslint:disable-next-line:no-string-literal 4250 delete request.headers["Authorization"]; 4251 } 4252 }; 4253 LongPollingTransport.prototype.poll = function (url, pollOptions) { 4254 return __awaiter(this, void 0, void 0, function () { 4255 var token, pollUrl, response, e_1; 4256 return __generator(this, function (_a) { 4257 switch (_a.label) { 4258 case 0: 4259 _a.trys.push([0, , 8, 9]); 4260 _a.label = 1; 4261 case 1: 4262 if (!this.running) return [3 /*break*/, 7]; 4263 return [4 /*yield*/, this.getAccessToken()]; 4264 case 2: 4265 token = _a.sent(); 4266 this.updateHeaderToken(pollOptions, token); 4267 _a.label = 3; 4268 case 3: 4269 _a.trys.push([3, 5, , 6]); 4270 pollUrl = url + "&_=" + Date.now(); 4271 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) polling: " + pollUrl + "."); 4272 return [4 /*yield*/, this.httpClient.get(pollUrl, pollOptions)]; 4273 case 4: 4274 response = _a.sent(); 4275 if (response.statusCode === 204) { 4276 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Information, "(LongPolling transport) Poll terminated by server."); 4277 this.running = false; 4278 } 4279 else if (response.statusCode !== 200) { 4280 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Error, "(LongPolling transport) Unexpected response code: " + response.statusCode + "."); 4281 // Unexpected status code 4282 this.closeError = new _Errors__WEBPACK_IMPORTED_MODULE_1__["HttpError"](response.statusText || "", response.statusCode); 4283 this.running = false; 4284 } 4285 else { 4286 // Process the response 4287 if (response.content) { 4288 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) data received. " + Object(_Utils__WEBPACK_IMPORTED_MODULE_4__["getDataDetail"])(response.content, this.logMessageContent) + "."); 4289 if (this.onreceive) { 4290 this.onreceive(response.content); 4291 } 4292 } 4293 else { 4294 // This is another way timeout manifest. 4295 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Poll timed out, reissuing."); 4296 } 4297 } 4298 return [3 /*break*/, 6]; 4299 case 5: 4300 e_1 = _a.sent(); 4301 if (!this.running) { 4302 // Log but disregard errors that occur after stopping 4303 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Poll errored after shutdown: " + e_1.message); 4304 } 4305 else { 4306 if (e_1 instanceof _Errors__WEBPACK_IMPORTED_MODULE_1__["TimeoutError"]) { 4307 // Ignore timeouts and reissue the poll. 4308 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Poll timed out, reissuing."); 4309 } 4310 else { 4311 // Close the connection with the error as the result. 4312 this.closeError = e_1; 4313 this.running = false; 4314 } 4315 } 4316 return [3 /*break*/, 6]; 4317 case 6: return [3 /*break*/, 1]; 4318 case 7: return [3 /*break*/, 9]; 4319 case 8: 4320 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Polling complete."); 4321 // We will reach here with pollAborted==false when the server returned a response causing the transport to stop. 4322 // If pollAborted==true then client initiated the stop and the stop method will raise the close event after DELETE is sent. 4323 if (!this.pollAborted) { 4324 this.raiseOnClose(); 4325 } 4326 return [7 /*endfinally*/]; 4327 case 9: return [2 /*return*/]; 4328 } 4329 }); 4330 }); 4331 }; 4332 LongPollingTransport.prototype.send = function (data) { 4333 return __awaiter(this, void 0, void 0, function () { 4334 return __generator(this, function (_a) { 4335 if (!this.running) { 4336 return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))];
vendor: 15,463 bytes, lines 4337-4625
4337 } 4338 return [2 /*return*/, Object(_Utils__WEBPACK_IMPORTED_MODULE_4__["sendMessage"])(this.logger, "LongPolling", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent)]; 4339 }); 4340 }); 4341 }; 4342 LongPollingTransport.prototype.stop = function () { 4343 return __awaiter(this, void 0, void 0, function () { 4344 var deleteOptions, token; 4345 return __generator(this, function (_a) { 4346 switch (_a.label) { 4347 case 0: 4348 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Stopping polling."); 4349 // Tell receiving loop to stop, abort any current request, and then wait for it to finish 4350 this.running = false; 4351 this.pollAbort.abort(); 4352 _a.label = 1; 4353 case 1: 4354 _a.trys.push([1, , 5, 6]); 4355 return [4 /*yield*/, this.receiving]; 4356 case 2: 4357 _a.sent(); 4358 // Send DELETE to clean up long polling on the server 4359 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) sending DELETE request to " + this.url + "."); 4360 deleteOptions = { 4361 headers: {}, 4362 }; 4363 return [4 /*yield*/, this.getAccessToken()]; 4364 case 3: 4365 token = _a.sent(); 4366 this.updateHeaderToken(deleteOptions, token); 4367 return [4 /*yield*/, this.httpClient.delete(this.url, deleteOptions)]; 4368 case 4: 4369 _a.sent(); 4370 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) DELETE request sent."); 4371 return [3 /*break*/, 6]; 4372 case 5: 4373 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, "(LongPolling transport) Stop finished."); 4374 // Raise close event here instead of in polling 4375 // It needs to happen after the DELETE request is sent 4376 this.raiseOnClose(); 4377 return [7 /*endfinally*/]; 4378 case 6: return [2 /*return*/]; 4379 } 4380 }); 4381 }); 4382 }; 4383 LongPollingTransport.prototype.raiseOnClose = function () { 4384 if (this.onclose) { 4385 var logMessage = "(LongPolling transport) Firing onclose event."; 4386 if (this.closeError) { 4387 logMessage += " Error: " + this.closeError; 4388 } 4389 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_2__["LogLevel"].Trace, logMessage); 4390 this.onclose(this.closeError); 4391 } 4392 }; 4393 return LongPollingTransport; 4394}()); 4395 4396 4397 4398/***/ }), 4399/* 22 */ 4400/***/ (function(module, __webpack_exports__, __webpack_require__) { 4401 4402"use strict"; 4403__webpack_require__.r(__webpack_exports__); 4404/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AbortController", function() { return AbortController; }); 4405// Copyright (c) .NET Foundation. All rights reserved. 4406// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4407// Rough polyfill of https://developer.mozilla.org/en-US/docs/Web/API/AbortController 4408// We don't actually ever use the API being polyfilled, we always use the polyfill because 4409// it's a very new API right now. 4410// Not exported from index. 4411/** @private */ 4412var AbortController = /** @class */ (function () { 4413 function AbortController() { 4414 this.isAborted = false; 4415 this.onabort = null; 4416 } 4417 AbortController.prototype.abort = function () { 4418 if (!this.isAborted) { 4419 this.isAborted = true; 4420 if (this.onabort) { 4421 this.onabort(); 4422 } 4423 } 4424 }; 4425 Object.defineProperty(AbortController.prototype, "signal", { 4426 get: function () { 4427 return this; 4428 }, 4429 enumerable: true, 4430 configurable: true 4431 }); 4432 Object.defineProperty(AbortController.prototype, "aborted", { 4433 get: function () { 4434 return this.isAborted; 4435 }, 4436 enumerable: true, 4437 configurable: true 4438 }); 4439 return AbortController; 4440}()); 4441 4442 4443 4444/***/ }), 4445/* 23 */ 4446/***/ (function(module, __webpack_exports__, __webpack_require__) { 4447 4448"use strict"; 4449__webpack_require__.r(__webpack_exports__); 4450/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ServerSentEventsTransport", function() { return ServerSentEventsTransport; }); 4451/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); 4452/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20); 4453/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13); 4454// Copyright (c) .NET Foundation. All rights reserved. 4455// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4456var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 4457 return new (P || (P = Promise))(function (resolve, reject) { 4458 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 4459 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 4460 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 4461 step((generator = generator.apply(thisArg, _arguments || [])).next()); 4462 }); 4463}; 4464var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 4465 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 4466 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 4467 function verb(n) { return function (v) { return step([n, v]); }; } 4468 function step(op) { 4469 if (f) throw new TypeError("Generator is already executing."); 4470 while (_) try { 4471 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 4472 if (y = 0, t) op = [op[0] & 2, t.value]; 4473 switch (op[0]) { 4474 case 0: case 1: t = op; break; 4475 case 4: _.label++; return { value: op[1], done: false }; 4476 case 5: _.label++; y = op[1]; op = [0]; continue; 4477 case 7: op = _.ops.pop(); _.trys.pop(); continue; 4478 default: 4479 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 4480 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 4481 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 4482 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 4483 if (t[2]) _.ops.pop(); 4484 _.trys.pop(); continue; 4485 } 4486 op = body.call(thisArg, _); 4487 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 4488 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 4489 } 4490}; 4491 4492 4493 4494/** @private */ 4495var ServerSentEventsTransport = /** @class */ (function () { 4496 function ServerSentEventsTransport(httpClient, accessTokenFactory, logger, logMessageContent, eventSourceConstructor) { 4497 this.httpClient = httpClient; 4498 this.accessTokenFactory = accessTokenFactory; 4499 this.logger = logger; 4500 this.logMessageContent = logMessageContent; 4501 this.eventSourceConstructor = eventSourceConstructor; 4502 this.onreceive = null; 4503 this.onclose = null; 4504 } 4505 ServerSentEventsTransport.prototype.connect = function (url, transferFormat) { 4506 return __awaiter(this, void 0, void 0, function () { 4507 var token; 4508 var _this = this; 4509 return __generator(this, function (_a) { 4510 switch (_a.label) { 4511 case 0: 4512 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isRequired(url, "url"); 4513 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isRequired(transferFormat, "transferFormat"); 4514 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isIn(transferFormat, _ITransport__WEBPACK_IMPORTED_MODULE_1__["TransferFormat"], "transferFormat"); 4515 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(SSE transport) Connecting."); 4516 // set url before accessTokenFactory because this.url is only for send and we set the auth header instead of the query string for send 4517 this.url = url; 4518 if (!this.accessTokenFactory) return [3 /*break*/, 2]; 4519 return [4 /*yield*/, this.accessTokenFactory()]; 4520 case 1: 4521 token = _a.sent(); 4522 if (token) { 4523 url += (url.indexOf("?") < 0 ? "?" : "&") + ("access_token=" + encodeURIComponent(token)); 4524 } 4525 _a.label = 2; 4526 case 2: return [2 /*return*/, new Promise(function (resolve, reject) { 4527 var opened = false; 4528 if (transferFormat !== _ITransport__WEBPACK_IMPORTED_MODULE_1__["TransferFormat"].Text) { 4529 reject(new Error("The Server-Sent Events transport only supports the 'Text' transfer format")); 4530 return; 4531 } 4532 var eventSource; 4533 if (_Utils__WEBPACK_IMPORTED_MODULE_2__["Platform"].isBrowser || _Utils__WEBPACK_IMPORTED_MODULE_2__["Platform"].isWebWorker) { 4534 eventSource = new _this.eventSourceConstructor(url, { withCredentials: true }); 4535 } 4536 else { 4537 // Non-browser passes cookies via the dictionary 4538 var cookies = _this.httpClient.getCookieString(url); 4539 eventSource = new _this.eventSourceConstructor(url, { withCredentials: true, headers: { Cookie: cookies } }); 4540 } 4541 try { 4542 eventSource.onmessage = function (e) { 4543 if (_this.onreceive) { 4544 try { 4545 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(SSE transport) data received. " + Object(_Utils__WEBPACK_IMPORTED_MODULE_2__["getDataDetail"])(e.data, _this.logMessageContent) + "."); 4546 _this.onreceive(e.data); 4547 } 4548 catch (error) { 4549 _this.close(error); 4550 return; 4551 } 4552 } 4553 }; 4554 eventSource.onerror = function (e) { 4555 var error = new Error(e.data || "Error occurred"); 4556 if (opened) { 4557 _this.close(error); 4558 } 4559 else { 4560 reject(error); 4561 } 4562 }; 4563 eventSource.onopen = function () { 4564 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Information, "SSE connected to " + _this.url); 4565 _this.eventSource = eventSource; 4566 opened = true; 4567 resolve(); 4568 }; 4569 } 4570 catch (e) { 4571 reject(e); 4572 return; 4573 } 4574 })]; 4575 } 4576 }); 4577 }); 4578 }; 4579 ServerSentEventsTransport.prototype.send = function (data) { 4580 return __awaiter(this, void 0, void 0, function () { 4581 return __generator(this, function (_a) { 4582 if (!this.eventSource) { 4583 return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; 4584 } 4585 return [2 /*return*/, Object(_Utils__WEBPACK_IMPORTED_MODULE_2__["sendMessage"])(this.logger, "SSE", this.httpClient, this.url, this.accessTokenFactory, data, this.logMessageContent)]; 4586 }); 4587 }); 4588 }; 4589 ServerSentEventsTransport.prototype.stop = function () { 4590 this.close(); 4591 return Promise.resolve(); 4592 }; 4593 ServerSentEventsTransport.prototype.close = function (e) { 4594 if (this.eventSource) { 4595 this.eventSource.close(); 4596 this.eventSource = undefined; 4597 if (this.onclose) { 4598 this.onclose(e); 4599 } 4600 } 4601 }; 4602 return ServerSentEventsTransport; 4603}()); 4604 4605 4606 4607/***/ }), 4608/* 24 */ 4609/***/ (function(module, __webpack_exports__, __webpack_require__) { 4610 4611"use strict"; 4612__webpack_require__.r(__webpack_exports__); 4613/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "WebSocketTransport", function() { return WebSocketTransport; }); 4614/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9); 4615/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20); 4616/* harmony import */ var _Utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13); 4617// Copyright (c) .NET Foundation. All rights reserved. 4618// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4619var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { 4620 return new (P || (P = Promise))(function (resolve, reject) { 4621 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 4622 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 4623 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 4624 step((generator = generator.apply(thisArg, _arguments || [])).next()); 4625 });
4626}; 4627var __generator = (undefined && undefined.__generator) || function (thisArg, body) { 4628 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 4629 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 4630 function verb(n) { return function (v) { return step([n, v]); }; } 4631 function step(op) { 4632 if (f) throw new TypeError("Generator is already executing."); 4633 while (_) try { 4634 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 4635 if (y = 0, t) op = [op[0] & 2, t.value]; 4636 switch (op[0]) { 4637 case 0: case 1: t = op; break; 4638 case 4: _.label++; return { value: op[1], done: false }; 4639 case 5: _.label++; y = op[1]; op = [0]; continue; 4640 case 7: op = _.ops.pop(); _.trys.pop(); continue; 4641 default: 4642 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 4643 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 4644 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 4645 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 4646 if (t[2]) _.ops.pop(); 4647 _.trys.pop(); continue; 4648 } 4649 op = body.call(thisArg, _); 4650 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 4651 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 4652 } 4653}; 4654 4655 4656 4657/** @private */ 4658var WebSocketTransport = /** @class */ (function () { 4659 function WebSocketTransport(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor) { 4660 this.logger = logger; 4661 this.accessTokenFactory = accessTokenFactory; 4662 this.logMessageContent = logMessageContent; 4663 this.webSocketConstructor = webSocketConstructor; 4664 this.httpClient = httpClient; 4665 this.onreceive = null; 4666 this.onclose = null; 4667 } 4668 WebSocketTransport.prototype.connect = function (url, transferFormat) { 4669 return __awaiter(this, void 0, void 0, function () { 4670 var token; 4671 var _this = this; 4672 return __generator(this, function (_a) { 4673 switch (_a.label) { 4674 case 0: 4675 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isRequired(url, "url"); 4676 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isRequired(transferFormat, "transferFormat"); 4677 _Utils__WEBPACK_IMPORTED_MODULE_2__["Arg"].isIn(transferFormat, _ITransport__WEBPACK_IMPORTED_MODULE_1__["TransferFormat"], "transferFormat"); 4678 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(WebSockets transport) Connecting."); 4679 if (!this.accessTokenFactory) return [3 /*break*/, 2]; 4680 return [4 /*yield*/, this.accessTokenFactory()]; 4681 case 1: 4682 token = _a.sent(); 4683 if (token) { 4684 url += (url.indexOf("?") < 0 ? "?" : "&") + ("access_token=" + encodeURIComponent(token)); 4685 } 4686 _a.label = 2; 4687 case 2: return [2 /*return*/, new Promise(function (resolve, reject) { 4688 url = url.replace(/^http/, "ws"); 4689 var webSocket; 4690 var cookies = _this.httpClient.getCookieString(url); 4691 var opened = false; 4692 if (_Utils__WEBPACK_IMPORTED_MODULE_2__["Platform"].isNode && cookies) { 4693 // Only pass cookies when in non-browser environments 4694 webSocket = new _this.webSocketConstructor(url, undefined, { 4695 headers: {
4696 Cookie: "" + cookies, 4697 }, 4698 }); 4699 } 4700 if (!webSocket) { 4701 // Chrome is not happy with passing 'undefined' as protocol 4702 webSocket = new _this.webSocketConstructor(url); 4703 } 4704 if (transferFormat === _ITransport__WEBPACK_IMPORTED_MODULE_1__["TransferFormat"].Binary) { 4705 webSocket.binaryType = "arraybuffer"; 4706 } 4707 // tslint:disable-next-line:variable-name 4708 webSocket.onopen = function (_event) { 4709 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Information, "WebSocket connected to " + url + "."); 4710 _this.webSocket = webSocket; 4711 opened = true; 4712 resolve(); 4713 }; 4714 webSocket.onerror = function (event) { 4715 var error = null; 4716 // ErrorEvent is a browser only type we need to check if the type exists before using it 4717 if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) { 4718 error = event.error; 4719 } 4720 else { 4721 error = new Error("There was an error with the transport."); 4722 } 4723 reject(error); 4724 }; 4725 webSocket.onmessage = function (message) { 4726 _this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(WebSockets transport) data received. " + Object(_Utils__WEBPACK_IMPORTED_MODULE_2__["getDataDetail"])(message.data, _this.logMessageContent) + "."); 4727 if (_this.onreceive) { 4728 _this.onreceive(message.data); 4729 } 4730 }; 4731 webSocket.onclose = function (event) { 4732 // Don't call close handler if connection was never established 4733 // We'll reject the connect call instead 4734 if (opened) { 4735 _this.close(event); 4736 } 4737 else { 4738 var error = null; 4739 // ErrorEvent is a browser only type we need to check if the type exists before using it 4740 if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) { 4741 error = event.error; 4742 } 4743 else { 4744 error = new Error("There was an error with the transport."); 4745 } 4746 reject(error); 4747 } 4748 }; 4749 })]; 4750 } 4751 }); 4752 }); 4753 }; 4754 WebSocketTransport.prototype.send = function (data) { 4755 if (this.webSocket && this.webSocket.readyState === this.webSocketConstructor.OPEN) { 4756 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(WebSockets transport) sending data. " + Object(_Utils__WEBPACK_IMPORTED_MODULE_2__["getDataDetail"])(data, this.logMessageContent) + "."); 4757 this.webSocket.send(data); 4758 return Promise.resolve(); 4759 } 4760 return Promise.reject("WebSocket is not in the OPEN state"); 4761 }; 4762 WebSocketTransport.prototype.stop = function () { 4763 if (this.webSocket) { 4764 // Manually invoke onclose callback inline so we know the HttpConnection was closed properly before returning
vendor: 7,170 bytes, lines 4765-4917
4765 // This also solves an issue where websocket.onclose could take 18+ seconds to trigger during network disconnects 4766 this.close(undefined); 4767 } 4768 return Promise.resolve(); 4769 }; 4770 WebSocketTransport.prototype.close = function (event) { 4771 // webSocket will be null if the transport did not start successfully 4772 if (this.webSocket) { 4773 // Clear websocket handlers because we are considering the socket closed now 4774 this.webSocket.onclose = function () { }; 4775 this.webSocket.onmessage = function () { }; 4776 this.webSocket.onerror = function () { }; 4777 this.webSocket.close(); 4778 this.webSocket = undefined; 4779 } 4780 this.logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_0__["LogLevel"].Trace, "(WebSockets transport) socket closed."); 4781 if (this.onclose) { 4782 if (event && (event.wasClean === false || event.code !== 1000)) { 4783 this.onclose(new Error("WebSocket closed with status code: " + event.code + " (" + event.reason + ").")); 4784 } 4785 else { 4786 this.onclose(); 4787 } 4788 } 4789 }; 4790 return WebSocketTransport; 4791}()); 4792 4793 4794 4795/***/ }), 4796/* 25 */ 4797/***/ (function(module, __webpack_exports__, __webpack_require__) { 4798 4799"use strict"; 4800__webpack_require__.r(__webpack_exports__); 4801/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "JsonHubProtocol", function() { return JsonHubProtocol; }); 4802/* harmony import */ var _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15); 4803/* harmony import */ var _ILogger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9); 4804/* harmony import */ var _ITransport__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20); 4805/* harmony import */ var _Loggers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14); 4806/* harmony import */ var _TextMessageFormat__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(12); 4807// Copyright (c) .NET Foundation. All rights reserved. 4808// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4809 4810 4811 4812 4813 4814var JSON_HUB_PROTOCOL_NAME = "json"; 4815/** Implements the JSON Hub Protocol. */ 4816var JsonHubProtocol = /** @class */ (function () { 4817 function JsonHubProtocol() { 4818 /** @inheritDoc */ 4819 this.name = JSON_HUB_PROTOCOL_NAME; 4820 /** @inheritDoc */ 4821 this.version = 1; 4822 /** @inheritDoc */ 4823 this.transferFormat = _ITransport__WEBPACK_IMPORTED_MODULE_2__["TransferFormat"].Text; 4824 } 4825 /** Creates an array of {@link @microsoft/signalr.HubMessage} objects from the specified serialized representation. 4826 * 4827 * @param {string} input A string containing the serialized representation. 4828 * @param {ILogger} logger A logger that will be used to log messages that occur during parsing. 4829 */ 4830 JsonHubProtocol.prototype.parseMessages = function (input, logger) { 4831 // The interface does allow "ArrayBuffer" to be passed in, but this implementation does not. So let's throw a useful error. 4832 if (typeof input !== "string") { 4833 throw new Error("Invalid input for JSON hub protocol. Expected a string."); 4834 } 4835 if (!input) { 4836 return []; 4837 } 4838 if (logger === null) { 4839 logger = _Loggers__WEBPACK_IMPORTED_MODULE_3__["NullLogger"].instance; 4840 } 4841 // Parse the messages 4842 var messages = _TextMessageFormat__WEBPACK_IMPORTED_MODULE_4__["TextMessageFormat"].parse(input); 4843 var hubMessages = []; 4844 for (var _i = 0, messages_1 = messages; _i < messages_1.length; _i++) { 4845 var message = messages_1[_i]; 4846 var parsedMessage = JSON.parse(message); 4847 if (typeof parsedMessage.type !== "number") { 4848 throw new Error("Invalid payload."); 4849 } 4850 switch (parsedMessage.type) { 4851 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__["MessageType"].Invocation: 4852 this.isInvocationMessage(parsedMessage); 4853 break; 4854 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__["MessageType"].StreamItem: 4855 this.isStreamItemMessage(parsedMessage); 4856 break; 4857 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__["MessageType"].Completion: 4858 this.isCompletionMessage(parsedMessage); 4859 break; 4860 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__["MessageType"].Ping: 4861 // Single value, no need to validate 4862 break; 4863 case _IHubProtocol__WEBPACK_IMPORTED_MODULE_0__["MessageType"].Close: 4864 // All optional values, no need to validate 4865 break; 4866 default: 4867 // Future protocol changes can add message types, old clients can ignore them 4868 logger.log(_ILogger__WEBPACK_IMPORTED_MODULE_1__["LogLevel"].Information, "Unknown message type '" + parsedMessage.type + "' ignored."); 4869 continue; 4870 } 4871 hubMessages.push(parsedMessage); 4872 } 4873 return hubMessages; 4874 }; 4875 /** Writes the specified {@link @microsoft/signalr.HubMessage} to a string and returns it. 4876 * 4877 * @param {HubMessage} message The message to write. 4878 * @returns {string} A string containing the serialized representation of the message. 4879 */ 4880 JsonHubProtocol.prototype.writeMessage = function (message) { 4881 return _TextMessageFormat__WEBPACK_IMPORTED_MODULE_4__["TextMessageFormat"].write(JSON.stringify(message)); 4882 }; 4883 JsonHubProtocol.prototype.isInvocationMessage = function (message) { 4884 this.assertNotEmptyString(message.target, "Invalid payload for Invocation message."); 4885 if (message.invocationId !== undefined) { 4886 this.assertNotEmptyString(message.invocationId, "Invalid payload for Invocation message."); 4887 } 4888 }; 4889 JsonHubProtocol.prototype.isStreamItemMessage = function (message) { 4890 this.assertNotEmptyString(message.invocationId, "Invalid payload for StreamItem message."); 4891 if (message.item === undefined) { 4892 throw new Error("Invalid payload for StreamItem message."); 4893 } 4894 }; 4895 JsonHubProtocol.prototype.isCompletionMessage = function (message) { 4896 if (message.result && message.error) { 4897 throw new Error("Invalid payload for Completion message."); 4898 } 4899 if (!message.result && message.error) { 4900 this.assertNotEmptyString(message.error, "Invalid payload for Completion message."); 4901 } 4902 this.assertNotEmptyString(message.invocationId, "Invalid payload for Completion message."); 4903 }; 4904 JsonHubProtocol.prototype.assertNotEmptyString = function (value, errorMessage) { 4905 if (typeof value !== "string" || value === "") { 4906 throw new Error(errorMessage); 4907 } 4908 }; 4909 return JsonHubProtocol; 4910}()); 4911 4912 4913 4914/***/ }) 4915/******/ ]); 4916}); 4917//# sourceMappingURL=signalr.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.