parent
58e7c1b1fe
commit
39b2990b62
|
|
@ -1,6 +1,8 @@
|
||||||
import { IHttpClient } from "../Microsoft.AspNetCore.SignalR.Client.TS/HttpClient"
|
import { IHttpClient } from "../Microsoft.AspNetCore.SignalR.Client.TS/HttpClient"
|
||||||
import { Connection } from "../Microsoft.AspNetCore.SignalR.Client.TS/Connection"
|
import { Connection } from "../Microsoft.AspNetCore.SignalR.Client.TS/Connection"
|
||||||
import { ISignalROptions } from "../Microsoft.AspNetCore.SignalR.Client.TS/ISignalROptions"
|
import { ISignalROptions } from "../Microsoft.AspNetCore.SignalR.Client.TS/ISignalROptions"
|
||||||
|
import { DataReceived, TransportClosed } from "../Microsoft.AspNetCore.SignalR.Client.TS/Common"
|
||||||
|
import { ITransport } from "../Microsoft.AspNetCore.SignalR.Client.TS/Transports"
|
||||||
|
|
||||||
describe("Connection", () => {
|
describe("Connection", () => {
|
||||||
|
|
||||||
|
|
@ -122,4 +124,44 @@ describe("Connection", () => {
|
||||||
await connection.stop();
|
await connection.stop();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves users connection string", async done => {
|
||||||
|
let options: ISignalROptions = {
|
||||||
|
httpClient: <IHttpClient>{
|
||||||
|
get(url: string): Promise<string> {
|
||||||
|
if (url.includes("negotiate")) {
|
||||||
|
return Promise.resolve("42");
|
||||||
|
}
|
||||||
|
return Promise.resolve("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as ISignalROptions;
|
||||||
|
|
||||||
|
let connectQueryString: string;
|
||||||
|
let fakeTransport: ITransport = {
|
||||||
|
connect(url: string, queryString: string): Promise<void> {
|
||||||
|
connectQueryString = queryString;
|
||||||
|
return Promise.reject("");
|
||||||
|
},
|
||||||
|
send(data: any): Promise<void> {
|
||||||
|
return Promise.reject("");
|
||||||
|
},
|
||||||
|
stop(): void { },
|
||||||
|
onDataReceived: undefined,
|
||||||
|
onClosed: undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
var connection = new Connection("http://tempuri.org", "q=myData", options);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connection.start(fakeTransport);
|
||||||
|
fail();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(connectQueryString).toBe("q=myData&id=42");
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export class Connection implements IConnection {
|
||||||
|
|
||||||
constructor(url: string, queryString: string = "", options: ISignalROptions = {}) {
|
constructor(url: string, queryString: string = "", options: ISignalROptions = {}) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.queryString = queryString;
|
this.queryString = queryString || "";
|
||||||
this.httpClient = options.httpClient || new HttpClient();
|
this.httpClient = options.httpClient || new HttpClient();
|
||||||
this.connectionState = ConnectionState.Initial;
|
this.connectionState = ConnectionState.Initial;
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +47,10 @@ export class Connection implements IConnection {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.queryString = `id=${this.connectionId}`;
|
if (this.queryString) {
|
||||||
|
this.queryString += "&";
|
||||||
|
}
|
||||||
|
this.queryString += `id=${this.connectionId}`;
|
||||||
|
|
||||||
this.transport = this.createTransport(transportType);
|
this.transport = this.createTransport(transportType);
|
||||||
this.transport.onDataReceived = this.onDataReceived;
|
this.transport.onDataReceived = this.onDataReceived;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue