diff --git a/src/platform/web/transport/transport-options.ts b/src/platform/web/transport/transport-options.ts index ba0d16cc2..bb3b4e336 100644 --- a/src/platform/web/transport/transport-options.ts +++ b/src/platform/web/transport/transport-options.ts @@ -31,4 +31,10 @@ export interface TransportOptions { * @defaultValue `true` */ traceSip?: boolean; + + /** + * The transport protocol to use in Via header declarations. + * If not specified, will be inferred from the server URL. + */ + headerProtocol?: string; } diff --git a/src/platform/web/transport/transport.ts b/src/platform/web/transport/transport.ts index 13943b753..16799fb1e 100644 --- a/src/platform/web/transport/transport.ts +++ b/src/platform/web/transport/transport.ts @@ -16,7 +16,8 @@ export class Transport implements TransportDefinition { connectionTimeout: 5, keepAliveInterval: 0, keepAliveDebounce: 10, - traceSip: true + traceSip: true, + headerProtocol: "" }; public onConnect: (() => void) | undefined; @@ -100,7 +101,14 @@ export class Transport implements TransportDefinition { this.logger.error(`Invalid scheme in WebSocket Server URL "${url}"`); throw new Error("Invalid scheme in WebSocket Server URL"); } - this._protocol = parsed.scheme.toUpperCase(); + + // Use the explicit header protocol if defined, but fall back to the + // server's indicated scheme + if (typeof this.configuration.headerProtocol === "string" && this.configuration.headerProtocol !== "") { + this._protocol = this.configuration.headerProtocol.toUpperCase(); + } else { + this._protocol = parsed.scheme.toUpperCase(); + } } public dispose(): Promise { diff --git a/test/spec/platform/web/transport.spec.ts b/test/spec/platform/web/transport.spec.ts index f18911ee6..7bb5148aa 100644 --- a/test/spec/platform/web/transport.spec.ts +++ b/test/spec/platform/web/transport.spec.ts @@ -64,6 +64,21 @@ describe("Web Transport", () => { // The transport should now be in the Disconnected state, so traverse the FSM. traverseTransportStateMachine(); + + describe("supports customized header protocols", () => { + // constructTransport normally validates that the protocol is WSS + // given that the server URL is wss://... + const headerProtocol = "ws"; + const customizedTransport = new Transport(logger, { + connectionTimeout, + server, + headerProtocol + }); + + it("protocol MUST be WS", () => { + expect(customizedTransport.protocol).toBe(headerProtocol.toUpperCase()); + }); + }); }); function initServer(): void {