"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultTunnelRelayStreamFactory = void 0;
const sshHelpers_1 = require("./sshHelpers");
/**
 * Default factory for creating streams to a tunnel relay.
 */
class DefaultTunnelRelayStreamFactory {
    async createRelayStream(relayUri, protocols, accessToken, clientConfig) {
        if ((0, sshHelpers_1.isNode)()) {
            const stream = await sshHelpers_1.SshHelpers.openConnection(relayUri, protocols, Object.assign({}, (accessToken && { Authorization: `tunnel ${accessToken}` })), clientConfig);
            return { stream, protocol: stream.protocol };
        }
        else {
            // Web sockets don't support auth. Authenticate TunnelRelay by sending accessToken as a subprotocol.
            if (accessToken) {
                protocols = [...protocols, accessToken];
            }
            const stream = await sshHelpers_1.SshHelpers.openConnection(relayUri, protocols);
            return { stream, protocol: stream.protocol };
        }
    }
}
exports.DefaultTunnelRelayStreamFactory = DefaultTunnelRelayStreamFactory;
//# sourceMappingURL=https://github.com/VSCodium/sourcemaps/releases/download/stable-4c0b0c6cc561d2d3636d1ec250935431876ce4dc/node_modules-@microsoft-dev-tunnels-connections-defaultTunnelRelayStreamFactory.js.map