diff --git a/src/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts b/src/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts index 112bddb045..39d89f4867 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts +++ b/src/Microsoft.AspNetCore.SignalR.Client.TS/Connection.ts @@ -22,7 +22,7 @@ export class Connection { this.connectionState = ConnectionState.Disconnected; } - start(transportName: string = 'webSockets'): Promise { + async start(transportName: string = 'webSockets'): Promise { if (this.connectionState != ConnectionState.Disconnected) { throw new Error("Cannot start a connection that is not in the 'Disconnected' state"); } @@ -31,21 +31,18 @@ export class Connection { this.transport.onDataReceived = this.dataReceivedCallback; this.transport.onError = e => this.stopConnection(); - return new HttpClient().get(`${this.url}/getid?${this.queryString}`) - .then(connectionId => { - this.connectionId = connectionId; - this.queryString = `id=${connectionId}&${this.connectionId}`; - return this.transport.connect(this.url, this.queryString); - }) - .then(() => { - this.connectionState = ConnectionState.Connected; - }) - .catch(e => { - console.log("Failed to start the connection.") - this.connectionState = ConnectionState.Disconnected; - this.transport = null; - throw e; - }); + try { + this.connectionId = await new HttpClient().get(`${this.url}/getid?${this.queryString}`); + this.queryString = `id=${this.connectionId}`; + await this.transport.connect(this.url, this.queryString); + this.connectionState = ConnectionState.Connected; + } + catch(e) { + console.log("Failed to start the connection.") + this.connectionState = ConnectionState.Disconnected; + this.transport = null; + throw e; + }; } private createTransport(transportName: string): ITransport { diff --git a/src/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts b/src/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts index 31fef741e0..dbb7cc6a85 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts +++ b/src/Microsoft.AspNetCore.SignalR.Client.TS/HttpClient.ts @@ -8,7 +8,7 @@ export class HttpClient { } private xhr(method: string, url: string, content?: string): Promise { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.open(method, url, true); diff --git a/src/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts b/src/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts index 803481afee..0cad611f23 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts +++ b/src/Microsoft.AspNetCore.SignalR.Client.TS/HubConnection.ts @@ -16,8 +16,8 @@ export { Connection } from "./Connection" export class HubConnection { private connection: Connection; - private callbacks: Map void>; - private methods: Map void>; + private callbacks: Map void>; + private methods: Map void>; private id: number; constructor(url: string, queryString?: string) { @@ -28,13 +28,13 @@ export class HubConnection { thisHubConnection.dataReceived(data); }; - this.callbacks = new Map void>(); - this.methods = new Map void>(); + this.callbacks = new Map void>(); + this.methods = new Map void>(); this.id = 0; } private dataReceived(data: any) { - //TODO: separate JSON parsing + // TODO: separate JSON parsing // Can happen if a poll request was cancelled if (!data) { return; @@ -105,4 +105,4 @@ export class HubConnection { set connectionClosed(callback: ConnectionClosed) { this.connection.connectionClosed = callback; } -} \ No newline at end of file +} diff --git a/src/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts b/src/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts index 4ea8c87f1f..f5082b363a 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts +++ b/src/Microsoft.AspNetCore.SignalR.Client.TS/Transports.ts @@ -112,8 +112,8 @@ export class ServerSentEventsTransport implements ITransport { }); } - send(data: any): Promise { - return new HttpClient().post(this.url + "/send?" + this.queryString, data); + async send(data: any): Promise { + await new HttpClient().post(this.url + "/send?" + this.queryString, data); } stop(): void { @@ -189,8 +189,8 @@ export class LongPollingTransport implements ITransport { this.pollXhr.send(); } - send(data: any): Promise { - return new HttpClient().post(this.url + "/send?" + this.queryString, data); + async send(data: any): Promise { + await new HttpClient().post(this.url + "/send?" + this.queryString, data); } stop(): void {