diff --git a/clients/ts/signalr/spec/HttpConnection.spec.ts b/clients/ts/signalr/spec/HttpConnection.spec.ts index 853faf739cdc457b81d5b7130be05156684ccdc1..3c5f7d4771b492f4a250680f894f297da620d314 100644 --- a/clients/ts/signalr/spec/HttpConnection.spec.ts +++ b/clients/ts/signalr/spec/HttpConnection.spec.ts @@ -223,27 +223,35 @@ describe("HttpConnection", () => { }); eachTransport((requestedTransport: HttpTransportType) => { - // OPTIONS is not sent when WebSockets transport is explicitly requested - if (requestedTransport === HttpTransportType.WebSockets) { - return; - } - it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async (done) => { + it(`cannot be started if requested ${HttpTransportType[requestedTransport]} transport not available on server`, async () => { + const negotiateResponse = { + availableTransports: [ + { transport: "WebSockets", transferFormats: [ "Text", "Binary" ] }, + { transport: "ServerSentEvents", transferFormats: [ "Text" ] }, + { transport: "LongPolling", transferFormats: [ "Text", "Binary" ] }, + ], + connectionId: "abc123", + }; + + // Remove the requested transport from the response + negotiateResponse.availableTransports = negotiateResponse.availableTransports + .filter((f) => f.transport !== HttpTransportType[requestedTransport]); + const options: IHttpConnectionOptions = { ...commonOptions, httpClient: new TestHttpClient() - .on("POST", (r) => ({ connectionId: "42", availableTransports: [] })) - .on("GET", (r) => ""), + .on("POST", (r) => negotiateResponse) + .on("GET", (r) => new HttpResponse(204)), transport: requestedTransport, } as IHttpConnectionOptions; const connection = new HttpConnection("http://tempuri.org", options); + try { await connection.start(TransferFormat.Text); - fail(); - done(); + fail("Expected connection.start to throw!"); } catch (e) { expect(e.message).toBe("Unable to initialize any of the available transports."); - done(); } }); }); diff --git a/clients/ts/signalr/src/ITransport.ts b/clients/ts/signalr/src/ITransport.ts index b5c4fb1654d8c8e3aaf63fa05439609603d04d5f..936bcb420a81dfadf84151fef7e9c1753b875935 100644 --- a/clients/ts/signalr/src/ITransport.ts +++ b/clients/ts/signalr/src/ITransport.ts @@ -1,14 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// This will be treated as a bit flag in the future, so we keep it using power-of-two values. /** Specifies a specific HTTP transport type. */ export enum HttpTransportType { + /** Specifies no transport preference. */ + None = 0, /** Specifies the WebSockets transport. */ - WebSockets, + WebSockets = 1, /** Specifies the Server-Sent Events transport. */ - ServerSentEvents, + ServerSentEvents = 2, /** Specifies the Long Polling transport. */ - LongPolling, + LongPolling = 4, } /** Specifies the transfer format for a connection. */