@aspnet/signalr
Advanced tools
Comparing version 1.1.2 to 1.1.4
@@ -17,10 +17,4 @@ "use strict"; | ||
var HttpClient_1 = require("./HttpClient"); | ||
var NodeHttpClient_1 = require("./NodeHttpClient"); | ||
var XhrHttpClient_1 = require("./XhrHttpClient"); | ||
var nodeHttpClientModule; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
nodeHttpClientModule = requireFunc("./NodeHttpClient"); | ||
} | ||
/** Default implementation of {@link @aspnet/signalr.HttpClient}. */ | ||
@@ -35,7 +29,4 @@ var DefaultHttpClient = /** @class */ (function (_super) { | ||
} | ||
else if (typeof nodeHttpClientModule !== "undefined") { | ||
_this.httpClient = new nodeHttpClientModule.NodeHttpClient(logger); | ||
} | ||
else { | ||
throw new Error("No HttpClient could be created."); | ||
_this.httpClient = new NodeHttpClient_1.NodeHttpClient(logger); | ||
} | ||
@@ -42,0 +33,0 @@ return _this; |
@@ -161,8 +161,12 @@ "use strict"; | ||
var invocationDescriptor = this.createStreamInvocation(methodName, args); | ||
var subject = new Utils_1.Subject(function () { | ||
var promiseQueue; | ||
var subject = new Utils_1.Subject(); | ||
subject.cancelCallback = function () { | ||
var cancelInvocation = _this.createCancelInvocation(invocationDescriptor.invocationId); | ||
var cancelMessage = _this.protocol.writeMessage(cancelInvocation); | ||
delete _this.callbacks[invocationDescriptor.invocationId]; | ||
return _this.sendMessage(cancelMessage); | ||
}); | ||
return promiseQueue.then(function () { | ||
return _this.sendMessage(cancelMessage); | ||
}); | ||
}; | ||
this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { | ||
@@ -189,3 +193,3 @@ if (error) { | ||
var message = this.protocol.writeMessage(invocationDescriptor); | ||
this.sendMessage(message) | ||
promiseQueue = this.sendMessage(message) | ||
.catch(function (e) { | ||
@@ -192,0 +196,0 @@ subject.error(e); |
@@ -7,3 +7,3 @@ "use strict"; | ||
/** The version of the SignalR client. */ | ||
exports.VERSION = "1.1.2"; | ||
exports.VERSION = "1.1.4"; | ||
var Errors_1 = require("./Errors"); | ||
@@ -10,0 +10,0 @@ exports.AbortError = Errors_1.AbortError; |
@@ -23,3 +23,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Request = require("request"); | ||
var Errors_1 = require("./Errors"); | ||
@@ -29,2 +28,9 @@ var HttpClient_1 = require("./HttpClient"); | ||
var Utils_1 = require("./Utils"); | ||
var requestModule; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
requestModule = requireFunc("request"); | ||
} | ||
var NodeHttpClient = /** @class */ (function (_super) { | ||
@@ -34,5 +40,8 @@ __extends(NodeHttpClient, _super); | ||
var _this = _super.call(this) || this; | ||
if (typeof requestModule === "undefined") { | ||
throw new Error("The 'request' module could not be loaded."); | ||
} | ||
_this.logger = logger; | ||
_this.cookieJar = Request.jar(); | ||
_this.request = Request.defaults({ jar: _this.cookieJar }); | ||
_this.cookieJar = requestModule.jar(); | ||
_this.request = requestModule.defaults({ jar: _this.cookieJar }); | ||
return _this; | ||
@@ -39,0 +48,0 @@ } |
@@ -150,5 +150,4 @@ "use strict"; | ||
var Subject = /** @class */ (function () { | ||
function Subject(cancelCallback) { | ||
function Subject() { | ||
this.observers = []; | ||
this.cancelCallback = cancelCallback; | ||
} | ||
@@ -195,3 +194,3 @@ Subject.prototype.next = function (item) { | ||
} | ||
if (this.subject.observers.length === 0) { | ||
if (this.subject.observers.length === 0 && this.subject.cancelCallback) { | ||
this.subject.cancelCallback().catch(function (_) { }); | ||
@@ -198,0 +197,0 @@ } |
@@ -15,10 +15,4 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
import { HttpClient } from "./HttpClient"; | ||
import { NodeHttpClient } from "./NodeHttpClient"; | ||
import { XhrHttpClient } from "./XhrHttpClient"; | ||
var nodeHttpClientModule; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
nodeHttpClientModule = requireFunc("./NodeHttpClient"); | ||
} | ||
/** Default implementation of {@link @aspnet/signalr.HttpClient}. */ | ||
@@ -33,7 +27,4 @@ var DefaultHttpClient = /** @class */ (function (_super) { | ||
} | ||
else if (typeof nodeHttpClientModule !== "undefined") { | ||
_this.httpClient = new nodeHttpClientModule.NodeHttpClient(logger); | ||
} | ||
else { | ||
throw new Error("No HttpClient could be created."); | ||
_this.httpClient = new NodeHttpClient(logger); | ||
} | ||
@@ -40,0 +31,0 @@ return _this; |
@@ -159,8 +159,12 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
var invocationDescriptor = this.createStreamInvocation(methodName, args); | ||
var subject = new Subject(function () { | ||
var promiseQueue; | ||
var subject = new Subject(); | ||
subject.cancelCallback = function () { | ||
var cancelInvocation = _this.createCancelInvocation(invocationDescriptor.invocationId); | ||
var cancelMessage = _this.protocol.writeMessage(cancelInvocation); | ||
delete _this.callbacks[invocationDescriptor.invocationId]; | ||
return _this.sendMessage(cancelMessage); | ||
}); | ||
return promiseQueue.then(function () { | ||
return _this.sendMessage(cancelMessage); | ||
}); | ||
}; | ||
this.callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) { | ||
@@ -187,3 +191,3 @@ if (error) { | ||
var message = this.protocol.writeMessage(invocationDescriptor); | ||
this.sendMessage(message) | ||
promiseQueue = this.sendMessage(message) | ||
.catch(function (e) { | ||
@@ -190,0 +194,0 @@ subject.error(e); |
@@ -5,3 +5,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** The version of the SignalR client. */ | ||
export var VERSION = "1.1.2"; | ||
export var VERSION = "1.1.4"; | ||
export { AbortError, HttpError, TimeoutError } from "./Errors"; | ||
@@ -8,0 +8,0 @@ export { HttpClient, HttpResponse } from "./HttpClient"; |
@@ -21,3 +21,2 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
}; | ||
import * as Request from "request"; | ||
import { AbortError, HttpError, TimeoutError } from "./Errors"; | ||
@@ -27,2 +26,9 @@ import { HttpClient, HttpResponse } from "./HttpClient"; | ||
import { isArrayBuffer } from "./Utils"; | ||
var requestModule; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
requestModule = requireFunc("request"); | ||
} | ||
var NodeHttpClient = /** @class */ (function (_super) { | ||
@@ -32,5 +38,8 @@ __extends(NodeHttpClient, _super); | ||
var _this = _super.call(this) || this; | ||
if (typeof requestModule === "undefined") { | ||
throw new Error("The 'request' module could not be loaded."); | ||
} | ||
_this.logger = logger; | ||
_this.cookieJar = Request.jar(); | ||
_this.request = Request.defaults({ jar: _this.cookieJar }); | ||
_this.cookieJar = requestModule.jar(); | ||
_this.request = requestModule.defaults({ jar: _this.cookieJar }); | ||
return _this; | ||
@@ -37,0 +46,0 @@ } |
@@ -22,4 +22,4 @@ import { HttpClient } from "./HttpClient"; | ||
observers: Array<IStreamSubscriber<T>>; | ||
cancelCallback: () => Promise<void>; | ||
constructor(cancelCallback: () => Promise<void>); | ||
cancelCallback?: () => Promise<void>; | ||
constructor(); | ||
next(item: T): void; | ||
@@ -26,0 +26,0 @@ error(err: any): void; |
@@ -143,5 +143,4 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
var Subject = /** @class */ (function () { | ||
function Subject(cancelCallback) { | ||
function Subject() { | ||
this.observers = []; | ||
this.cancelCallback = cancelCallback; | ||
} | ||
@@ -188,3 +187,3 @@ Subject.prototype.next = function (item) { | ||
} | ||
if (this.subject.observers.length === 0) { | ||
if (this.subject.observers.length === 0 && this.subject.cancelCallback) { | ||
this.subject.cancelCallback().catch(function (_) { }); | ||
@@ -191,0 +190,0 @@ } |
{ | ||
"name": "@aspnet/signalr", | ||
"version": "1.1.2", | ||
"version": "1.1.4", | ||
"description": "ASP.NET Core SignalR Client", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
@@ -7,12 +7,5 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
import { ILogger } from "./ILogger"; | ||
import { NodeHttpClient } from "./NodeHttpClient"; | ||
import { XhrHttpClient } from "./XhrHttpClient"; | ||
let nodeHttpClientModule: any; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
nodeHttpClientModule = requireFunc("./NodeHttpClient"); | ||
} | ||
/** Default implementation of {@link @aspnet/signalr.HttpClient}. */ | ||
@@ -28,6 +21,4 @@ export class DefaultHttpClient extends HttpClient { | ||
this.httpClient = new XhrHttpClient(logger); | ||
} else if (typeof nodeHttpClientModule !== "undefined") { | ||
this.httpClient = new nodeHttpClientModule.NodeHttpClient(logger); | ||
} else { | ||
throw new Error("No HttpClient could be created."); | ||
this.httpClient = new NodeHttpClient(logger); | ||
} | ||
@@ -34,0 +25,0 @@ } |
@@ -157,3 +157,5 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
const subject = new Subject<T>(() => { | ||
let promiseQueue: Promise<void>; | ||
const subject = new Subject<T>(); | ||
subject.cancelCallback = () => { | ||
const cancelInvocation: CancelInvocationMessage = this.createCancelInvocation(invocationDescriptor.invocationId); | ||
@@ -164,4 +166,6 @@ const cancelMessage: any = this.protocol.writeMessage(cancelInvocation); | ||
return this.sendMessage(cancelMessage); | ||
}); | ||
return promiseQueue.then(() => { | ||
return this.sendMessage(cancelMessage); | ||
}); | ||
}; | ||
@@ -188,3 +192,3 @@ this.callbacks[invocationDescriptor.invocationId] = (invocationEvent: CompletionMessage | StreamItemMessage | null, error?: Error) => { | ||
this.sendMessage(message) | ||
promiseQueue = this.sendMessage(message) | ||
.catch((e) => { | ||
@@ -191,0 +195,0 @@ subject.error(e); |
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
import * as Request from "request"; | ||
// @ts-ignore: This will be removed from built files and is here to make the types available during dev work | ||
import * as Request from "@types/request"; | ||
@@ -11,5 +12,13 @@ import { AbortError, HttpError, TimeoutError } from "./Errors"; | ||
let requestModule: Request.RequestAPI<Request.Request, Request.CoreOptions, Request.RequiredUriUrl>; | ||
if (typeof XMLHttpRequest === "undefined") { | ||
// In order to ignore the dynamic require in webpack builds we need to do this magic | ||
// @ts-ignore: TS doesn't know about these names | ||
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require; | ||
requestModule = requireFunc("request"); | ||
} | ||
export class NodeHttpClient extends HttpClient { | ||
private readonly logger: ILogger; | ||
private readonly request: Request.RequestAPI<Request.Request, Request.CoreOptions, Request.RequiredUriUrl>; | ||
private readonly request: typeof requestModule; | ||
private readonly cookieJar: Request.CookieJar; | ||
@@ -19,5 +28,9 @@ | ||
super(); | ||
if (typeof requestModule === "undefined") { | ||
throw new Error("The 'request' module could not be loaded."); | ||
} | ||
this.logger = logger; | ||
this.cookieJar = Request.jar(); | ||
this.request = Request.defaults({ jar: this.cookieJar }); | ||
this.cookieJar = requestModule.jar(); | ||
this.request = requestModule.defaults({ jar: this.cookieJar }); | ||
} | ||
@@ -24,0 +37,0 @@ |
@@ -110,7 +110,6 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
public observers: Array<IStreamSubscriber<T>>; | ||
public cancelCallback: () => Promise<void>; | ||
public cancelCallback?: () => Promise<void>; | ||
constructor(cancelCallback: () => Promise<void>) { | ||
constructor() { | ||
this.observers = []; | ||
this.cancelCallback = cancelCallback; | ||
} | ||
@@ -162,3 +161,3 @@ | ||
if (this.subject.observers.length === 0) { | ||
if (this.subject.observers.length === 0 && this.subject.cancelCallback) { | ||
this.subject.cancelCallback().catch((_) => { }); | ||
@@ -165,0 +164,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1383480
169
12717
8