Enabling creating HubConnection without HttpConnection
This commit is contained in:
parent
393ab6a4f0
commit
bb79a9760c
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import { ConnectionClosed } from "./Common"
|
import { ConnectionClosed } from "./Common"
|
||||||
import { IConnection } from "./IConnection"
|
import { IConnection } from "./IConnection"
|
||||||
|
import { HttpConnection} from "./HttpConnection"
|
||||||
import { TransportType, TransferMode } from "./Transports"
|
import { TransportType, TransferMode } from "./Transports"
|
||||||
import { Subject, Observable } from "./Observable"
|
import { Subject, Observable } from "./Observable"
|
||||||
import { IHubProtocol, ProtocolType, MessageType, HubMessage, CompletionMessage, ResultMessage, InvocationMessage, NegotiationMessage } from "./IHubProtocol";
|
import { IHubProtocol, ProtocolType, MessageType, HubMessage, CompletionMessage, ResultMessage, InvocationMessage, NegotiationMessage } from "./IHubProtocol";
|
||||||
|
|
@ -28,9 +29,15 @@ export class HubConnection {
|
||||||
private id: number;
|
private id: number;
|
||||||
private connectionClosedCallback: ConnectionClosed;
|
private connectionClosedCallback: ConnectionClosed;
|
||||||
|
|
||||||
constructor(connection: IConnection, options: IHubConnectionOptions = {}) {
|
constructor(urlOrConnection: string | IConnection, options: IHubConnectionOptions = {}) {
|
||||||
this.connection = connection;
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
if (typeof urlOrConnection === "string") {
|
||||||
|
this.connection = new HttpConnection(urlOrConnection, options);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.connection = urlOrConnection;
|
||||||
|
}
|
||||||
|
|
||||||
this.logger = LoggerFactory.createLogger(options.logging);
|
this.logger = LoggerFactory.createLogger(options.logging);
|
||||||
|
|
||||||
this.protocol = options.protocol || new JsonHubProtocol();
|
this.protocol = options.protocol || new JsonHubProtocol();
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
import { IHttpConnectionOptions } from "./IHttpConnectionOptions"
|
||||||
import { IHubProtocol } from "./IHubProtocol"
|
import { IHubProtocol } from "./IHubProtocol"
|
||||||
import { ILogger, LogLevel } from "./ILogger"
|
import { ILogger, LogLevel } from "./ILogger"
|
||||||
|
|
||||||
export interface IHubConnectionOptions {
|
export interface IHubConnectionOptions extends IHttpConnectionOptions {
|
||||||
protocol?: IHubProtocol;
|
protocol?: IHubProtocol;
|
||||||
logging?: ILogger | LogLevel;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
|
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||||
hubConnection.onClosed = function (error) {
|
hubConnection.onClosed = function (error) {
|
||||||
expect(error).toBe(undefined);
|
expect(error).toBe(undefined);
|
||||||
done();
|
done();
|
||||||
|
|
@ -44,7 +44,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
|
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||||
|
|
||||||
hubConnection.onClosed = function (error) {
|
hubConnection.onClosed = function (error) {
|
||||||
expect(error).toBe(undefined);
|
expect(error).toBe(undefined);
|
||||||
|
|
@ -79,7 +79,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
|
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||||
|
|
||||||
hubConnection.start().then(function () {
|
hubConnection.start().then(function () {
|
||||||
hubConnection.invoke('ThrowException', errorMessage).then(function () {
|
hubConnection.invoke('ThrowException', errorMessage).then(function () {
|
||||||
|
|
@ -105,7 +105,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
|
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||||
|
|
||||||
hubConnection.start().then(function () {
|
hubConnection.start().then(function () {
|
||||||
hubConnection.stream('ThrowException', errorMessage).subscribe({
|
hubConnection.stream('ThrowException', errorMessage).subscribe({
|
||||||
|
|
@ -132,7 +132,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
|
var hubConnection = new signalR.HubConnection(TESTHUBENDPOINT_URL, options);
|
||||||
|
|
||||||
var message = "你好 SignalR!";
|
var message = "你好 SignalR!";
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ describe('hubConnection', function () {
|
||||||
protocol: protocol,
|
protocol: protocol,
|
||||||
logging: signalR.LogLevel.Trace
|
logging: signalR.LogLevel.Trace
|
||||||
};
|
};
|
||||||
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection('http://' + document.location.host + '/uncreatable', options), options);
|
var hubConnection = new signalR.HubConnection('http://' + document.location.host + '/uncreatable', options);
|
||||||
|
|
||||||
hubConnection.onClosed = function (error) {
|
hubConnection.onClosed = function (error) {
|
||||||
expect(error.message).toMatch(errorRegex[signalR.TransportType[transportType]]);
|
expect(error.message).toMatch(errorRegex[signalR.TransportType[transportType]]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue