"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-824c4c46a288b839f13b24022655329c2aeb9f81/node_modules-@microsoft-dev-tunnels-connections-defaultTunnelRelayStreamFactory.js.map