Skip to content

Commit 527abdf

Browse files
committed
fix
1 parent 214e86b commit 527abdf

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/SignalR/clients/ts/signalr/src/HttpConnection.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class HttpConnection implements IConnection {
230230
this.transport = this.constructTransport(HttpTransportType.WebSockets);
231231
// We should just call connect directly in this case.
232232
// No fallback or negotiate in this case.
233-
await this.transport!.connect(url, transferFormat);
233+
await this.startTransport(url, transferFormat);
234234
} else {
235235
throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");
236236
}
@@ -341,9 +341,7 @@ export class HttpConnection implements IConnection {
341341
if (this.isITransport(requestedTransport)) {
342342
this.logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly.");
343343
this.transport = requestedTransport;
344-
this.transport.onreceive = this.onreceive;
345-
this.transport.onclose = (e) => this.stopConnection(e);
346-
await this.transport.connect(connectUrl, requestedTransferFormat);
344+
await this.startTransport(connectUrl, requestedTransferFormat);
347345

348346
return;
349347
}
@@ -366,9 +364,7 @@ export class HttpConnection implements IConnection {
366364
connectUrl = this.createConnectUrl(url, negotiateResponse.connectionId);
367365
}
368366
try {
369-
this.transport!.onreceive = this.onreceive;
370-
this.transport!.onclose = (e) => this.stopConnection(e);
371-
await this.transport!.connect(connectUrl, requestedTransferFormat);
367+
await this.startTransport(connectUrl, requestedTransferFormat);
372368
return;
373369
} catch (ex) {
374370
this.logger.log(LogLevel.Error, `Failed to start the transport '${endpoint.transport}': ${ex}`);
@@ -409,6 +405,12 @@ export class HttpConnection implements IConnection {
409405
}
410406
}
411407

408+
private startTransport(url: string, transferFormat: TransferFormat): Promise<void> {
409+
this.transport!.onreceive = this.onreceive;
410+
this.transport!.onclose = (e) => this.stopConnection(e);
411+
return this.transport!.connect(url, transferFormat);
412+
}
413+
412414
private resolveTransportOrError(endpoint: IAvailableTransport, requestedTransport: HttpTransportType | undefined, requestedTransferFormat: TransferFormat): ITransport | Error {
413415
const transport = HttpTransportType[endpoint.transport];
414416
if (transport === null || transport === undefined) {

0 commit comments

Comments
 (0)