@@ -230,7 +230,7 @@ export class HttpConnection implements IConnection {
230
230
this . transport = this . constructTransport ( HttpTransportType . WebSockets ) ;
231
231
// We should just call connect directly in this case.
232
232
// No fallback or negotiate in this case.
233
- await this . transport ! . connect ( url , transferFormat ) ;
233
+ await this . startTransport ( url , transferFormat ) ;
234
234
} else {
235
235
throw new Error ( "Negotiation can only be skipped when using the WebSocket transport directly." ) ;
236
236
}
@@ -341,9 +341,7 @@ export class HttpConnection implements IConnection {
341
341
if ( this . isITransport ( requestedTransport ) ) {
342
342
this . logger . log ( LogLevel . Debug , "Connection was provided an instance of ITransport, using that directly." ) ;
343
343
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 ) ;
347
345
348
346
return ;
349
347
}
@@ -366,9 +364,7 @@ export class HttpConnection implements IConnection {
366
364
connectUrl = this . createConnectUrl ( url , negotiateResponse . connectionId ) ;
367
365
}
368
366
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 ) ;
372
368
return ;
373
369
} catch ( ex ) {
374
370
this . logger . log ( LogLevel . Error , `Failed to start the transport '${ endpoint . transport } ': ${ ex } ` ) ;
@@ -409,6 +405,12 @@ export class HttpConnection implements IConnection {
409
405
}
410
406
}
411
407
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
+
412
414
private resolveTransportOrError ( endpoint : IAvailableTransport , requestedTransport : HttpTransportType | undefined , requestedTransferFormat : TransferFormat ) : ITransport | Error {
413
415
const transport = HttpTransportType [ endpoint . transport ] ;
414
416
if ( transport === null || transport === undefined ) {
0 commit comments