diff --git a/clients/ts/signalr/src/HttpConnection.ts b/clients/ts/signalr/src/HttpConnection.ts index e0fdd754fe..97e9078722 100644 --- a/clients/ts/signalr/src/HttpConnection.ts +++ b/clients/ts/signalr/src/HttpConnection.ts @@ -85,7 +85,7 @@ export class HttpConnection implements IConnection { this.transport = this.constructTransport(TransportType.WebSockets); // We should just call connect directly in this case. // No fallback or negotiate in this case. - await this.transport.connect(this.url, transferFormat, this); + await this.transport.connect(this.url, transferFormat); } else { const token = await this.options.accessTokenFactory(); let headers; @@ -103,6 +103,10 @@ export class HttpConnection implements IConnection { await this.createTransport(this.options.transport, negotiateResponse, transferFormat, headers); } + if (typeof this.transport === typeof LongPollingTransport) { + this.features.inherentKeepAlive = true; + } + this.transport.onreceive = this.onreceive; this.transport.onclose = (e) => this.stopConnection(true, e); @@ -121,7 +125,7 @@ export class HttpConnection implements IConnection { const negotiateUrl = this.resolveNegotiateUrl(this.baseUrl); this.logger.log(LogLevel.Trace, `Sending negotiation request: ${negotiateUrl}`); try { - const response = await this.httpClient.post(negotiateUrl, { + const response = await this.httpClient.post(negotiateUrl, { content: "", headers, }); @@ -142,7 +146,7 @@ export class HttpConnection implements IConnection { if (this.isITransport(requestedTransport)) { this.logger.log(LogLevel.Trace, "Connection was provided an instance of ITransport, using that directly."); this.transport = requestedTransport; - await this.transport.connect(this.url, requestedTransferFormat, this); + await this.transport.connect(this.url, requestedTransferFormat); // only change the state if we were connecting to not overwrite // the state if the connection is already marked as Disconnected @@ -161,7 +165,7 @@ export class HttpConnection implements IConnection { this.updateConnectionId(negotiateResponse); } try { - await this.transport.connect(this.url, requestedTransferFormat, this); + await this.transport.connect(this.url, requestedTransferFormat); this.changeState(ConnectionState.Connecting, ConnectionState.Connected); return; } catch (ex) { diff --git a/clients/ts/signalr/src/Transports.ts b/clients/ts/signalr/src/Transports.ts index a62414390a..5823ad9369 100644 --- a/clients/ts/signalr/src/Transports.ts +++ b/clients/ts/signalr/src/Transports.ts @@ -5,7 +5,6 @@ import { AbortController } from "./AbortController"; import { DataReceived, TransportClosed } from "./Common"; import { HttpError, TimeoutError } from "./Errors"; import { HttpClient, HttpRequest } from "./HttpClient"; -import { IConnection } from "./IConnection"; import { ILogger, LogLevel } from "./ILogger"; import { Arg } from "./Utils"; @@ -21,7 +20,7 @@ export enum TransferFormat { } export interface ITransport { - connect(url: string, transferFormat: TransferFormat, connection: IConnection): Promise; + connect(url: string, transferFormat: TransferFormat): Promise; send(data: any): Promise; stop(): Promise; onreceive: DataReceived; @@ -40,11 +39,10 @@ export class WebSocketTransport implements ITransport { this.logMessageContent = logMessageContent; } - public async connect(url: string, transferFormat: TransferFormat, connection: IConnection): Promise { + public async connect(url: string, transferFormat: TransferFormat): Promise { Arg.isRequired(url, "url"); Arg.isRequired(transferFormat, "transferFormat"); Arg.isIn(transferFormat, TransferFormat, "transferFormat"); - Arg.isRequired(connection, "connection"); if (typeof (WebSocket) === "undefined") { throw new Error("'WebSocket' is not supported in your environment."); @@ -131,11 +129,10 @@ export class ServerSentEventsTransport implements ITransport { this.logMessageContent = logMessageContent; } - public async connect(url: string, transferFormat: TransferFormat, connection: IConnection): Promise { + public async connect(url: string, transferFormat: TransferFormat): Promise { Arg.isRequired(url, "url"); Arg.isRequired(transferFormat, "transferFormat"); Arg.isIn(transferFormat, TransferFormat, "transferFormat"); - Arg.isRequired(connection, "connection"); if (typeof (EventSource) === "undefined") { throw new Error("'EventSource' is not supported in your environment."); @@ -226,19 +223,15 @@ export class LongPollingTransport implements ITransport { this.logMessageContent = logMessageContent; } - public connect(url: string, transferFormat: TransferFormat, connection: IConnection): Promise { + public connect(url: string, transferFormat: TransferFormat): Promise { Arg.isRequired(url, "url"); Arg.isRequired(transferFormat, "transferFormat"); Arg.isIn(transferFormat, TransferFormat, "transferFormat"); - Arg.isRequired(connection, "connection"); this.url = url; this.logger.log(LogLevel.Trace, "(LongPolling transport) Connecting"); - // Set a flag indicating we have inherent keep-alive in this transport. - connection.features.inherentKeepAlive = true; - if (transferFormat === TransferFormat.Binary && (typeof new XMLHttpRequest().responseType !== "string")) { // This will work if we fix: https://github.com/aspnet/SignalR/issues/742 throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");