@aspnet/signalr
Advanced tools
Comparing version 1.0.0-rc1-update1 to 1.0.0
@@ -8,2 +8,3 @@ "use strict"; | ||
// it's a very new API right now. | ||
// Not exported from index. | ||
var AbortController = /** @class */ (function () { | ||
@@ -10,0 +11,0 @@ function AbortController() { |
"use strict"; | ||
// 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. | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
// This is where we add any polyfills we'll need for the browser. It is the entry module for browser-specific builds. | ||
@@ -31,3 +29,3 @@ require("es6-promise/dist/es6-promise.auto.js"); | ||
} | ||
__export(require("./index")); | ||
tslib_1.__exportStar(require("./index"), exports); | ||
//# sourceMappingURL=browser-index.js.map |
"use strict"; | ||
// 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. | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
/** Error thrown when an HTTP request fails. */ | ||
var HttpError = /** @class */ (function (_super) { | ||
__extends(HttpError, _super); | ||
tslib_1.__extends(HttpError, _super); | ||
/** Constructs a new instance of {@link HttpError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
* @param {number} statusCode The HTTP status code represented by this error. | ||
*/ | ||
function HttpError(errorMessage, statusCode) { | ||
@@ -31,4 +28,9 @@ var _newTarget = this.constructor; | ||
exports.HttpError = HttpError; | ||
/** Error thrown when a timeout elapses. */ | ||
var TimeoutError = /** @class */ (function (_super) { | ||
__extends(TimeoutError, _super); | ||
tslib_1.__extends(TimeoutError, _super); | ||
/** Constructs a new instance of {@link TimeoutError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
*/ | ||
function TimeoutError(errorMessage) { | ||
@@ -35,0 +37,0 @@ var _newTarget = this.constructor; |
"use strict"; | ||
// 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. | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Errors_1 = require("./Errors"); | ||
var ILogger_1 = require("./ILogger"); | ||
/** Represents an HTTP response. */ | ||
var HttpResponse = /** @class */ (function () { | ||
@@ -34,2 +18,6 @@ function HttpResponse(statusCode, statusText, content) { | ||
exports.HttpResponse = HttpResponse; | ||
/** Abstraction over an HTTP client. | ||
* | ||
* This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms. | ||
*/ | ||
var HttpClient = /** @class */ (function () { | ||
@@ -39,9 +27,9 @@ function HttpClient() { | ||
HttpClient.prototype.get = function (url, options) { | ||
return this.send(__assign({}, options, { method: "GET", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "GET", url: url })); | ||
}; | ||
HttpClient.prototype.post = function (url, options) { | ||
return this.send(__assign({}, options, { method: "POST", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "POST", url: url })); | ||
}; | ||
HttpClient.prototype.delete = function (url, options) { | ||
return this.send(__assign({}, options, { method: "DELETE", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "DELETE", url: url })); | ||
}; | ||
@@ -51,4 +39,6 @@ return HttpClient; | ||
exports.HttpClient = HttpClient; | ||
/** Default implementation of {@link HttpClient}. */ | ||
var DefaultHttpClient = /** @class */ (function (_super) { | ||
__extends(DefaultHttpClient, _super); | ||
tslib_1.__extends(DefaultHttpClient, _super); | ||
/** Creates a new instance of the {@link DefaultHttpClient}, using the provided {@link ILogger} to log messages. */ | ||
function DefaultHttpClient(logger) { | ||
@@ -59,2 +49,3 @@ var _this = _super.call(this) || this; | ||
} | ||
/** @inheritDoc */ | ||
DefaultHttpClient.prototype.send = function (request) { | ||
@@ -61,0 +52,0 @@ var _this = this; |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var HttpClient_1 = require("./HttpClient"); | ||
@@ -80,5 +46,5 @@ var ILogger_1 = require("./ILogger"); | ||
HttpConnection.prototype.stop = function (error) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -111,6 +77,6 @@ case 0: | ||
HttpConnection.prototype.startInternal = function (transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var url, negotiateResponse, redirects, _loop_1, this_1, state_1, e_2; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -142,3 +108,3 @@ case 0: | ||
var accessToken_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -205,5 +171,5 @@ case 0: return [4 /*yield*/, this_1.getNegotiationResponse(url)]; | ||
HttpConnection.prototype.getNegotiationResponse = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var token, headers, negotiateUrl, response, e_3, _a; | ||
return __generator(this, function (_b) { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
@@ -246,5 +212,5 @@ case 0: return [4 /*yield*/, this.accessTokenFactory()]; | ||
HttpConnection.prototype.createTransport = function (url, requestedTransport, negotiateResponse, requestedTransferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var connectUrl, transports, _i, transports_1, endpoint, transport, ex_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -320,3 +286,3 @@ case 0: | ||
var transferFormats = endpoint.transferFormats.map(function (s) { return ITransport_1.TransferFormat[s]; }); | ||
if (!requestedTransport || transport === requestedTransport) { | ||
if (transportMatches(requestedTransport, transport)) { | ||
if (transferFormats.indexOf(requestedTransferFormat) >= 0) { | ||
@@ -343,3 +309,3 @@ if ((transport === ITransport_1.HttpTransportType.WebSockets && typeof WebSocket === "undefined") || | ||
HttpConnection.prototype.isITransport = function (transport) { | ||
return typeof (transport) === "object" && "connect" in transport; | ||
return transport && typeof (transport) === "object" && "connect" in transport; | ||
}; | ||
@@ -354,4 +320,4 @@ HttpConnection.prototype.changeState = function (from, to) { | ||
HttpConnection.prototype.stopConnection = function (error) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
this.transport = null; | ||
@@ -405,2 +371,5 @@ // If we have a stopError, it takes precedence over the error from the transport | ||
exports.HttpConnection = HttpConnection; | ||
function transportMatches(requestedTransport, actualTransport) { | ||
return !requestedTransport || ((actualTransport & requestedTransport) !== 0); | ||
} | ||
//# sourceMappingURL=HttpConnection.js.map |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var HandshakeProtocol_1 = require("./HandshakeProtocol"); | ||
var IHubProtocol_1 = require("./IHubProtocol"); | ||
var ILogger_1 = require("./ILogger"); | ||
var Utils_1 = require("./Utils"); | ||
var DEFAULT_TIMEOUT_IN_MS = 30 * 1000; | ||
/** Represents a connection to a SignalR Hub. */ | ||
var HubConnection = /** @class */ (function () { | ||
@@ -70,6 +38,10 @@ function HubConnection(connection, logger, protocol) { | ||
}; | ||
/** Starts the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.start = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var handshakeRequest; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -99,2 +71,6 @@ case 0: | ||
}; | ||
/** Stops the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.stop = function () { | ||
@@ -105,2 +81,9 @@ this.logger.log(ILogger_1.LogLevel.Debug, "Stopping HubConnection."); | ||
}; | ||
/** Invokes a streaming hub method on the server using the specified name and arguments. | ||
* | ||
* @typeparam T The type of the items returned by the server. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {IStreamResult<T>} An object that yields results from the server as they are received. | ||
*/ | ||
HubConnection.prototype.stream = function (methodName) { | ||
@@ -124,3 +107,3 @@ var _this = this; | ||
} | ||
if (invocationEvent.type === 3 /* Completion */) { | ||
if (invocationEvent.type === IHubProtocol_1.MessageType.Completion) { | ||
if (invocationEvent.error) { | ||
@@ -145,2 +128,11 @@ subject.error(new Error(invocationEvent.error)); | ||
}; | ||
/** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. | ||
* | ||
* The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still | ||
* be processing the invocation. | ||
* | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.send = function (methodName) { | ||
@@ -155,2 +147,13 @@ var args = []; | ||
}; | ||
/** Invokes a hub method on the server using the specified name and arguments. | ||
* | ||
* The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise | ||
* resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of | ||
* resolving the Promise. | ||
* | ||
* @typeparam T The expected return type. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error. | ||
*/ | ||
HubConnection.prototype.invoke = function (methodName) { | ||
@@ -169,3 +172,3 @@ var _this = this; | ||
} | ||
if (invocationEvent.type === 3 /* Completion */) { | ||
if (invocationEvent.type === IHubProtocol_1.MessageType.Completion) { | ||
var completionMessage = invocationEvent; | ||
@@ -192,2 +195,7 @@ if (completionMessage.error) { | ||
}; | ||
/** Registers a handler that will be invoked when the hub method with the specified method name is invoked. | ||
* | ||
* @param {string} methodName The name of the hub method to define. | ||
* @param {Function} newMethod The handler that will be raised when the hub method is invoked. | ||
*/ | ||
HubConnection.prototype.on = function (methodName, newMethod) { | ||
@@ -229,2 +237,6 @@ if (!methodName || !newMethod) { | ||
}; | ||
/** Registers a handler that will be invoked when the connection is closed. | ||
* | ||
* @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). | ||
*/ | ||
HubConnection.prototype.onclose = function (callback) { | ||
@@ -248,10 +260,10 @@ if (callback) { | ||
switch (message.type) { | ||
case 1 /* Invocation */: | ||
case IHubProtocol_1.MessageType.Invocation: | ||
this.invokeClientMethod(message); | ||
break; | ||
case 2 /* StreamItem */: | ||
case 3 /* Completion */: | ||
case IHubProtocol_1.MessageType.StreamItem: | ||
case IHubProtocol_1.MessageType.Completion: | ||
var callback = this.callbacks[message.invocationId]; | ||
if (callback != null) { | ||
if (message.type === 3 /* Completion */) { | ||
if (message.type === IHubProtocol_1.MessageType.Completion) { | ||
delete this.callbacks[message.invocationId]; | ||
@@ -262,6 +274,6 @@ } | ||
break; | ||
case 6 /* Ping */: | ||
case IHubProtocol_1.MessageType.Ping: | ||
// Don't care about pings | ||
break; | ||
case 7 /* Close */: | ||
case IHubProtocol_1.MessageType.Close: | ||
this.logger.log(ILogger_1.LogLevel.Information, "Close message received from server."); | ||
@@ -352,3 +364,3 @@ this.connection.stop(message.error ? new Error("Server returned an error on close: " + message.error) : null); | ||
target: methodName, | ||
type: 1 /* Invocation */, | ||
type: IHubProtocol_1.MessageType.Invocation, | ||
}; | ||
@@ -363,3 +375,3 @@ } | ||
target: methodName, | ||
type: 1 /* Invocation */, | ||
type: IHubProtocol_1.MessageType.Invocation, | ||
}; | ||
@@ -375,3 +387,3 @@ } | ||
target: methodName, | ||
type: 4 /* StreamInvocation */, | ||
type: IHubProtocol_1.MessageType.StreamInvocation, | ||
}; | ||
@@ -382,3 +394,3 @@ }; | ||
invocationId: id, | ||
type: 5 /* CancelInvocation */, | ||
type: IHubProtocol_1.MessageType.CancelInvocation, | ||
}; | ||
@@ -385,0 +397,0 @@ }; |
@@ -10,2 +10,3 @@ "use strict"; | ||
var Utils_1 = require("./Utils"); | ||
/** A builder for configuring {@link HubConnection} instances. */ | ||
var HubConnectionBuilder = /** @class */ (function () { | ||
@@ -39,2 +40,6 @@ function HubConnectionBuilder() { | ||
}; | ||
/** Configures the {@link HubConnection} to use the specified Hub Protocol. | ||
* | ||
* @param {IHubProtocol} protocol The {@link IHubProtocol} implementation to use. | ||
*/ | ||
HubConnectionBuilder.prototype.withHubProtocol = function (protocol) { | ||
@@ -45,2 +50,6 @@ Utils_1.Arg.isRequired(protocol, "protocol"); | ||
}; | ||
/** Creates a {@link HubConnection} from the configuration options specified in this builder. | ||
* | ||
* @returns {HubConnection} The configured {@link HubConnection}. | ||
*/ | ||
HubConnectionBuilder.prototype.build = function () { | ||
@@ -47,0 +56,0 @@ // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one |
@@ -5,2 +5,20 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** Defines the type of a Hub Message. */ | ||
var MessageType; | ||
(function (MessageType) { | ||
/** Indicates the message is an Invocation message and implements the {@link InvocationMessage} interface. */ | ||
MessageType[MessageType["Invocation"] = 1] = "Invocation"; | ||
/** Indicates the message is a StreamItem message and implements the {@link StreamItemMessage} interface. */ | ||
MessageType[MessageType["StreamItem"] = 2] = "StreamItem"; | ||
/** Indicates the message is a Completion message and implements the {@link CompletionMessage} interface. */ | ||
MessageType[MessageType["Completion"] = 3] = "Completion"; | ||
/** Indicates the message is a Stream Invocation message and implements the {@link StreamInvocationMessage} interface. */ | ||
MessageType[MessageType["StreamInvocation"] = 4] = "StreamInvocation"; | ||
/** Indicates the message is a Cancel Invocation message and implements the {@link CancelInvocationMessage} interface. */ | ||
MessageType[MessageType["CancelInvocation"] = 5] = "CancelInvocation"; | ||
/** Indicates the message is a Ping message and implements the {@link PingMessage} interface. */ | ||
MessageType[MessageType["Ping"] = 6] = "Ping"; | ||
/** Indicates the message is a Close message and implements the {@link CloseMessage} interface. */ | ||
MessageType[MessageType["Close"] = 7] = "Close"; | ||
})(MessageType = exports.MessageType || (exports.MessageType = {})); | ||
//# sourceMappingURL=IHubProtocol.js.map |
@@ -6,12 +6,23 @@ "use strict"; | ||
// These values are designed to match the ASP.NET Log Levels since that's the pattern we're emulating here. | ||
/** Indicates the severity of a log message. | ||
* | ||
* Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc. | ||
*/ | ||
var LogLevel; | ||
(function (LogLevel) { | ||
/** Log level for very low severity diagnostic messages. */ | ||
LogLevel[LogLevel["Trace"] = 0] = "Trace"; | ||
/** Log level for low severity diagnostic messages. */ | ||
LogLevel[LogLevel["Debug"] = 1] = "Debug"; | ||
/** Log level for informational diagnostic messages. */ | ||
LogLevel[LogLevel["Information"] = 2] = "Information"; | ||
/** Log level for diagnostic messages that indicate a non-fatal problem. */ | ||
LogLevel[LogLevel["Warning"] = 3] = "Warning"; | ||
/** Log level for diagnostic messages that indicate a failure in the current operation. */ | ||
LogLevel[LogLevel["Error"] = 4] = "Error"; | ||
/** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */ | ||
LogLevel[LogLevel["Critical"] = 5] = "Critical"; | ||
/** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */ | ||
LogLevel[LogLevel["None"] = 6] = "None"; | ||
})(LogLevel = exports.LogLevel || (exports.LogLevel = {})); | ||
//# sourceMappingURL=ILogger.js.map |
"use strict"; | ||
// 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. | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Everything that users need to access must be exported here. Including interfaces. | ||
__export(require("./Errors")); | ||
__export(require("./HttpClient")); | ||
__export(require("./HubConnection")); | ||
__export(require("./HubConnectionBuilder")); | ||
__export(require("./IHubProtocol")); | ||
__export(require("./ILogger")); | ||
__export(require("./ITransport")); | ||
__export(require("./Loggers")); | ||
__export(require("./JsonHubProtocol")); | ||
// Version token that will be replaced by the prepack command | ||
/** The version of the SignalR client. */ | ||
exports.VERSION = "1.0.0"; | ||
var Errors_1 = require("./Errors"); | ||
exports.HttpError = Errors_1.HttpError; | ||
exports.TimeoutError = Errors_1.TimeoutError; | ||
var HttpClient_1 = require("./HttpClient"); | ||
exports.DefaultHttpClient = HttpClient_1.DefaultHttpClient; | ||
exports.HttpClient = HttpClient_1.HttpClient; | ||
exports.HttpResponse = HttpClient_1.HttpResponse; | ||
var HubConnection_1 = require("./HubConnection"); | ||
exports.HubConnection = HubConnection_1.HubConnection; | ||
var HubConnectionBuilder_1 = require("./HubConnectionBuilder"); | ||
exports.HubConnectionBuilder = HubConnectionBuilder_1.HubConnectionBuilder; | ||
var IHubProtocol_1 = require("./IHubProtocol"); | ||
exports.MessageType = IHubProtocol_1.MessageType; | ||
var ILogger_1 = require("./ILogger"); | ||
exports.LogLevel = ILogger_1.LogLevel; | ||
var ITransport_1 = require("./ITransport"); | ||
exports.HttpTransportType = ITransport_1.HttpTransportType; | ||
exports.TransferFormat = ITransport_1.TransferFormat; | ||
var Loggers_1 = require("./Loggers"); | ||
exports.NullLogger = Loggers_1.NullLogger; | ||
var JsonHubProtocol_1 = require("./JsonHubProtocol"); | ||
exports.JsonHubProtocol = JsonHubProtocol_1.JsonHubProtocol; | ||
//# sourceMappingURL=index.js.map |
@@ -5,13 +5,23 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// This will be treated as a bit flag in the future, so we keep it using power-of-two values. | ||
/** Specifies a specific HTTP transport type. */ | ||
var HttpTransportType; | ||
(function (HttpTransportType) { | ||
HttpTransportType[HttpTransportType["WebSockets"] = 0] = "WebSockets"; | ||
HttpTransportType[HttpTransportType["ServerSentEvents"] = 1] = "ServerSentEvents"; | ||
HttpTransportType[HttpTransportType["LongPolling"] = 2] = "LongPolling"; | ||
/** Specifies no transport preference. */ | ||
HttpTransportType[HttpTransportType["None"] = 0] = "None"; | ||
/** Specifies the WebSockets transport. */ | ||
HttpTransportType[HttpTransportType["WebSockets"] = 1] = "WebSockets"; | ||
/** Specifies the Server-Sent Events transport. */ | ||
HttpTransportType[HttpTransportType["ServerSentEvents"] = 2] = "ServerSentEvents"; | ||
/** Specifies the Long Polling transport. */ | ||
HttpTransportType[HttpTransportType["LongPolling"] = 4] = "LongPolling"; | ||
})(HttpTransportType = exports.HttpTransportType || (exports.HttpTransportType = {})); | ||
/** Specifies the transfer format for a connection. */ | ||
var TransferFormat; | ||
(function (TransferFormat) { | ||
/** Specifies that only text data will be transmitted over the connection. */ | ||
TransferFormat[TransferFormat["Text"] = 1] = "Text"; | ||
/** Specifies that binary data will be transmitted over the connection. */ | ||
TransferFormat[TransferFormat["Binary"] = 2] = "Binary"; | ||
})(TransferFormat = exports.TransferFormat || (exports.TransferFormat = {})); | ||
//# sourceMappingURL=ITransport.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var IHubProtocol_1 = require("./IHubProtocol"); | ||
var ILogger_1 = require("./ILogger"); | ||
@@ -10,10 +11,23 @@ var ITransport_1 = require("./ITransport"); | ||
var TextMessageFormat_1 = require("./TextMessageFormat"); | ||
exports.JSON_HUB_PROTOCOL_NAME = "json"; | ||
var JSON_HUB_PROTOCOL_NAME = "json"; | ||
/** Implements the JSON Hub Protocol. */ | ||
var JsonHubProtocol = /** @class */ (function () { | ||
function JsonHubProtocol() { | ||
this.name = exports.JSON_HUB_PROTOCOL_NAME; | ||
/** @inheritDoc */ | ||
this.name = JSON_HUB_PROTOCOL_NAME; | ||
/** @inheritDoc */ | ||
this.version = 1; | ||
/** @inheritDoc */ | ||
this.transferFormat = ITransport_1.TransferFormat.Text; | ||
} | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* @param {string} input A string containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
JsonHubProtocol.prototype.parseMessages = function (input, logger) { | ||
// The interface does allow "ArrayBuffer" to be passed in, but this implementation does not. So let's throw a useful error. | ||
if (typeof input !== "string") { | ||
throw new Error("Invalid input for JSON hub protocol. Expected a string."); | ||
} | ||
if (!input) { | ||
@@ -35,15 +49,15 @@ return []; | ||
switch (parsedMessage.type) { | ||
case 1 /* Invocation */: | ||
case IHubProtocol_1.MessageType.Invocation: | ||
this.isInvocationMessage(parsedMessage); | ||
break; | ||
case 2 /* StreamItem */: | ||
case IHubProtocol_1.MessageType.StreamItem: | ||
this.isStreamItemMessage(parsedMessage); | ||
break; | ||
case 3 /* Completion */: | ||
case IHubProtocol_1.MessageType.Completion: | ||
this.isCompletionMessage(parsedMessage); | ||
break; | ||
case 6 /* Ping */: | ||
case IHubProtocol_1.MessageType.Ping: | ||
// Single value, no need to validate | ||
break; | ||
case 7 /* Close */: | ||
case IHubProtocol_1.MessageType.Close: | ||
// All optional values, no need to validate | ||
@@ -60,2 +74,7 @@ break; | ||
}; | ||
/** Writes the specified {@link HubMessage} to a string and returns it. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string} A string containing the serialized representation of the message. | ||
*/ | ||
JsonHubProtocol.prototype.writeMessage = function (message) { | ||
@@ -62,0 +81,0 @@ return TextMessageFormat_1.TextMessageFormat.write(JSON.stringify(message)); |
@@ -5,7 +5,10 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** A logger that does nothing when log messages are sent to it. */ | ||
var NullLogger = /** @class */ (function () { | ||
function NullLogger() { | ||
} | ||
/** @inheritDoc */ | ||
NullLogger.prototype.log = function (logLevel, message) { | ||
}; | ||
/** The singleton instance of the {@link NullLogger}. */ | ||
NullLogger.instance = new NullLogger(); | ||
@@ -12,0 +15,0 @@ return NullLogger; |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var AbortController_1 = require("./AbortController"); | ||
@@ -46,4 +12,5 @@ var Errors_1 = require("./Errors"); | ||
var SHUTDOWN_TIMEOUT = 5 * 1000; | ||
// Not exported from 'index', this type is internal. | ||
var LongPollingTransport = /** @class */ (function () { | ||
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent) { | ||
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, shutdownTimeout) { | ||
this.httpClient = httpClient; | ||
@@ -54,7 +21,16 @@ this.accessTokenFactory = accessTokenFactory || (function () { return null; }); | ||
this.logMessageContent = logMessageContent; | ||
this.shutdownTimeout = shutdownTimeout || SHUTDOWN_TIMEOUT; | ||
} | ||
Object.defineProperty(LongPollingTransport.prototype, "pollAborted", { | ||
// This is an internal type, not exported from 'index' so this is really just internal. | ||
get: function () { | ||
return this.pollAbort.aborted; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
LongPollingTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var pollOptions, token, closeError, pollUrl, response; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -116,5 +92,5 @@ case 0: | ||
LongPollingTransport.prototype.poll = function (url, pollOptions, closeError) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var token, pollUrl, response, e_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -140,4 +116,2 @@ case 0: | ||
this.logger.log(ILogger_1.LogLevel.Information, "(LongPolling transport) Poll terminated by server"); | ||
// If we were on a timeout waiting for shutdown, unregister it. | ||
clearTimeout(this.shutdownTimeout); | ||
this.running = false; | ||
@@ -186,2 +160,8 @@ } | ||
case 8: | ||
// Indicate that we've stopped so the shutdown timer doesn't get registered. | ||
this.stopped = true; | ||
// Clean up the shutdown timer if it was registered | ||
if (this.shutdownTimer) { | ||
clearTimeout(this.shutdownTimer); | ||
} | ||
// Fire our onclosed event | ||
@@ -200,4 +180,4 @@ if (this.onclose) { | ||
LongPollingTransport.prototype.send = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (!this.running) { | ||
@@ -211,6 +191,6 @@ return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; | ||
LongPollingTransport.prototype.stop = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var deleteOptions, token, response; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -234,8 +214,9 @@ case 0: | ||
case 3: | ||
// Abort the poll after 5 seconds if the server doesn't stop it. | ||
if (!this.pollAbort.aborted) { | ||
this.shutdownTimeout = setTimeout(SHUTDOWN_TIMEOUT, function () { | ||
_this.logger.log(ILogger_1.LogLevel.Warning, "(LongPolling transport) server did not terminate within 5 seconds after DELETE request, cancelling poll."); | ||
// Abort the poll after the shutdown timeout if the server doesn't stop the poll. | ||
if (!this.stopped) { | ||
this.shutdownTimer = setTimeout(function () { | ||
_this.logger.log(ILogger_1.LogLevel.Warning, "(LongPolling transport) server did not terminate after DELETE request, canceling poll."); | ||
// Abort any outstanding poll | ||
_this.pollAbort.abort(); | ||
}); | ||
}, this.shutdownTimeout); | ||
} | ||
@@ -242,0 +223,0 @@ return [7 /*endfinally*/]; |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var ILogger_1 = require("./ILogger"); | ||
@@ -51,6 +17,6 @@ var ITransport_1 = require("./ITransport"); | ||
ServerSentEventsTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var token; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -118,4 +84,4 @@ case 0: | ||
ServerSentEventsTransport.prototype.send = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (!this.eventSource) { | ||
@@ -122,0 +88,0 @@ return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; |
@@ -5,2 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// Not exported from index | ||
var TextMessageFormat = /** @class */ (function () { | ||
@@ -7,0 +8,0 @@ function TextMessageFormat() { |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var ILogger_1 = require("./ILogger"); | ||
@@ -89,5 +55,5 @@ var Loggers_1 = require("./Loggers"); | ||
function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var headers, token, response, _a; | ||
return __generator(this, function (_b) { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
@@ -94,0 +60,0 @@ case 0: return [4 /*yield*/, accessTokenFactory()]; |
"use strict"; | ||
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var ILogger_1 = require("./ILogger"); | ||
@@ -50,6 +16,6 @@ var ITransport_1 = require("./ITransport"); | ||
WebSocketTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var token; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -56,0 +22,0 @@ case 0: |
@@ -8,5 +8,8 @@ export declare class AbortController implements AbortSignal { | ||
} | ||
/** Represents a signal that can be monitored to determine if a request has been aborted. */ | ||
export interface AbortSignal { | ||
/** Indicates if the request has been aborted. */ | ||
aborted: boolean; | ||
/** Set this to a handler that will be invoked when the request is aborted. */ | ||
onabort: () => void; | ||
} |
@@ -6,2 +6,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
// it's a very new API right now. | ||
// Not exported from index. | ||
var AbortController = /** @class */ (function () { | ||
@@ -8,0 +9,0 @@ function AbortController() { |
@@ -0,9 +1,21 @@ | ||
/** Error thrown when an HTTP request fails. */ | ||
export declare class HttpError extends Error { | ||
private __proto__; | ||
/** The HTTP status code represented by this error. */ | ||
statusCode: number; | ||
/** Constructs a new instance of {@link HttpError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
* @param {number} statusCode The HTTP status code represented by this error. | ||
*/ | ||
constructor(errorMessage: string, statusCode: number); | ||
} | ||
/** Error thrown when a timeout elapses. */ | ||
export declare class TimeoutError extends Error { | ||
private __proto__; | ||
/** Constructs a new instance of {@link TimeoutError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
*/ | ||
constructor(errorMessage?: string); | ||
} |
// 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. | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
import * as tslib_1 from "tslib"; | ||
/** Error thrown when an HTTP request fails. */ | ||
var HttpError = /** @class */ (function (_super) { | ||
__extends(HttpError, _super); | ||
tslib_1.__extends(HttpError, _super); | ||
/** Constructs a new instance of {@link HttpError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
* @param {number} statusCode The HTTP status code represented by this error. | ||
*/ | ||
function HttpError(errorMessage, statusCode) { | ||
@@ -29,4 +26,9 @@ var _newTarget = this.constructor; | ||
export { HttpError }; | ||
/** Error thrown when a timeout elapses. */ | ||
var TimeoutError = /** @class */ (function (_super) { | ||
__extends(TimeoutError, _super); | ||
tslib_1.__extends(TimeoutError, _super); | ||
/** Constructs a new instance of {@link TimeoutError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
*/ | ||
function TimeoutError(errorMessage) { | ||
@@ -33,0 +35,0 @@ var _newTarget = this.constructor; |
import { AbortSignal } from "./AbortController"; | ||
import { ILogger } from "./ILogger"; | ||
/** Represents an HTTP request. */ | ||
export interface HttpRequest { | ||
/** The HTTP method to use for the request. */ | ||
method?: string; | ||
/** The URL for the request. */ | ||
url?: string; | ||
/** The body content for the request. May be a string or an ArrayBuffer (for binary data). */ | ||
content?: string | ArrayBuffer; | ||
/** An object describing headers to apply to the request. */ | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
/** The XMLHttpRequestResponseType to apply to the request. */ | ||
responseType?: XMLHttpRequestResponseType; | ||
/** An AbortSignal that can be monitored for cancellation. */ | ||
abortSignal?: AbortSignal; | ||
/** The time to wait for the request to complete before throwing a TimeoutError. Measured in milliseconds. */ | ||
timeout?: number; | ||
} | ||
/** Represents an HTTP response. */ | ||
export declare class HttpResponse { | ||
@@ -18,20 +27,86 @@ readonly statusCode: number; | ||
readonly content: string | ArrayBuffer; | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
*/ | ||
constructor(statusCode: number); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code and message. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code, message and string content. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
* @param {string} content The content of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string, content: string); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code, message and binary content. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
* @param {ArrayBuffer} content The content of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string, content: ArrayBuffer); | ||
} | ||
/** Abstraction over an HTTP client. | ||
* | ||
* This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms. | ||
*/ | ||
export declare abstract class HttpClient { | ||
/** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
get(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
get(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
/** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
post(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
post(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
/** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
delete(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
delete(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
/** Issues an HTTP request to the specified URL, returning a {@link Promise} that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {HttpRequest} request An {@link HttpRequest} describing the request to send. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an HttpResponse describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
abstract send(request: HttpRequest): Promise<HttpResponse>; | ||
} | ||
/** Default implementation of {@link HttpClient}. */ | ||
export declare class DefaultHttpClient extends HttpClient { | ||
private readonly logger; | ||
/** Creates a new instance of the {@link DefaultHttpClient}, using the provided {@link ILogger} to log messages. */ | ||
constructor(logger: ILogger); | ||
/** @inheritDoc */ | ||
send(request: HttpRequest): Promise<HttpResponse>; | ||
} |
// 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. | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { HttpError, TimeoutError } from "./Errors"; | ||
import { LogLevel } from "./ILogger"; | ||
/** Represents an HTTP response. */ | ||
var HttpResponse = /** @class */ (function () { | ||
@@ -32,2 +16,6 @@ function HttpResponse(statusCode, statusText, content) { | ||
export { HttpResponse }; | ||
/** Abstraction over an HTTP client. | ||
* | ||
* This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms. | ||
*/ | ||
var HttpClient = /** @class */ (function () { | ||
@@ -37,9 +25,9 @@ function HttpClient() { | ||
HttpClient.prototype.get = function (url, options) { | ||
return this.send(__assign({}, options, { method: "GET", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "GET", url: url })); | ||
}; | ||
HttpClient.prototype.post = function (url, options) { | ||
return this.send(__assign({}, options, { method: "POST", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "POST", url: url })); | ||
}; | ||
HttpClient.prototype.delete = function (url, options) { | ||
return this.send(__assign({}, options, { method: "DELETE", url: url })); | ||
return this.send(tslib_1.__assign({}, options, { method: "DELETE", url: url })); | ||
}; | ||
@@ -49,4 +37,6 @@ return HttpClient; | ||
export { HttpClient }; | ||
/** Default implementation of {@link HttpClient}. */ | ||
var DefaultHttpClient = /** @class */ (function (_super) { | ||
__extends(DefaultHttpClient, _super); | ||
tslib_1.__extends(DefaultHttpClient, _super); | ||
/** Creates a new instance of the {@link DefaultHttpClient}, using the provided {@link ILogger} to log messages. */ | ||
function DefaultHttpClient(logger) { | ||
@@ -57,2 +47,3 @@ var _this = _super.call(this) || this; | ||
} | ||
/** @inheritDoc */ | ||
DefaultHttpClient.prototype.send = function (request) { | ||
@@ -59,0 +50,0 @@ var _this = this; |
import { IConnection } from "./IConnection"; | ||
import { IHttpConnectionOptions } from "./IHttpConnectionOptions"; | ||
import { TransferFormat } from "./ITransport"; | ||
import { HttpTransportType, TransferFormat } from "./ITransport"; | ||
export interface INegotiateResponse { | ||
connectionId?: string; | ||
availableTransports?: IAvailableTransport[]; | ||
url?: string; | ||
accessToken?: string; | ||
} | ||
export interface IAvailableTransport { | ||
transport: keyof typeof HttpTransportType; | ||
transferFormats: Array<keyof typeof TransferFormat>; | ||
} | ||
export declare class HttpConnection implements IConnection { | ||
@@ -5,0 +15,0 @@ private connectionState; |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { DefaultHttpClient } from "./HttpClient"; | ||
@@ -78,5 +44,5 @@ import { LogLevel } from "./ILogger"; | ||
HttpConnection.prototype.stop = function (error) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var e_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -109,6 +75,6 @@ case 0: | ||
HttpConnection.prototype.startInternal = function (transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var url, negotiateResponse, redirects, _loop_1, this_1, state_1, e_2; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -140,3 +106,3 @@ case 0: | ||
var accessToken_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -203,5 +169,5 @@ case 0: return [4 /*yield*/, this_1.getNegotiationResponse(url)]; | ||
HttpConnection.prototype.getNegotiationResponse = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var token, headers, negotiateUrl, response, e_3, _a; | ||
return __generator(this, function (_b) { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
@@ -244,5 +210,5 @@ case 0: return [4 /*yield*/, this.accessTokenFactory()]; | ||
HttpConnection.prototype.createTransport = function (url, requestedTransport, negotiateResponse, requestedTransferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var connectUrl, transports, _i, transports_1, endpoint, transport, ex_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -318,3 +284,3 @@ case 0: | ||
var transferFormats = endpoint.transferFormats.map(function (s) { return TransferFormat[s]; }); | ||
if (!requestedTransport || transport === requestedTransport) { | ||
if (transportMatches(requestedTransport, transport)) { | ||
if (transferFormats.indexOf(requestedTransferFormat) >= 0) { | ||
@@ -341,3 +307,3 @@ if ((transport === HttpTransportType.WebSockets && typeof WebSocket === "undefined") || | ||
HttpConnection.prototype.isITransport = function (transport) { | ||
return typeof (transport) === "object" && "connect" in transport; | ||
return transport && typeof (transport) === "object" && "connect" in transport; | ||
}; | ||
@@ -352,4 +318,4 @@ HttpConnection.prototype.changeState = function (from, to) { | ||
HttpConnection.prototype.stopConnection = function (error) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
this.transport = null; | ||
@@ -403,2 +369,5 @@ // If we have a stopError, it takes precedence over the error from the transport | ||
export { HttpConnection }; | ||
function transportMatches(requestedTransport, actualTransport) { | ||
return !requestedTransport || ((actualTransport & requestedTransport) !== 0); | ||
} | ||
//# sourceMappingURL=HttpConnection.js.map |
import { IStreamResult } from "./Stream"; | ||
/** Represents a connection to a SignalR Hub. */ | ||
export declare class HubConnection { | ||
@@ -13,11 +14,73 @@ private readonly connection; | ||
private receivedHandshakeResponse; | ||
/** The server timeout in milliseconds. | ||
* | ||
* If this timeout elapses without receiving any messages from the server, the connection will be terminated with an error. | ||
* The default timeout value is 30,000 milliseconds (30 seconds). | ||
*/ | ||
serverTimeoutInMilliseconds: number; | ||
private constructor(); | ||
/** Starts the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error. | ||
*/ | ||
start(): Promise<void>; | ||
/** Stops the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. | ||
*/ | ||
stop(): Promise<void>; | ||
/** Invokes a streaming hub method on the server using the specified name and arguments. | ||
* | ||
* @typeparam T The type of the items returned by the server. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {IStreamResult<T>} An object that yields results from the server as they are received. | ||
*/ | ||
stream<T = any>(methodName: string, ...args: any[]): IStreamResult<T>; | ||
/** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. | ||
* | ||
* The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still | ||
* be processing the invocation. | ||
* | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. | ||
*/ | ||
send(methodName: string, ...args: any[]): Promise<void>; | ||
/** Invokes a hub method on the server using the specified name and arguments. | ||
* | ||
* The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise | ||
* resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of | ||
* resolving the Promise. | ||
* | ||
* @typeparam T The expected return type. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error. | ||
*/ | ||
invoke<T = any>(methodName: string, ...args: any[]): Promise<T>; | ||
/** Registers a handler that will be invoked when the hub method with the specified method name is invoked. | ||
* | ||
* @param {string} methodName The name of the hub method to define. | ||
* @param {Function} newMethod The handler that will be raised when the hub method is invoked. | ||
*/ | ||
on(methodName: string, newMethod: (...args: any[]) => void): void; | ||
off(methodName: string, method?: (...args: any[]) => void): void; | ||
/** Removes all handlers for the specified hub method. | ||
* | ||
* @param {string} methodName The name of the method to remove handlers for. | ||
*/ | ||
off(methodName: string): void; | ||
/** Removes the specified handler for the specified hub method. | ||
* | ||
* You must pass the exact same Function instance as was previously passed to {@link on}. Passing a different instance (even if the function | ||
* body is the same) will not remove the handler. | ||
* | ||
* @param {string} methodName The name of the method to remove handlers for. | ||
* @param {Function} method The handler to remove. This must be the same Function instance as the one passed to {@link on}. | ||
*/ | ||
off(methodName: string, method: (...args: any[]) => void): void; | ||
/** Registers a handler that will be invoked when the connection is closed. | ||
* | ||
* @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). | ||
*/ | ||
onclose(callback: (error?: Error) => void): void; | ||
@@ -24,0 +87,0 @@ private processIncomingData(data); |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { HandshakeProtocol } from "./HandshakeProtocol"; | ||
import { MessageType } from "./IHubProtocol"; | ||
import { LogLevel } from "./ILogger"; | ||
import { Arg, Subject } from "./Utils"; | ||
var DEFAULT_TIMEOUT_IN_MS = 30 * 1000; | ||
/** Represents a connection to a SignalR Hub. */ | ||
var HubConnection = /** @class */ (function () { | ||
@@ -68,6 +36,10 @@ function HubConnection(connection, logger, protocol) { | ||
}; | ||
/** Starts the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.start = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var handshakeRequest; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -97,2 +69,6 @@ case 0: | ||
}; | ||
/** Stops the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.stop = function () { | ||
@@ -103,2 +79,9 @@ this.logger.log(LogLevel.Debug, "Stopping HubConnection."); | ||
}; | ||
/** Invokes a streaming hub method on the server using the specified name and arguments. | ||
* | ||
* @typeparam T The type of the items returned by the server. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {IStreamResult<T>} An object that yields results from the server as they are received. | ||
*/ | ||
HubConnection.prototype.stream = function (methodName) { | ||
@@ -122,3 +105,3 @@ var _this = this; | ||
} | ||
if (invocationEvent.type === 3 /* Completion */) { | ||
if (invocationEvent.type === MessageType.Completion) { | ||
if (invocationEvent.error) { | ||
@@ -143,2 +126,11 @@ subject.error(new Error(invocationEvent.error)); | ||
}; | ||
/** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. | ||
* | ||
* The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still | ||
* be processing the invocation. | ||
* | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. | ||
*/ | ||
HubConnection.prototype.send = function (methodName) { | ||
@@ -153,2 +145,13 @@ var args = []; | ||
}; | ||
/** Invokes a hub method on the server using the specified name and arguments. | ||
* | ||
* The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise | ||
* resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of | ||
* resolving the Promise. | ||
* | ||
* @typeparam T The expected return type. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error. | ||
*/ | ||
HubConnection.prototype.invoke = function (methodName) { | ||
@@ -167,3 +170,3 @@ var _this = this; | ||
} | ||
if (invocationEvent.type === 3 /* Completion */) { | ||
if (invocationEvent.type === MessageType.Completion) { | ||
var completionMessage = invocationEvent; | ||
@@ -190,2 +193,7 @@ if (completionMessage.error) { | ||
}; | ||
/** Registers a handler that will be invoked when the hub method with the specified method name is invoked. | ||
* | ||
* @param {string} methodName The name of the hub method to define. | ||
* @param {Function} newMethod The handler that will be raised when the hub method is invoked. | ||
*/ | ||
HubConnection.prototype.on = function (methodName, newMethod) { | ||
@@ -227,2 +235,6 @@ if (!methodName || !newMethod) { | ||
}; | ||
/** Registers a handler that will be invoked when the connection is closed. | ||
* | ||
* @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). | ||
*/ | ||
HubConnection.prototype.onclose = function (callback) { | ||
@@ -246,10 +258,10 @@ if (callback) { | ||
switch (message.type) { | ||
case 1 /* Invocation */: | ||
case MessageType.Invocation: | ||
this.invokeClientMethod(message); | ||
break; | ||
case 2 /* StreamItem */: | ||
case 3 /* Completion */: | ||
case MessageType.StreamItem: | ||
case MessageType.Completion: | ||
var callback = this.callbacks[message.invocationId]; | ||
if (callback != null) { | ||
if (message.type === 3 /* Completion */) { | ||
if (message.type === MessageType.Completion) { | ||
delete this.callbacks[message.invocationId]; | ||
@@ -260,6 +272,6 @@ } | ||
break; | ||
case 6 /* Ping */: | ||
case MessageType.Ping: | ||
// Don't care about pings | ||
break; | ||
case 7 /* Close */: | ||
case MessageType.Close: | ||
this.logger.log(LogLevel.Information, "Close message received from server."); | ||
@@ -350,3 +362,3 @@ this.connection.stop(message.error ? new Error("Server returned an error on close: " + message.error) : null); | ||
target: methodName, | ||
type: 1 /* Invocation */, | ||
type: MessageType.Invocation, | ||
}; | ||
@@ -361,3 +373,3 @@ } | ||
target: methodName, | ||
type: 1 /* Invocation */, | ||
type: MessageType.Invocation, | ||
}; | ||
@@ -373,3 +385,3 @@ } | ||
target: methodName, | ||
type: 4 /* StreamInvocation */, | ||
type: MessageType.StreamInvocation, | ||
}; | ||
@@ -380,3 +392,3 @@ }; | ||
invocationId: id, | ||
type: 5 /* CancelInvocation */, | ||
type: MessageType.CancelInvocation, | ||
}; | ||
@@ -383,0 +395,0 @@ }; |
@@ -6,9 +6,48 @@ import { HubConnection } from "./HubConnection"; | ||
import { HttpTransportType } from "./ITransport"; | ||
/** A builder for configuring {@link HubConnection} instances. */ | ||
export declare class HubConnectionBuilder { | ||
configureLogging(logging: LogLevel | ILogger): HubConnectionBuilder; | ||
/** Configures console logging for the {@link HubConnection}. | ||
* | ||
* @param {LogLevel} logLevel The minimum level of messages to log. Anything at this level, or a more severe level, will be logged. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
configureLogging(logLevel: LogLevel): HubConnectionBuilder; | ||
/** Configures custom logging for the {@link HubConnection}. | ||
* | ||
* @param {ILogger} logger An object implementing the {@link ILogger} interface, which will be used to write all log messages. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
configureLogging(logger: ILogger): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use HTTP-based transports to connect to the specified URL. | ||
* | ||
* The transport will be selected automatically based on what the server and client support. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
withUrl(url: string): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use the specified HTTP-based transport to connect to the specified URL. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @param {HttpTransportType} transportType The specific transport to use. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
withUrl(url: string, transportType: HttpTransportType): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use HTTP-based transports to connect to the specified URL. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @param {IHttpConnectionOptions} options An options object used to configure the connection. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
withUrl(url: string, options: IHttpConnectionOptions): HubConnectionBuilder; | ||
withUrl(url: string, transportType: HttpTransportType): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use the specified Hub Protocol. | ||
* | ||
* @param {IHubProtocol} protocol The {@link IHubProtocol} implementation to use. | ||
*/ | ||
withHubProtocol(protocol: IHubProtocol): HubConnectionBuilder; | ||
/** Creates a {@link HubConnection} from the configuration options specified in this builder. | ||
* | ||
* @returns {HubConnection} The configured {@link HubConnection}. | ||
*/ | ||
build(): HubConnection; | ||
} |
@@ -8,2 +8,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
import { Arg, ConsoleLogger } from "./Utils"; | ||
/** A builder for configuring {@link HubConnection} instances. */ | ||
var HubConnectionBuilder = /** @class */ (function () { | ||
@@ -37,2 +38,6 @@ function HubConnectionBuilder() { | ||
}; | ||
/** Configures the {@link HubConnection} to use the specified Hub Protocol. | ||
* | ||
* @param {IHubProtocol} protocol The {@link IHubProtocol} implementation to use. | ||
*/ | ||
HubConnectionBuilder.prototype.withHubProtocol = function (protocol) { | ||
@@ -43,2 +48,6 @@ Arg.isRequired(protocol, "protocol"); | ||
}; | ||
/** Creates a {@link HubConnection} from the configuration options specified in this builder. | ||
* | ||
* @returns {HubConnection} The configured {@link HubConnection}. | ||
*/ | ||
HubConnectionBuilder.prototype.build = function () { | ||
@@ -45,0 +54,0 @@ // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one |
import { HttpClient } from "./HttpClient"; | ||
import { ILogger, LogLevel } from "./ILogger"; | ||
import { HttpTransportType, ITransport } from "./ITransport"; | ||
/** Options provided to the 'withUrl' method on {@link HubConnectionBuilder} to configure options for the HTTP-based transports. */ | ||
export interface IHttpConnectionOptions { | ||
/** An {@link HttpClient} that will be used to make HTTP requests. */ | ||
httpClient?: HttpClient; | ||
/** An {@link HttpTransportType} value specifying the transport to use for the connection. */ | ||
transport?: HttpTransportType | ITransport; | ||
/** Configures the logger used for logging. | ||
* | ||
* Provide an {@link ILogger} instance, and log messages will be logged via that instance. Alternatively, provide a value from | ||
* the {@link LogLevel} enumeration and a default logger which logs to the Console will be configured to log messages of the specified | ||
* level (or higher). | ||
*/ | ||
logger?: ILogger | LogLevel; | ||
accessTokenFactory?: () => string | Promise<string>; | ||
/** A function that provides an access token required for HTTP Bearer authentication. | ||
* | ||
* @returns {string | Promise<string>} A string containing the access token, or a Promise that resolves to a string containing the access token. | ||
*/ | ||
accessTokenFactory?(): string | Promise<string>; | ||
/** A boolean indicating if message content should be logged. | ||
* | ||
* Message content can contain sensitive user data, so this is disabled by default. | ||
*/ | ||
logMessageContent?: boolean; | ||
/** A boolean indicating if negotiation should be skipped. | ||
* | ||
* Negotiation can only be skipped when the {@link transport} property is set to 'HttpTransportType.WebSockets'. | ||
*/ | ||
skipNegotiation?: boolean; | ||
} |
import { ILogger } from "./ILogger"; | ||
import { TransferFormat } from "./ITransport"; | ||
export declare const enum MessageType { | ||
/** Defines the type of a Hub Message. */ | ||
export declare enum MessageType { | ||
/** Indicates the message is an Invocation message and implements the {@link InvocationMessage} interface. */ | ||
Invocation = 1, | ||
/** Indicates the message is a StreamItem message and implements the {@link StreamItemMessage} interface. */ | ||
StreamItem = 2, | ||
/** Indicates the message is a Completion message and implements the {@link CompletionMessage} interface. */ | ||
Completion = 3, | ||
/** Indicates the message is a Stream Invocation message and implements the {@link StreamInvocationMessage} interface. */ | ||
StreamInvocation = 4, | ||
/** Indicates the message is a Cancel Invocation message and implements the {@link CancelInvocationMessage} interface. */ | ||
CancelInvocation = 5, | ||
/** Indicates the message is a Ping message and implements the {@link PingMessage} interface. */ | ||
Ping = 6, | ||
/** Indicates the message is a Close message and implements the {@link CloseMessage} interface. */ | ||
Close = 7, | ||
} | ||
/** Defines a dictionary of string keys and string values representing headers attached to a Hub message. */ | ||
export interface MessageHeaders { | ||
/** Gets or sets the header with the specified key. */ | ||
[key: string]: string; | ||
} | ||
/** Union type of all known Hub messages. */ | ||
export declare type HubMessage = InvocationMessage | StreamInvocationMessage | StreamItemMessage | CompletionMessage | CancelInvocationMessage | PingMessage | CloseMessage; | ||
/** Defines properties common to all Hub messages. */ | ||
export interface HubMessageBase { | ||
/** A {@link MessageType} value indicating the type of this message. */ | ||
readonly type: MessageType; | ||
} | ||
/** Defines properties common to all Hub messages relating to a specific invocation. */ | ||
export interface HubInvocationMessage extends HubMessageBase { | ||
/** A {@link MessageHeaders} dictionary containing headers attached to the message. */ | ||
readonly headers?: MessageHeaders; | ||
/** The ID of the invocation relating to this message. | ||
* | ||
* This is expected to be present for {@link StreamInvocationMessage} and {@link CompletionMessage}. It may | ||
* be 'undefined' for an {@link InvocationMessage} if the sender does not expect a response. | ||
*/ | ||
readonly invocationId?: string; | ||
} | ||
/** A hub message representing a non-streaming invocation. */ | ||
export interface InvocationMessage extends HubInvocationMessage { | ||
readonly type: MessageType.Invocation; | ||
/** The target method name. */ | ||
readonly target: string; | ||
/** The target method arguments. */ | ||
readonly arguments: any[]; | ||
} | ||
/** A hub message representing a streaming invocation. */ | ||
export interface StreamInvocationMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.StreamInvocation; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The target method name. */ | ||
readonly target: string; | ||
/** The target method arguments. */ | ||
readonly arguments: any[]; | ||
} | ||
/** A hub message representing a single item produced as part of a result stream. */ | ||
export interface StreamItemMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.StreamItem; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The item produced by the server. */ | ||
readonly item?: any; | ||
} | ||
/** A hub message representing the result of an invocation. */ | ||
export interface CompletionMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Completion; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The error produced by the invocation, if any. | ||
* | ||
* Either {@link error} or {@link result} must be defined, but not both. | ||
*/ | ||
readonly error?: string; | ||
/** The result produced by the invocation, if any. | ||
* | ||
* Either {@link error} or {@link result} must be defined, but not both. | ||
*/ | ||
readonly result?: any; | ||
} | ||
/** A hub message indicating that the sender is still active. */ | ||
export interface PingMessage extends HubMessageBase { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Ping; | ||
} | ||
/** A hub message indicating that the sender is closing the connection. | ||
* | ||
* If {@link error} is defined, the sender is closing the connection due to an error. | ||
*/ | ||
export interface CloseMessage extends HubMessageBase { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Close; | ||
/** The error that triggered the close, if any. | ||
* | ||
* If this property is undefined, the connection was closed normally and without error. | ||
*/ | ||
readonly error?: string; | ||
} | ||
/** A hub message sent to request that a streaming invocation be canceled. */ | ||
export interface CancelInvocationMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.CancelInvocation; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
} | ||
/** A protocol abstraction for communicating with SignalR Hubs. */ | ||
export interface IHubProtocol { | ||
/** The name of the protocol. This is used by SignalR to resolve the protocol between the client and server. */ | ||
readonly name: string; | ||
/** The version of the protocol. */ | ||
readonly version: number; | ||
/** The {@link TransferFormat} of the protocol. */ | ||
readonly transferFormat: TransferFormat; | ||
parseMessages(input: any, logger: ILogger): HubMessage[]; | ||
writeMessage(message: HubMessage): any; | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* If {@link transferFormat} is 'Text', the {@link input} parameter must be a string, otherwise it must be an ArrayBuffer. | ||
* | ||
* @param {string | ArrayBuffer} input A string, or ArrayBuffer containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
parseMessages(input: string | ArrayBuffer, logger: ILogger): HubMessage[]; | ||
/** Writes the specified {@link HubMessage} to a string or ArrayBuffer and returns it. | ||
* | ||
* If {@link transferFormat} is 'Text', the result of this method will be a string, otherwise it will be an ArrayBuffer. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string | ArrayBuffer} A string or ArrayBuffer containing the serialized representation of the message. | ||
*/ | ||
writeMessage(message: HubMessage): string | ArrayBuffer; | ||
} |
// 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. | ||
/** Defines the type of a Hub Message. */ | ||
export var MessageType; | ||
(function (MessageType) { | ||
/** Indicates the message is an Invocation message and implements the {@link InvocationMessage} interface. */ | ||
MessageType[MessageType["Invocation"] = 1] = "Invocation"; | ||
/** Indicates the message is a StreamItem message and implements the {@link StreamItemMessage} interface. */ | ||
MessageType[MessageType["StreamItem"] = 2] = "StreamItem"; | ||
/** Indicates the message is a Completion message and implements the {@link CompletionMessage} interface. */ | ||
MessageType[MessageType["Completion"] = 3] = "Completion"; | ||
/** Indicates the message is a Stream Invocation message and implements the {@link StreamInvocationMessage} interface. */ | ||
MessageType[MessageType["StreamInvocation"] = 4] = "StreamInvocation"; | ||
/** Indicates the message is a Cancel Invocation message and implements the {@link CancelInvocationMessage} interface. */ | ||
MessageType[MessageType["CancelInvocation"] = 5] = "CancelInvocation"; | ||
/** Indicates the message is a Ping message and implements the {@link PingMessage} interface. */ | ||
MessageType[MessageType["Ping"] = 6] = "Ping"; | ||
/** Indicates the message is a Close message and implements the {@link CloseMessage} interface. */ | ||
MessageType[MessageType["Close"] = 7] = "Close"; | ||
})(MessageType || (MessageType = {})); | ||
//# sourceMappingURL=IHubProtocol.js.map |
@@ -0,12 +1,29 @@ | ||
/** Indicates the severity of a log message. | ||
* | ||
* Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc. | ||
*/ | ||
export declare enum LogLevel { | ||
/** Log level for very low severity diagnostic messages. */ | ||
Trace = 0, | ||
/** Log level for low severity diagnostic messages. */ | ||
Debug = 1, | ||
/** Log level for informational diagnostic messages. */ | ||
Information = 2, | ||
/** Log level for diagnostic messages that indicate a non-fatal problem. */ | ||
Warning = 3, | ||
/** Log level for diagnostic messages that indicate a failure in the current operation. */ | ||
Error = 4, | ||
/** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */ | ||
Critical = 5, | ||
/** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */ | ||
None = 6, | ||
} | ||
/** An abstraction that provides a sink for diagnostic messages. */ | ||
export interface ILogger { | ||
/** Called by the framework to emit a diagnostic message. | ||
* | ||
* @param {LogLevel} logLevel The severity level of the message. | ||
* @param {string} message The message. | ||
*/ | ||
log(logLevel: LogLevel, message: string): void; | ||
} |
// 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. | ||
// These values are designed to match the ASP.NET Log Levels since that's the pattern we're emulating here. | ||
/** Indicates the severity of a log message. | ||
* | ||
* Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc. | ||
*/ | ||
export var LogLevel; | ||
(function (LogLevel) { | ||
/** Log level for very low severity diagnostic messages. */ | ||
LogLevel[LogLevel["Trace"] = 0] = "Trace"; | ||
/** Log level for low severity diagnostic messages. */ | ||
LogLevel[LogLevel["Debug"] = 1] = "Debug"; | ||
/** Log level for informational diagnostic messages. */ | ||
LogLevel[LogLevel["Information"] = 2] = "Information"; | ||
/** Log level for diagnostic messages that indicate a non-fatal problem. */ | ||
LogLevel[LogLevel["Warning"] = 3] = "Warning"; | ||
/** Log level for diagnostic messages that indicate a failure in the current operation. */ | ||
LogLevel[LogLevel["Error"] = 4] = "Error"; | ||
/** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */ | ||
LogLevel[LogLevel["Critical"] = 5] = "Critical"; | ||
/** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */ | ||
LogLevel[LogLevel["None"] = 6] = "None"; | ||
})(LogLevel || (LogLevel = {})); | ||
//# sourceMappingURL=ILogger.js.map |
@@ -1,13 +0,16 @@ | ||
export * from "./Errors"; | ||
export * from "./HttpClient"; | ||
export * from "./IHttpConnectionOptions"; | ||
export * from "./HubConnection"; | ||
export * from "./HubConnectionBuilder"; | ||
export * from "./IHubProtocol"; | ||
export * from "./ILogger"; | ||
export * from "./ITransport"; | ||
export * from "./Stream"; | ||
export * from "./Loggers"; | ||
export * from "./JsonHubProtocol"; | ||
/** The version of the SignalR client. */ | ||
export declare const VERSION: string; | ||
export { AbortSignal } from "./AbortController"; | ||
export { HttpError, TimeoutError } from "./Errors"; | ||
export { DefaultHttpClient, HttpClient, HttpRequest, HttpResponse } from "./HttpClient"; | ||
export { IHttpConnectionOptions } from "./IHttpConnectionOptions"; | ||
export { HubConnection } from "./HubConnection"; | ||
export { HubConnectionBuilder } from "./HubConnectionBuilder"; | ||
export { MessageType, MessageHeaders, HubMessage, HubMessageBase, HubInvocationMessage, InvocationMessage, StreamInvocationMessage, StreamItemMessage, CompletionMessage, PingMessage, CloseMessage, CancelInvocationMessage, IHubProtocol } from "./IHubProtocol"; | ||
export { ILogger, LogLevel } from "./ILogger"; | ||
export { HttpTransportType, TransferFormat, ITransport } from "./ITransport"; | ||
export { IStreamSubscriber, IStreamResult, ISubscription } from "./Stream"; | ||
export { NullLogger } from "./Loggers"; | ||
export { JsonHubProtocol } from "./JsonHubProtocol"; | ||
export as namespace signalR; |
// 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. | ||
// Everything that users need to access must be exported here. Including interfaces. | ||
export * from "./Errors"; | ||
export * from "./HttpClient"; | ||
export * from "./HubConnection"; | ||
export * from "./HubConnectionBuilder"; | ||
export * from "./IHubProtocol"; | ||
export * from "./ILogger"; | ||
export * from "./ITransport"; | ||
export * from "./Loggers"; | ||
export * from "./JsonHubProtocol"; | ||
// Version token that will be replaced by the prepack command | ||
/** The version of the SignalR client. */ | ||
export var VERSION = "1.0.0"; | ||
export { HttpError, TimeoutError } from "./Errors"; | ||
export { DefaultHttpClient, HttpClient, HttpResponse } from "./HttpClient"; | ||
export { HubConnection } from "./HubConnection"; | ||
export { HubConnectionBuilder } from "./HubConnectionBuilder"; | ||
export { MessageType } from "./IHubProtocol"; | ||
export { LogLevel } from "./ILogger"; | ||
export { HttpTransportType, TransferFormat } from "./ITransport"; | ||
export { NullLogger } from "./Loggers"; | ||
export { JsonHubProtocol } from "./JsonHubProtocol"; | ||
//# sourceMappingURL=index.js.map |
@@ -0,10 +1,20 @@ | ||
/** Specifies a specific HTTP transport type. */ | ||
export declare enum HttpTransportType { | ||
WebSockets = 0, | ||
ServerSentEvents = 1, | ||
LongPolling = 2, | ||
/** Specifies no transport preference. */ | ||
None = 0, | ||
/** Specifies the WebSockets transport. */ | ||
WebSockets = 1, | ||
/** Specifies the Server-Sent Events transport. */ | ||
ServerSentEvents = 2, | ||
/** Specifies the Long Polling transport. */ | ||
LongPolling = 4, | ||
} | ||
/** Specifies the transfer format for a connection. */ | ||
export declare enum TransferFormat { | ||
/** Specifies that only text data will be transmitted over the connection. */ | ||
Text = 1, | ||
/** Specifies that binary data will be transmitted over the connection. */ | ||
Binary = 2, | ||
} | ||
/** An abstraction over the behavior of transports. This is designed to support the framework and not intended for use by applications. */ | ||
export interface ITransport { | ||
@@ -11,0 +21,0 @@ connect(url: string, transferFormat: TransferFormat): Promise<void>; |
// 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. | ||
// This will be treated as a bit flag in the future, so we keep it using power-of-two values. | ||
/** Specifies a specific HTTP transport type. */ | ||
export var HttpTransportType; | ||
(function (HttpTransportType) { | ||
HttpTransportType[HttpTransportType["WebSockets"] = 0] = "WebSockets"; | ||
HttpTransportType[HttpTransportType["ServerSentEvents"] = 1] = "ServerSentEvents"; | ||
HttpTransportType[HttpTransportType["LongPolling"] = 2] = "LongPolling"; | ||
/** Specifies no transport preference. */ | ||
HttpTransportType[HttpTransportType["None"] = 0] = "None"; | ||
/** Specifies the WebSockets transport. */ | ||
HttpTransportType[HttpTransportType["WebSockets"] = 1] = "WebSockets"; | ||
/** Specifies the Server-Sent Events transport. */ | ||
HttpTransportType[HttpTransportType["ServerSentEvents"] = 2] = "ServerSentEvents"; | ||
/** Specifies the Long Polling transport. */ | ||
HttpTransportType[HttpTransportType["LongPolling"] = 4] = "LongPolling"; | ||
})(HttpTransportType || (HttpTransportType = {})); | ||
/** Specifies the transfer format for a connection. */ | ||
export var TransferFormat; | ||
(function (TransferFormat) { | ||
/** Specifies that only text data will be transmitted over the connection. */ | ||
TransferFormat[TransferFormat["Text"] = 1] = "Text"; | ||
/** Specifies that binary data will be transmitted over the connection. */ | ||
TransferFormat[TransferFormat["Binary"] = 2] = "Binary"; | ||
})(TransferFormat || (TransferFormat = {})); | ||
//# sourceMappingURL=ITransport.js.map |
import { HubMessage, IHubProtocol } from "./IHubProtocol"; | ||
import { ILogger } from "./ILogger"; | ||
import { TransferFormat } from "./ITransport"; | ||
export declare const JSON_HUB_PROTOCOL_NAME: string; | ||
/** Implements the JSON Hub Protocol. */ | ||
export declare class JsonHubProtocol implements IHubProtocol { | ||
/** @inheritDoc */ | ||
readonly name: string; | ||
/** @inheritDoc */ | ||
readonly version: number; | ||
/** @inheritDoc */ | ||
readonly transferFormat: TransferFormat; | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* @param {string} input A string containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
parseMessages(input: string, logger: ILogger): HubMessage[]; | ||
/** Writes the specified {@link HubMessage} to a string and returns it. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string} A string containing the serialized representation of the message. | ||
*/ | ||
writeMessage(message: HubMessage): string; | ||
@@ -11,0 +24,0 @@ private isInvocationMessage(message); |
// 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 { MessageType } from "./IHubProtocol"; | ||
import { LogLevel } from "./ILogger"; | ||
@@ -7,10 +8,23 @@ import { TransferFormat } from "./ITransport"; | ||
import { TextMessageFormat } from "./TextMessageFormat"; | ||
export var JSON_HUB_PROTOCOL_NAME = "json"; | ||
var JSON_HUB_PROTOCOL_NAME = "json"; | ||
/** Implements the JSON Hub Protocol. */ | ||
var JsonHubProtocol = /** @class */ (function () { | ||
function JsonHubProtocol() { | ||
/** @inheritDoc */ | ||
this.name = JSON_HUB_PROTOCOL_NAME; | ||
/** @inheritDoc */ | ||
this.version = 1; | ||
/** @inheritDoc */ | ||
this.transferFormat = TransferFormat.Text; | ||
} | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* @param {string} input A string containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
JsonHubProtocol.prototype.parseMessages = function (input, logger) { | ||
// The interface does allow "ArrayBuffer" to be passed in, but this implementation does not. So let's throw a useful error. | ||
if (typeof input !== "string") { | ||
throw new Error("Invalid input for JSON hub protocol. Expected a string."); | ||
} | ||
if (!input) { | ||
@@ -32,15 +46,15 @@ return []; | ||
switch (parsedMessage.type) { | ||
case 1 /* Invocation */: | ||
case MessageType.Invocation: | ||
this.isInvocationMessage(parsedMessage); | ||
break; | ||
case 2 /* StreamItem */: | ||
case MessageType.StreamItem: | ||
this.isStreamItemMessage(parsedMessage); | ||
break; | ||
case 3 /* Completion */: | ||
case MessageType.Completion: | ||
this.isCompletionMessage(parsedMessage); | ||
break; | ||
case 6 /* Ping */: | ||
case MessageType.Ping: | ||
// Single value, no need to validate | ||
break; | ||
case 7 /* Close */: | ||
case MessageType.Close: | ||
// All optional values, no need to validate | ||
@@ -57,2 +71,7 @@ break; | ||
}; | ||
/** Writes the specified {@link HubMessage} to a string and returns it. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string} A string containing the serialized representation of the message. | ||
*/ | ||
JsonHubProtocol.prototype.writeMessage = function (message) { | ||
@@ -59,0 +78,0 @@ return TextMessageFormat.write(JSON.stringify(message)); |
import { ILogger, LogLevel } from "./ILogger"; | ||
/** A logger that does nothing when log messages are sent to it. */ | ||
export declare class NullLogger implements ILogger { | ||
/** The singleton instance of the {@link NullLogger}. */ | ||
static instance: ILogger; | ||
private constructor(); | ||
/** @inheritDoc */ | ||
log(logLevel: LogLevel, message: string): void; | ||
} |
// 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. | ||
/** A logger that does nothing when log messages are sent to it. */ | ||
var NullLogger = /** @class */ (function () { | ||
function NullLogger() { | ||
} | ||
/** @inheritDoc */ | ||
NullLogger.prototype.log = function (logLevel, message) { | ||
}; | ||
/** The singleton instance of the {@link NullLogger}. */ | ||
NullLogger.instance = new NullLogger(); | ||
@@ -9,0 +12,0 @@ return NullLogger; |
@@ -12,5 +12,8 @@ import { HttpClient } from "./HttpClient"; | ||
private pollAbort; | ||
private shutdownTimer; | ||
private shutdownTimeout; | ||
private running; | ||
constructor(httpClient: HttpClient, accessTokenFactory: () => string | Promise<string>, logger: ILogger, logMessageContent: boolean); | ||
private stopped; | ||
readonly pollAborted: boolean; | ||
constructor(httpClient: HttpClient, accessTokenFactory: () => string | Promise<string>, logger: ILogger, logMessageContent: boolean, shutdownTimeout?: number); | ||
connect(url: string, transferFormat: TransferFormat): Promise<void>; | ||
@@ -17,0 +20,0 @@ private updateHeaderToken(request, token); |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { AbortController } from "./AbortController"; | ||
@@ -44,4 +10,5 @@ import { HttpError, TimeoutError } from "./Errors"; | ||
var SHUTDOWN_TIMEOUT = 5 * 1000; | ||
// Not exported from 'index', this type is internal. | ||
var LongPollingTransport = /** @class */ (function () { | ||
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent) { | ||
function LongPollingTransport(httpClient, accessTokenFactory, logger, logMessageContent, shutdownTimeout) { | ||
this.httpClient = httpClient; | ||
@@ -52,7 +19,16 @@ this.accessTokenFactory = accessTokenFactory || (function () { return null; }); | ||
this.logMessageContent = logMessageContent; | ||
this.shutdownTimeout = shutdownTimeout || SHUTDOWN_TIMEOUT; | ||
} | ||
Object.defineProperty(LongPollingTransport.prototype, "pollAborted", { | ||
// This is an internal type, not exported from 'index' so this is really just internal. | ||
get: function () { | ||
return this.pollAbort.aborted; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
LongPollingTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var pollOptions, token, closeError, pollUrl, response; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -114,5 +90,5 @@ case 0: | ||
LongPollingTransport.prototype.poll = function (url, pollOptions, closeError) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var token, pollUrl, response, e_1; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -138,4 +114,2 @@ case 0: | ||
this.logger.log(LogLevel.Information, "(LongPolling transport) Poll terminated by server"); | ||
// If we were on a timeout waiting for shutdown, unregister it. | ||
clearTimeout(this.shutdownTimeout); | ||
this.running = false; | ||
@@ -184,2 +158,8 @@ } | ||
case 8: | ||
// Indicate that we've stopped so the shutdown timer doesn't get registered. | ||
this.stopped = true; | ||
// Clean up the shutdown timer if it was registered | ||
if (this.shutdownTimer) { | ||
clearTimeout(this.shutdownTimer); | ||
} | ||
// Fire our onclosed event | ||
@@ -198,4 +178,4 @@ if (this.onclose) { | ||
LongPollingTransport.prototype.send = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (!this.running) { | ||
@@ -209,6 +189,6 @@ return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; | ||
LongPollingTransport.prototype.stop = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var deleteOptions, token, response; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -232,8 +212,9 @@ case 0: | ||
case 3: | ||
// Abort the poll after 5 seconds if the server doesn't stop it. | ||
if (!this.pollAbort.aborted) { | ||
this.shutdownTimeout = setTimeout(SHUTDOWN_TIMEOUT, function () { | ||
_this.logger.log(LogLevel.Warning, "(LongPolling transport) server did not terminate within 5 seconds after DELETE request, cancelling poll."); | ||
// Abort the poll after the shutdown timeout if the server doesn't stop the poll. | ||
if (!this.stopped) { | ||
this.shutdownTimer = setTimeout(function () { | ||
_this.logger.log(LogLevel.Warning, "(LongPolling transport) server did not terminate after DELETE request, canceling poll."); | ||
// Abort any outstanding poll | ||
_this.pollAbort.abort(); | ||
}); | ||
}, this.shutdownTimeout); | ||
} | ||
@@ -240,0 +221,0 @@ return [7 /*endfinally*/]; |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { LogLevel } from "./ILogger"; | ||
@@ -49,6 +15,6 @@ import { TransferFormat } from "./ITransport"; | ||
ServerSentEventsTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var token; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -116,4 +82,4 @@ case 0: | ||
ServerSentEventsTransport.prototype.send = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { | ||
if (!this.eventSource) { | ||
@@ -120,0 +86,0 @@ return [2 /*return*/, Promise.reject(new Error("Cannot send until the transport is connected"))]; |
@@ -0,12 +1,40 @@ | ||
/** Defines the expected type for a receiver of results streamed by the server. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface IStreamSubscriber<T> { | ||
/** A boolean that will be set by the {@link IStreamResult} when the stream is closed. */ | ||
closed?: boolean; | ||
/** Called by the framework when a new item is available. */ | ||
next(value: T): void; | ||
/** Called by the framework when an error has occurred. | ||
* | ||
* After this method is called, no additional methods on the {@link IStreamSubscriber} will be called. | ||
*/ | ||
error(err: any): void; | ||
/** Called by the framework when the end of the stream is reached. | ||
* | ||
* After this method is called, no additional methods on the {@link IStreamSubscriber} will be called. | ||
*/ | ||
complete(): void; | ||
} | ||
/** Defines the result of a streaming hub method. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface IStreamResult<T> { | ||
subscribe(observer: IStreamSubscriber<T>): ISubscription<T>; | ||
/** Attaches a {@link IStreamSubscriber}, which will be invoked when new items are available from the stream. | ||
* | ||
* @param {IStreamSubscriber<T>} observer The subscriber to attach. | ||
* @returns {ISubscription<T>} A subscription that can be disposed to terminate the stream and stop calling methods on the {@link IStreamSubscriber}. | ||
*/ | ||
subscribe(subscriber: IStreamSubscriber<T>): ISubscription<T>; | ||
} | ||
/** An interface that allows an {@link IStreamSubscriber} to be disconnected from a stream. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface ISubscription<T> { | ||
/** Disconnects the {@link IStreamSubscriber} associated with this subscription from the stream. */ | ||
dispose(): void; | ||
} |
// 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. | ||
// Not exported from index | ||
var TextMessageFormat = /** @class */ (function () { | ||
@@ -4,0 +5,0 @@ function TextMessageFormat() { |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { LogLevel } from "./ILogger"; | ||
@@ -85,5 +51,5 @@ import { NullLogger } from "./Loggers"; | ||
export function sendMessage(logger, transportName, httpClient, url, accessTokenFactory, content, logMessageContent) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var headers, token, response, _a; | ||
return __generator(this, function (_b) { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
@@ -90,0 +56,0 @@ case 0: return [4 /*yield*/, accessTokenFactory()]; |
// 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. | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import * as tslib_1 from "tslib"; | ||
import { LogLevel } from "./ILogger"; | ||
@@ -48,6 +14,6 @@ import { TransferFormat } from "./ITransport"; | ||
WebSocketTransport.prototype.connect = function (url, transferFormat) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
var token; | ||
return __generator(this, function (_a) { | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
@@ -54,0 +20,0 @@ case 0: |
{ | ||
"_from": "@aspnet/signalr", | ||
"_id": "@aspnet/signalr@1.0.0-rc1-final", | ||
"_inBundle": false, | ||
"_integrity": "sha1-Etuhpjuzyf00iEiJxjan5k/cHc4=", | ||
"_location": "/@aspnet/signalr", | ||
"_phantomChildren": {}, | ||
"_requested": { | ||
"type": "tag", | ||
"registry": true, | ||
"raw": "@aspnet/signalr", | ||
"name": "@aspnet/signalr", | ||
"escapedName": "@aspnet%2fsignalr", | ||
"scope": "@aspnet", | ||
"rawSpec": "", | ||
"saveSpec": null, | ||
"fetchSpec": "latest" | ||
"name": "@aspnet/signalr", | ||
"version": "1.0.0", | ||
"description": "ASP.NET Core SignalR Client", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"typings": "./dist/esm/index.d.ts", | ||
"umd": "./dist/browser/signalr.js", | ||
"umd_name": "signalR", | ||
"directories": { | ||
"test": "spec" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/@aspnet/signalr/-/signalr-1.0.0-rc1-final.tgz", | ||
"_shasum": "12dba1a63bb3c9fd34884889c636a7e64fdc1dce", | ||
"_spec": "@aspnet/signalr", | ||
"_where": "C:\\users\\anurse\\Desktop\\temp", | ||
"author": { | ||
"name": "Microsoft" | ||
"scripts": { | ||
"clean": "node ../node_modules/rimraf/bin.js ./dist", | ||
"build": "npm run clean && npm run build:lint && npm run build:esm && npm run build:cjs && npm run build:browser && npm run build:uglify", | ||
"build:lint": "node ../node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json", | ||
"build:esm": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d && node ./build/process-dts.js", | ||
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs", | ||
"build:browser": "node ../node_modules/rollup/bin/rollup -c", | ||
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js", | ||
"prepack": "node ../build/embed-version.js", | ||
"test": "echo \"Run 'npm test' in the 'clients\\ts' folder to test this package\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/aspnet/SignalR.git" | ||
}, | ||
"author": "Microsoft", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/aspnet/SignalR/issues" | ||
}, | ||
"bundleDependencies": false, | ||
"deprecated": false, | ||
"description": "ASP.NET Core SignalR Client", | ||
"devDependencies": { | ||
"es6-promise": "^4.2.2" | ||
}, | ||
"directories": { | ||
"test": "spec" | ||
}, | ||
"homepage": "https://github.com/aspnet/SignalR#readme", | ||
"files": [ | ||
@@ -46,26 +38,5 @@ "dist/**/*", | ||
], | ||
"homepage": "https://github.com/aspnet/SignalR#readme", | ||
"license": "Apache-2.0", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"name": "@aspnet/signalr", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/aspnet/SignalR.git" | ||
}, | ||
"scripts": { | ||
"build": "npm run clean && npm run build:lint && npm run build:esm && npm run build:cjs && npm run build:browser && npm run build:uglify", | ||
"build:browser": "node ../node_modules/rollup/bin/rollup -c", | ||
"build:cjs": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs --target ES5", | ||
"build:esm": "node ../node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm --target ES5 -d && node ./build/process-dts.js", | ||
"build:lint": "node ../node_modules/tslint/bin/tslint -c ../tslint.json -p ./tsconfig.json", | ||
"build:uglify": "node ../node_modules/uglify-js/bin/uglifyjs --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js", | ||
"clean": "node ../node_modules/rimraf/bin.js ./dist ./.rpt2_cache", | ||
"pretest": "node ../node_modules/rimraf/bin.js ./spec/obj && node ../node_modules/typescript/bin/tsc --project ./spec/tsconfig.json", | ||
"test": "node ../node_modules/jasmine/bin/jasmine.js ./spec/obj/spec/**/*.spec.js" | ||
}, | ||
"typings": "./dist/esm/index.d.ts", | ||
"umd": "./dist/browser/signalr.js", | ||
"umd_name": "signalR", | ||
"version": "1.0.0-rc1-update1" | ||
"devDependencies": { | ||
"es6-promise": "^4.2.2" | ||
} | ||
} |
@@ -8,2 +8,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
// Not exported from index. | ||
export class AbortController implements AbortSignal { | ||
@@ -31,5 +32,8 @@ private isAborted: boolean = false; | ||
/** Represents a signal that can be monitored to determine if a request has been aborted. */ | ||
export interface AbortSignal { | ||
/** Indicates if the request has been aborted. */ | ||
aborted: boolean; | ||
/** Set this to a handler that will be invoked when the request is aborted. */ | ||
onabort: () => void; | ||
} |
// 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. | ||
/** Error thrown when an HTTP request fails. */ | ||
export class HttpError extends Error { | ||
// tslint:disable-next-line:variable-name | ||
private __proto__: Error; | ||
/** The HTTP status code represented by this error. */ | ||
public statusCode: number; | ||
/** Constructs a new instance of {@link HttpError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
* @param {number} statusCode The HTTP status code represented by this error. | ||
*/ | ||
constructor(errorMessage: string, statusCode: number) { | ||
@@ -19,5 +28,11 @@ const trueProto = new.target.prototype; | ||
/** Error thrown when a timeout elapses. */ | ||
export class TimeoutError extends Error { | ||
// tslint:disable-next-line:variable-name | ||
private __proto__: Error; | ||
/** Constructs a new instance of {@link TimeoutError}. | ||
* | ||
* @param {string} errorMessage A descriptive error message. | ||
*/ | ||
constructor(errorMessage: string = "A timeout occurred.") { | ||
@@ -24,0 +39,0 @@ const trueProto = new.target.prototype; |
@@ -8,16 +8,55 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** Represents an HTTP request. */ | ||
export interface HttpRequest { | ||
/** The HTTP method to use for the request. */ | ||
method?: string; | ||
/** The URL for the request. */ | ||
url?: string; | ||
/** The body content for the request. May be a string or an ArrayBuffer (for binary data). */ | ||
content?: string | ArrayBuffer; | ||
/** An object describing headers to apply to the request. */ | ||
headers?: { [key: string]: string }; | ||
/** The XMLHttpRequestResponseType to apply to the request. */ | ||
responseType?: XMLHttpRequestResponseType; | ||
/** An AbortSignal that can be monitored for cancellation. */ | ||
abortSignal?: AbortSignal; | ||
/** The time to wait for the request to complete before throwing a TimeoutError. Measured in milliseconds. */ | ||
timeout?: number; | ||
} | ||
/** Represents an HTTP response. */ | ||
export class HttpResponse { | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
*/ | ||
constructor(statusCode: number); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code and message. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code, message and string content. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
* @param {string} content The content of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string, content: string); | ||
/** Constructs a new instance of {@link HttpResponse} with the specified status code, message and binary content. | ||
* | ||
* @param {number} statusCode The status code of the response. | ||
* @param {string} statusText The status message of the response. | ||
* @param {ArrayBuffer} content The content of the response. | ||
*/ | ||
constructor(statusCode: number, statusText: string, content: ArrayBuffer); | ||
@@ -31,4 +70,20 @@ constructor( | ||
/** Abstraction over an HTTP client. | ||
* | ||
* This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms. | ||
*/ | ||
export abstract class HttpClient { | ||
/** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public get(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP GET request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public get(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
@@ -43,3 +98,15 @@ public get(url: string, options?: HttpRequest): Promise<HttpResponse> { | ||
/** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public post(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP POST request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public post(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
@@ -54,3 +121,15 @@ public post(url: string, options?: HttpRequest): Promise<HttpResponse> { | ||
/** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public delete(url: string): Promise<HttpResponse>; | ||
/** Issues an HTTP DELETE request to the specified URL, returning a Promise that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {string} url The URL for the request. | ||
* @param {HttpRequest} options Additional options to configure the request. The 'url' field in this object will be overridden by the url parameter. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an {@link HttpResponse} describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public delete(url: string, options: HttpRequest): Promise<HttpResponse>; | ||
@@ -65,9 +144,16 @@ public delete(url: string, options?: HttpRequest): Promise<HttpResponse> { | ||
/** Issues an HTTP request to the specified URL, returning a {@link Promise} that resolves with an {@link HttpResponse} representing the result. | ||
* | ||
* @param {HttpRequest} request An {@link HttpRequest} describing the request to send. | ||
* @returns {Promise<HttpResponse>} A Promise that resolves with an HttpResponse describing the response, or rejects with an Error indicating a failure. | ||
*/ | ||
public abstract send(request: HttpRequest): Promise<HttpResponse>; | ||
} | ||
/** Default implementation of {@link HttpClient}. */ | ||
export class DefaultHttpClient extends HttpClient { | ||
private readonly logger: ILogger; | ||
constructor(logger: ILogger) { | ||
/** Creates a new instance of the {@link DefaultHttpClient}, using the provided {@link ILogger} to log messages. */ | ||
public constructor(logger: ILogger) { | ||
super(); | ||
@@ -77,2 +163,3 @@ this.logger = logger; | ||
/** @inheritDoc */ | ||
public send(request: HttpRequest): Promise<HttpResponse> { | ||
@@ -79,0 +166,0 @@ return new Promise<HttpResponse>((resolve, reject) => { |
@@ -20,10 +20,10 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
interface INegotiateResponse { | ||
connectionId: string; | ||
availableTransports: IAvailableTransport[]; | ||
url: string; | ||
accessToken: string; | ||
export interface INegotiateResponse { | ||
connectionId?: string; | ||
availableTransports?: IAvailableTransport[]; | ||
url?: string; | ||
accessToken?: string; | ||
} | ||
interface IAvailableTransport { | ||
export interface IAvailableTransport { | ||
transport: keyof typeof HttpTransportType; | ||
@@ -266,3 +266,3 @@ transferFormats: Array<keyof typeof TransferFormat>; | ||
const transferFormats = endpoint.transferFormats.map((s) => TransferFormat[s]); | ||
if (!requestedTransport || transport === requestedTransport) { | ||
if (transportMatches(requestedTransport, transport)) { | ||
if (transferFormats.indexOf(requestedTransferFormat) >= 0) { | ||
@@ -287,3 +287,3 @@ if ((transport === HttpTransportType.WebSockets && typeof WebSocket === "undefined") || | ||
private isITransport(transport: any): transport is ITransport { | ||
return typeof (transport) === "object" && "connect" in transport; | ||
return transport && typeof (transport) === "object" && "connect" in transport; | ||
} | ||
@@ -351,1 +351,5 @@ | ||
} | ||
function transportMatches(requestedTransport: HttpTransportType, actualTransport: HttpTransportType) { | ||
return !requestedTransport || ((actualTransport & requestedTransport) !== 0); | ||
} |
@@ -13,2 +13,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** Represents a connection to a SignalR Hub. */ | ||
export class HubConnection { | ||
@@ -26,2 +27,7 @@ private readonly connection: IConnection; | ||
/** The server timeout in milliseconds. | ||
* | ||
* If this timeout elapses without receiving any messages from the server, the connection will be terminated with an error. | ||
* The default timeout value is 30,000 milliseconds (30 seconds). | ||
*/ | ||
public serverTimeoutInMilliseconds: number; | ||
@@ -59,2 +65,6 @@ | ||
/** Starts the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error. | ||
*/ | ||
public async start(): Promise<void> { | ||
@@ -83,2 +93,6 @@ const handshakeRequest: HandshakeRequestMessage = { | ||
/** Stops the connection. | ||
* | ||
* @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error. | ||
*/ | ||
public stop(): Promise<void> { | ||
@@ -91,2 +105,9 @@ this.logger.log(LogLevel.Debug, "Stopping HubConnection."); | ||
/** Invokes a streaming hub method on the server using the specified name and arguments. | ||
* | ||
* @typeparam T The type of the items returned by the server. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {IStreamResult<T>} An object that yields results from the server as they are received. | ||
*/ | ||
public stream<T = any>(methodName: string, ...args: any[]): IStreamResult<T> { | ||
@@ -132,2 +153,11 @@ const invocationDescriptor = this.createStreamInvocation(methodName, args); | ||
/** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver. | ||
* | ||
* The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still | ||
* be processing the invocation. | ||
* | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error. | ||
*/ | ||
public send(methodName: string, ...args: any[]): Promise<void> { | ||
@@ -141,2 +171,13 @@ const invocationDescriptor = this.createInvocation(methodName, args, true); | ||
/** Invokes a hub method on the server using the specified name and arguments. | ||
* | ||
* The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise | ||
* resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of | ||
* resolving the Promise. | ||
* | ||
* @typeparam T The expected return type. | ||
* @param {string} methodName The name of the server method to invoke. | ||
* @param {any[]} args The arguments used to invoke the server method. | ||
* @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error. | ||
*/ | ||
public invoke<T = any>(methodName: string, ...args: any[]): Promise<T> { | ||
@@ -175,2 +216,7 @@ const invocationDescriptor = this.createInvocation(methodName, args, false); | ||
/** Registers a handler that will be invoked when the hub method with the specified method name is invoked. | ||
* | ||
* @param {string} methodName The name of the hub method to define. | ||
* @param {Function} newMethod The handler that will be raised when the hub method is invoked. | ||
*/ | ||
public on(methodName: string, newMethod: (...args: any[]) => void) { | ||
@@ -194,3 +240,18 @@ if (!methodName || !newMethod) { | ||
public off(methodName: string, method?: (...args: any[]) => void) { | ||
/** Removes all handlers for the specified hub method. | ||
* | ||
* @param {string} methodName The name of the method to remove handlers for. | ||
*/ | ||
public off(methodName: string): void; | ||
/** Removes the specified handler for the specified hub method. | ||
* | ||
* You must pass the exact same Function instance as was previously passed to {@link on}. Passing a different instance (even if the function | ||
* body is the same) will not remove the handler. | ||
* | ||
* @param {string} methodName The name of the method to remove handlers for. | ||
* @param {Function} method The handler to remove. This must be the same Function instance as the one passed to {@link on}. | ||
*/ | ||
public off(methodName: string, method: (...args: any[]) => void): void; | ||
public off(methodName: string, method?: (...args: any[]) => void): void { | ||
if (!methodName) { | ||
@@ -219,2 +280,6 @@ return; | ||
/** Registers a handler that will be invoked when the connection is closed. | ||
* | ||
* @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). | ||
*/ | ||
public onclose(callback: (error?: Error) => void) { | ||
@@ -221,0 +286,0 @@ if (callback) { |
@@ -14,2 +14,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** A builder for configuring {@link HubConnection} instances. */ | ||
export class HubConnectionBuilder { | ||
@@ -25,2 +26,15 @@ /** @internal */ | ||
/** Configures console logging for the {@link HubConnection}. | ||
* | ||
* @param {LogLevel} logLevel The minimum level of messages to log. Anything at this level, or a more severe level, will be logged. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
public configureLogging(logLevel: LogLevel): HubConnectionBuilder; | ||
/** Configures custom logging for the {@link HubConnection}. | ||
* | ||
* @param {ILogger} logger An object implementing the {@link ILogger} interface, which will be used to write all log messages. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
public configureLogging(logger: ILogger): HubConnectionBuilder; | ||
public configureLogging(logging: LogLevel | ILogger): HubConnectionBuilder { | ||
@@ -38,5 +52,26 @@ Arg.isRequired(logging, "logging"); | ||
/** Configures the {@link HubConnection} to use HTTP-based transports to connect to the specified URL. | ||
* | ||
* The transport will be selected automatically based on what the server and client support. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
public withUrl(url: string): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use the specified HTTP-based transport to connect to the specified URL. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @param {HttpTransportType} transportType The specific transport to use. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
public withUrl(url: string, transportType: HttpTransportType): HubConnectionBuilder; | ||
/** Configures the {@link HubConnection} to use HTTP-based transports to connect to the specified URL. | ||
* | ||
* @param {string} url The URL the connection will use. | ||
* @param {IHttpConnectionOptions} options An options object used to configure the connection. | ||
* @returns The {@link HubConnectionBuilder} instance, for chaining. | ||
*/ | ||
public withUrl(url: string, options: IHttpConnectionOptions): HubConnectionBuilder; | ||
public withUrl(url: string, transportType: HttpTransportType): HubConnectionBuilder; | ||
public withUrl(url: string, transportTypeOrOptions?: IHttpConnectionOptions | HttpTransportType): HubConnectionBuilder { | ||
@@ -60,2 +95,6 @@ Arg.isRequired(url, "url"); | ||
/** Configures the {@link HubConnection} to use the specified Hub Protocol. | ||
* | ||
* @param {IHubProtocol} protocol The {@link IHubProtocol} implementation to use. | ||
*/ | ||
public withHubProtocol(protocol: IHubProtocol): HubConnectionBuilder { | ||
@@ -68,2 +107,6 @@ Arg.isRequired(protocol, "protocol"); | ||
/** Creates a {@link HubConnection} from the configuration options specified in this builder. | ||
* | ||
* @returns {HubConnection} The configured {@link HubConnection}. | ||
*/ | ||
public build(): HubConnection { | ||
@@ -70,0 +113,0 @@ // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one |
@@ -8,9 +8,35 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** Options provided to the 'withUrl' method on {@link HubConnectionBuilder} to configure options for the HTTP-based transports. */ | ||
export interface IHttpConnectionOptions { | ||
/** An {@link HttpClient} that will be used to make HTTP requests. */ | ||
httpClient?: HttpClient; | ||
/** An {@link HttpTransportType} value specifying the transport to use for the connection. */ | ||
transport?: HttpTransportType | ITransport; | ||
/** Configures the logger used for logging. | ||
* | ||
* Provide an {@link ILogger} instance, and log messages will be logged via that instance. Alternatively, provide a value from | ||
* the {@link LogLevel} enumeration and a default logger which logs to the Console will be configured to log messages of the specified | ||
* level (or higher). | ||
*/ | ||
logger?: ILogger | LogLevel; | ||
accessTokenFactory?: () => string | Promise<string>; | ||
/** A function that provides an access token required for HTTP Bearer authentication. | ||
* | ||
* @returns {string | Promise<string>} A string containing the access token, or a Promise that resolves to a string containing the access token. | ||
*/ | ||
accessTokenFactory?(): string | Promise<string>; | ||
/** A boolean indicating if message content should be logged. | ||
* | ||
* Message content can contain sensitive user data, so this is disabled by default. | ||
*/ | ||
logMessageContent?: boolean; | ||
/** A boolean indicating if negotiation should be skipped. | ||
* | ||
* Negotiation can only be skipped when the {@link transport} property is set to 'HttpTransportType.WebSockets'. | ||
*/ | ||
skipNegotiation?: boolean; | ||
} |
@@ -7,67 +7,160 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
export const enum MessageType { | ||
/** Defines the type of a Hub Message. */ | ||
export enum MessageType { | ||
/** Indicates the message is an Invocation message and implements the {@link InvocationMessage} interface. */ | ||
Invocation = 1, | ||
/** Indicates the message is a StreamItem message and implements the {@link StreamItemMessage} interface. */ | ||
StreamItem = 2, | ||
/** Indicates the message is a Completion message and implements the {@link CompletionMessage} interface. */ | ||
Completion = 3, | ||
/** Indicates the message is a Stream Invocation message and implements the {@link StreamInvocationMessage} interface. */ | ||
StreamInvocation = 4, | ||
/** Indicates the message is a Cancel Invocation message and implements the {@link CancelInvocationMessage} interface. */ | ||
CancelInvocation = 5, | ||
/** Indicates the message is a Ping message and implements the {@link PingMessage} interface. */ | ||
Ping = 6, | ||
/** Indicates the message is a Close message and implements the {@link CloseMessage} interface. */ | ||
Close = 7, | ||
} | ||
export interface MessageHeaders { [key: string]: string; } | ||
/** Defines a dictionary of string keys and string values representing headers attached to a Hub message. */ | ||
export interface MessageHeaders { | ||
/** Gets or sets the header with the specified key. */ | ||
[key: string]: string; | ||
} | ||
export type HubMessage = InvocationMessage | StreamInvocationMessage | StreamItemMessage | CompletionMessage | CancelInvocationMessage | PingMessage | CloseMessage; | ||
/** Union type of all known Hub messages. */ | ||
export type HubMessage = | ||
InvocationMessage | | ||
StreamInvocationMessage | | ||
StreamItemMessage | | ||
CompletionMessage | | ||
CancelInvocationMessage | | ||
PingMessage | | ||
CloseMessage; | ||
/** Defines properties common to all Hub messages. */ | ||
export interface HubMessageBase { | ||
/** A {@link MessageType} value indicating the type of this message. */ | ||
readonly type: MessageType; | ||
} | ||
/** Defines properties common to all Hub messages relating to a specific invocation. */ | ||
export interface HubInvocationMessage extends HubMessageBase { | ||
/** A {@link MessageHeaders} dictionary containing headers attached to the message. */ | ||
readonly headers?: MessageHeaders; | ||
/** The ID of the invocation relating to this message. | ||
* | ||
* This is expected to be present for {@link StreamInvocationMessage} and {@link CompletionMessage}. It may | ||
* be 'undefined' for an {@link InvocationMessage} if the sender does not expect a response. | ||
*/ | ||
readonly invocationId?: string; | ||
} | ||
/** A hub message representing a non-streaming invocation. */ | ||
export interface InvocationMessage extends HubInvocationMessage { | ||
readonly type: MessageType.Invocation; | ||
/** The target method name. */ | ||
readonly target: string; | ||
/** The target method arguments. */ | ||
readonly arguments: any[]; | ||
} | ||
/** A hub message representing a streaming invocation. */ | ||
export interface StreamInvocationMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.StreamInvocation; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The target method name. */ | ||
readonly target: string; | ||
/** The target method arguments. */ | ||
readonly arguments: any[]; | ||
} | ||
/** A hub message representing a single item produced as part of a result stream. */ | ||
export interface StreamItemMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.StreamItem; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The item produced by the server. */ | ||
readonly item?: any; | ||
} | ||
/** A hub message representing the result of an invocation. */ | ||
export interface CompletionMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Completion; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
/** The error produced by the invocation, if any. | ||
* | ||
* Either {@link error} or {@link result} must be defined, but not both. | ||
*/ | ||
readonly error?: string; | ||
/** The result produced by the invocation, if any. | ||
* | ||
* Either {@link error} or {@link result} must be defined, but not both. | ||
*/ | ||
readonly result?: any; | ||
} | ||
/** A hub message indicating that the sender is still active. */ | ||
export interface PingMessage extends HubMessageBase { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Ping; | ||
} | ||
/** A hub message indicating that the sender is closing the connection. | ||
* | ||
* If {@link error} is defined, the sender is closing the connection due to an error. | ||
*/ | ||
export interface CloseMessage extends HubMessageBase { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.Close; | ||
/** The error that triggered the close, if any. | ||
* | ||
* If this property is undefined, the connection was closed normally and without error. | ||
*/ | ||
readonly error?: string; | ||
} | ||
/** A hub message sent to request that a streaming invocation be canceled. */ | ||
export interface CancelInvocationMessage extends HubInvocationMessage { | ||
/** @inheritDoc */ | ||
readonly type: MessageType.CancelInvocation; | ||
/** The invocation ID. */ | ||
readonly invocationId: string; | ||
} | ||
/** A protocol abstraction for communicating with SignalR Hubs. */ | ||
export interface IHubProtocol { | ||
/** The name of the protocol. This is used by SignalR to resolve the protocol between the client and server. */ | ||
readonly name: string; | ||
/** The version of the protocol. */ | ||
readonly version: number; | ||
/** The {@link TransferFormat} of the protocol. */ | ||
readonly transferFormat: TransferFormat; | ||
parseMessages(input: any, logger: ILogger): HubMessage[]; | ||
writeMessage(message: HubMessage): any; | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* If {@link transferFormat} is 'Text', the {@link input} parameter must be a string, otherwise it must be an ArrayBuffer. | ||
* | ||
* @param {string | ArrayBuffer} input A string, or ArrayBuffer containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
parseMessages(input: string | ArrayBuffer, logger: ILogger): HubMessage[]; | ||
/** Writes the specified {@link HubMessage} to a string or ArrayBuffer and returns it. | ||
* | ||
* If {@link transferFormat} is 'Text', the result of this method will be a string, otherwise it will be an ArrayBuffer. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string | ArrayBuffer} A string or ArrayBuffer containing the serialized representation of the message. | ||
*/ | ||
writeMessage(message: HubMessage): string | ArrayBuffer; | ||
} |
@@ -5,14 +5,31 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
// These values are designed to match the ASP.NET Log Levels since that's the pattern we're emulating here. | ||
/** Indicates the severity of a log message. | ||
* | ||
* Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc. | ||
*/ | ||
export enum LogLevel { | ||
/** Log level for very low severity diagnostic messages. */ | ||
Trace = 0, | ||
/** Log level for low severity diagnostic messages. */ | ||
Debug = 1, | ||
/** Log level for informational diagnostic messages. */ | ||
Information = 2, | ||
/** Log level for diagnostic messages that indicate a non-fatal problem. */ | ||
Warning = 3, | ||
/** Log level for diagnostic messages that indicate a failure in the current operation. */ | ||
Error = 4, | ||
/** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */ | ||
Critical = 5, | ||
/** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */ | ||
None = 6, | ||
} | ||
/** An abstraction that provides a sink for diagnostic messages. */ | ||
export interface ILogger { | ||
/** Called by the framework to emit a diagnostic message. | ||
* | ||
* @param {LogLevel} logLevel The severity level of the message. | ||
* @param {string} message The message. | ||
*/ | ||
log(logLevel: LogLevel, message: string): void; | ||
} |
// 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. | ||
// Version token that will be replaced by the prepack command | ||
/** The version of the SignalR client. */ | ||
export const VERSION: string = "0.0.0-DEV_BUILD"; | ||
// Everything that users need to access must be exported here. Including interfaces. | ||
export * from "./Errors"; | ||
export * from "./HttpClient"; | ||
export * from "./IHttpConnectionOptions"; | ||
export * from "./HubConnection"; | ||
export * from "./HubConnectionBuilder"; | ||
export * from "./IHubProtocol"; | ||
export * from "./ILogger"; | ||
export * from "./ITransport"; | ||
export * from "./Stream"; | ||
export * from "./Loggers"; | ||
export * from "./JsonHubProtocol"; | ||
export { AbortSignal } from "./AbortController"; | ||
export { HttpError, TimeoutError } from "./Errors"; | ||
export { DefaultHttpClient, HttpClient, HttpRequest, HttpResponse } from "./HttpClient"; | ||
export { IHttpConnectionOptions } from "./IHttpConnectionOptions"; | ||
export { HubConnection } from "./HubConnection"; | ||
export { HubConnectionBuilder } from "./HubConnectionBuilder"; | ||
export { MessageType, MessageHeaders, HubMessage, HubMessageBase, HubInvocationMessage, InvocationMessage, StreamInvocationMessage, StreamItemMessage, CompletionMessage, PingMessage, CloseMessage, CancelInvocationMessage, IHubProtocol } from "./IHubProtocol"; | ||
export { ILogger, LogLevel } from "./ILogger"; | ||
export { HttpTransportType, TransferFormat, ITransport } from "./ITransport"; | ||
export { IStreamSubscriber, IStreamResult, ISubscription } from "./Stream"; | ||
export { NullLogger } from "./Loggers"; | ||
export { JsonHubProtocol } from "./JsonHubProtocol"; |
// 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. | ||
// This will be treated as a bit flag in the future, so we keep it using power-of-two values. | ||
/** Specifies a specific HTTP transport type. */ | ||
export enum HttpTransportType { | ||
WebSockets, | ||
ServerSentEvents, | ||
LongPolling, | ||
/** Specifies no transport preference. */ | ||
None = 0, | ||
/** Specifies the WebSockets transport. */ | ||
WebSockets = 1, | ||
/** Specifies the Server-Sent Events transport. */ | ||
ServerSentEvents = 2, | ||
/** Specifies the Long Polling transport. */ | ||
LongPolling = 4, | ||
} | ||
/** Specifies the transfer format for a connection. */ | ||
export enum TransferFormat { | ||
/** Specifies that only text data will be transmitted over the connection. */ | ||
Text = 1, | ||
/** Specifies that binary data will be transmitted over the connection. */ | ||
Binary, | ||
} | ||
/** An abstraction over the behavior of transports. This is designed to support the framework and not intended for use by applications. */ | ||
export interface ITransport { | ||
@@ -16,0 +27,0 @@ connect(url: string, transferFormat: TransferFormat): Promise<void>; |
@@ -10,12 +10,26 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
export const JSON_HUB_PROTOCOL_NAME: string = "json"; | ||
const JSON_HUB_PROTOCOL_NAME: string = "json"; | ||
/** Implements the JSON Hub Protocol. */ | ||
export class JsonHubProtocol implements IHubProtocol { | ||
/** @inheritDoc */ | ||
public readonly name: string = JSON_HUB_PROTOCOL_NAME; | ||
/** @inheritDoc */ | ||
public readonly version: number = 1; | ||
/** @inheritDoc */ | ||
public readonly transferFormat: TransferFormat = TransferFormat.Text; | ||
/** Creates an array of {@link HubMessage} objects from the specified serialized representation. | ||
* | ||
* @param {string} input A string containing the serialized representation. | ||
* @param {ILogger} logger A logger that will be used to log messages that occur during parsing. | ||
*/ | ||
public parseMessages(input: string, logger: ILogger): HubMessage[] { | ||
// The interface does allow "ArrayBuffer" to be passed in, but this implementation does not. So let's throw a useful error. | ||
if (typeof input !== "string") { | ||
throw new Error("Invalid input for JSON hub protocol. Expected a string."); | ||
} | ||
if (!input) { | ||
@@ -65,2 +79,7 @@ return []; | ||
/** Writes the specified {@link HubMessage} to a string and returns it. | ||
* | ||
* @param {HubMessage} message The message to write. | ||
* @returns {string} A string containing the serialized representation of the message. | ||
*/ | ||
public writeMessage(message: HubMessage): string { | ||
@@ -67,0 +86,0 @@ return TextMessageFormat.write(JSON.stringify(message)); |
@@ -6,3 +6,5 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** A logger that does nothing when log messages are sent to it. */ | ||
export class NullLogger implements ILogger { | ||
/** The singleton instance of the {@link NullLogger}. */ | ||
public static instance: ILogger = new NullLogger(); | ||
@@ -12,4 +14,5 @@ | ||
/** @inheritDoc */ | ||
public log(logLevel: LogLevel, message: string): void { | ||
} | ||
} |
@@ -13,2 +13,3 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
// Not exported from 'index', this type is internal. | ||
export class LongPollingTransport implements ITransport { | ||
@@ -23,6 +24,13 @@ private readonly httpClient: HttpClient; | ||
private pollAbort: AbortController; | ||
private shutdownTimer: any; // We use 'any' because this is an object in NodeJS. But it still gets passed to clearTimeout, so it doesn't really matter | ||
private shutdownTimeout: number; | ||
private running: boolean; | ||
private stopped: boolean; | ||
constructor(httpClient: HttpClient, accessTokenFactory: () => string | Promise<string>, logger: ILogger, logMessageContent: boolean) { | ||
// This is an internal type, not exported from 'index' so this is really just internal. | ||
public get pollAborted() { | ||
return this.pollAbort.aborted; | ||
} | ||
constructor(httpClient: HttpClient, accessTokenFactory: () => string | Promise<string>, logger: ILogger, logMessageContent: boolean, shutdownTimeout?: number) { | ||
this.httpClient = httpClient; | ||
@@ -33,2 +41,3 @@ this.accessTokenFactory = accessTokenFactory || (() => null); | ||
this.logMessageContent = logMessageContent; | ||
this.shutdownTimeout = shutdownTimeout || SHUTDOWN_TIMEOUT; | ||
} | ||
@@ -112,5 +121,2 @@ | ||
// If we were on a timeout waiting for shutdown, unregister it. | ||
clearTimeout(this.shutdownTimeout); | ||
this.running = false; | ||
@@ -152,2 +158,10 @@ } else if (response.statusCode !== 200) { | ||
} finally { | ||
// Indicate that we've stopped so the shutdown timer doesn't get registered. | ||
this.stopped = true; | ||
// Clean up the shutdown timer if it was registered | ||
if (this.shutdownTimer) { | ||
clearTimeout(this.shutdownTimer); | ||
} | ||
// Fire our onclosed event | ||
@@ -185,8 +199,10 @@ if (this.onclose) { | ||
} finally { | ||
// Abort the poll after 5 seconds if the server doesn't stop it. | ||
if (!this.pollAbort.aborted) { | ||
this.shutdownTimeout = setTimeout(SHUTDOWN_TIMEOUT, () => { | ||
this.logger.log(LogLevel.Warning, "(LongPolling transport) server did not terminate within 5 seconds after DELETE request, cancelling poll."); | ||
// Abort the poll after the shutdown timeout if the server doesn't stop the poll. | ||
if (!this.stopped) { | ||
this.shutdownTimer = setTimeout(() => { | ||
this.logger.log(LogLevel.Warning, "(LongPolling transport) server did not terminate after DELETE request, canceling poll."); | ||
// Abort any outstanding poll | ||
this.pollAbort.abort(); | ||
}); | ||
}, this.shutdownTimeout); | ||
} | ||
@@ -193,0 +209,0 @@ } |
@@ -10,15 +10,43 @@ // Copyright (c) .NET Foundation. All rights reserved. | ||
/** Defines the expected type for a receiver of results streamed by the server. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface IStreamSubscriber<T> { | ||
/** A boolean that will be set by the {@link IStreamResult} when the stream is closed. */ | ||
closed?: boolean; | ||
/** Called by the framework when a new item is available. */ | ||
next(value: T): void; | ||
/** Called by the framework when an error has occurred. | ||
* | ||
* After this method is called, no additional methods on the {@link IStreamSubscriber} will be called. | ||
*/ | ||
error(err: any): void; | ||
/** Called by the framework when the end of the stream is reached. | ||
* | ||
* After this method is called, no additional methods on the {@link IStreamSubscriber} will be called. | ||
*/ | ||
complete(): void; | ||
} | ||
/** Defines the result of a streaming hub method. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface IStreamResult<T> { | ||
subscribe(observer: IStreamSubscriber<T>): ISubscription<T>; | ||
/** Attaches a {@link IStreamSubscriber}, which will be invoked when new items are available from the stream. | ||
* | ||
* @param {IStreamSubscriber<T>} observer The subscriber to attach. | ||
* @returns {ISubscription<T>} A subscription that can be disposed to terminate the stream and stop calling methods on the {@link IStreamSubscriber}. | ||
*/ | ||
subscribe(subscriber: IStreamSubscriber<T>): ISubscription<T>; | ||
} | ||
/** An interface that allows an {@link IStreamSubscriber} to be disconnected from a stream. | ||
* | ||
* @typeparam T The type of the items being sent by the server. | ||
*/ | ||
export interface ISubscription<T> { | ||
/** Disconnects the {@link IStreamSubscriber} associated with this subscription from the stream. */ | ||
dispose(): void; | ||
} |
// 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. | ||
// Not exported from index | ||
export class TextMessageFormat { | ||
@@ -5,0 +6,0 @@ public static RecordSeparatorCode = 0x1e; |
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
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
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
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
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1276761
9997
0
1