diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts index 8185c65356..e8348aa0cb 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS.Tests/Connection.spec.ts @@ -18,7 +18,7 @@ describe("Connection", () => { } } as ISignalROptions; - let connection = new Connection("http://tempuri.org", undefined, options); + let connection = new Connection("http://tempuri.org", options); try { await connection.start(); @@ -53,7 +53,7 @@ describe("Connection", () => { } } as ISignalROptions; - let connection = new Connection("http://tempuri.org", undefined, options); + let connection = new Connection("http://tempuri.org", options); try { await connection.start(); @@ -76,7 +76,7 @@ describe("Connection", () => { } } as ISignalROptions; - let connection = new Connection("http://tempuri.org", undefined, options); + let connection = new Connection("http://tempuri.org", options); try { // start will fail and transition the connection to the Disconnected state @@ -111,7 +111,7 @@ describe("Connection", () => { } } as ISignalROptions; - var connection = new Connection("http://tempuri.org", undefined, options); + var connection = new Connection("http://tempuri.org", options); try { await connection.start(); @@ -141,10 +141,10 @@ describe("Connection", () => { } } as ISignalROptions; - let connectQueryString: string; + let connectUrl: string; let fakeTransport: ITransport = { - connect(url: string, queryString: string): Promise { - connectQueryString = queryString; + connect(url: string): Promise { + connectUrl = url; return Promise.reject(""); }, send(data: any): Promise { @@ -155,7 +155,7 @@ describe("Connection", () => { onClosed: undefined } - var connection = new Connection("http://tempuri.org", "q=myData", options); + var connection = new Connection("http://tempuri.org?q=myData", options); try { await connection.start(fakeTransport); @@ -165,7 +165,7 @@ describe("Connection", () => { catch (e) { } - expect(connectQueryString).toBe("q=myData&id=42"); + expect(connectUrl).toBe("http://tempuri.org?q=myData&id=42"); done(); }); }); diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts index bb7a2f81a8..e4d228131a 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts @@ -14,15 +14,13 @@ enum ConnectionState { export class Connection implements IConnection { private connectionState: ConnectionState; private url: string; - private queryString: string; private connectionId: string; private httpClient: IHttpClient; private transport: ITransport; private startPromise: Promise; - constructor(url: string, queryString: string = "", options: ISignalROptions = {}) { + constructor(url: string, options: ISignalROptions = {}) { this.url = url; - this.queryString = queryString || ""; this.httpClient = options.httpClient || new HttpClient(); this.connectionState = ConnectionState.Initial; } @@ -40,23 +38,19 @@ export class Connection implements IConnection { private async startInternal(transportType: TransportType | ITransport): Promise { try { - var negotiateUrl = this.url + (this.queryString ? "?" + this.queryString : ""); - this.connectionId = await this.httpClient.options(negotiateUrl); + this.connectionId = await this.httpClient.options(this.url); // the user tries to stop the the connection when it is being started if (this.connectionState == ConnectionState.Disconnected) { return; } - if (this.queryString) { - this.queryString += "&"; - } - this.queryString += `id=${this.connectionId}`; + this.url += (this.url.indexOf("?") == -1 ? "?" : "&") + `id=${this.connectionId}`; this.transport = this.createTransport(transportType); this.transport.onDataReceived = this.onDataReceived; this.transport.onClosed = e => this.stopConnection(true, e); - await this.transport.connect(this.url, this.queryString); + await this.transport.connect(this.url); // only change the state if we were connecting to not overwrite // the state if the connection is already marked as Disconnected this.changeState(ConnectionState.Connecting, ConnectionState.Connected); diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts index f6039c4f1e..c98b8b8206 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts +++ b/client-ts/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts @@ -8,7 +8,7 @@ export enum TransportType { } export interface ITransport { - connect(url: string, queryString: string): Promise; + connect(url: string): Promise; send(data: any): Promise; stop(): void; onDataReceived: DataReceived; @@ -21,12 +21,11 @@ export class WebSocketTransport implements ITransport { connect(url: string, queryString: string = ""): Promise { return new Promise((resolve, reject) => { url = url.replace(/^http/, "ws"); - let connectUrl = url + (queryString ? "?" + queryString : ""); - let webSocket = new WebSocket(connectUrl); + let webSocket = new WebSocket(url); webSocket.onopen = (event: Event) => { - console.log(`WebSocket connected to ${connectUrl}`); + console.log(`WebSocket connected to ${url}`); this.webSocket = webSocket; resolve(); }; @@ -80,24 +79,20 @@ export class ServerSentEventsTransport implements ITransport { private eventSource: EventSource; private url: string; private queryString: string; - private fullUrl: string; private httpClient: IHttpClient; constructor(httpClient: IHttpClient) { this.httpClient = httpClient; } - connect(url: string, queryString: string): Promise { + connect(url: string): Promise { if (typeof (EventSource) === "undefined") { Promise.reject("EventSource not supported by the browser.") } - - this.queryString = queryString; this.url = url; - this.fullUrl = url + (queryString ? "?" + queryString : ""); return new Promise((resolve, reject) => { - let eventSource = new EventSource(this.fullUrl); + let eventSource = new EventSource(this.url); try { eventSource.onmessage = (e: MessageEvent) => { @@ -124,7 +119,7 @@ export class ServerSentEventsTransport implements ITransport { } eventSource.onopen = () => { - console.log(`SSE connected to ${this.fullUrl}`); + console.log(`SSE connected to ${this.url}`); this.eventSource = eventSource; resolve(); } @@ -136,7 +131,7 @@ export class ServerSentEventsTransport implements ITransport { } async send(data: any): Promise { - return send(this.httpClient, this.fullUrl, data); + return send(this.httpClient, this.url, data); } stop(): void { @@ -152,8 +147,6 @@ export class ServerSentEventsTransport implements ITransport { export class LongPollingTransport implements ITransport { private url: string; - private queryString: string; - private fullUrl: string; private httpClient: IHttpClient; private pollXhr: XMLHttpRequest; private shouldPoll: boolean; @@ -162,12 +155,10 @@ export class LongPollingTransport implements ITransport { this.httpClient = httpClient; } - connect(url: string, queryString: string): Promise { + connect(url: string): Promise { this.url = url; - this.queryString = queryString; this.shouldPoll = true; - this.fullUrl = url + (queryString ? "?" + queryString : ""); - this.poll(this.fullUrl); + this.poll(this.url); return Promise.resolve(); } @@ -224,7 +215,7 @@ export class LongPollingTransport implements ITransport { } async send(data: any): Promise { - return send(this.httpClient, this.fullUrl, data); + return send(this.httpClient, this.url, data); } stop(): void { diff --git a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Microsoft.AspNetCore.SignalR.Test.Server.csproj b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Microsoft.AspNetCore.SignalR.Test.Server.csproj index 8735f725e5..5e24866e29 100644 --- a/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Microsoft.AspNetCore.SignalR.Test.Server.csproj +++ b/client-ts/Microsoft.AspNetCore.SignalR.Test.Server/Microsoft.AspNetCore.SignalR.Test.Server.csproj @@ -3,7 +3,7 @@ - netcoreapp2.0;net461 + netcoreapp2.0