UNPKG

@voice-ping/cognitive-services-speech

Version:

VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft

88 lines (86 loc) 4.49 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Exports_1 = require("../common.browser/Exports"); var Exports_2 = require("../sdk/Exports"); var ConnectionFactoryBase_1 = require("./ConnectionFactoryBase"); var Exports_3 = require("./Exports"); var QueryParameterNames_1 = require("./QueryParameterNames"); var baseUrl = "convai.speech"; var botFramework = { authHeader: "X-DLS-Secret", resourcePath: "", version: "v3" }; var customCommands = { authHeader: "X-CommandsAppId", resourcePath: "commands", version: "v1" }; var pathSuffix = "api"; function getDialogSpecificValues(dialogType) { switch (dialogType) { case "custom_commands": { return customCommands; } case "bot_framework": { return botFramework; } } throw new Error("Invalid dialog type '" + dialogType + "'"); } var DialogConnectionFactory = /** @class */ (function (_super) { __extends(DialogConnectionFactory, _super); function DialogConnectionFactory() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.create = function (config, authInfo, connectionId) { var applicationId = config.parameters.getProperty(Exports_2.PropertyId.Conversation_ApplicationId, ""); var dialogType = config.parameters.getProperty(Exports_2.PropertyId.Conversation_DialogType); var region = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_Region); var language = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_RecoLanguage, "en-US"); var queryParams = {}; queryParams[QueryParameterNames_1.QueryParameterNames.LanguageParamName] = language; queryParams[QueryParameterNames_1.QueryParameterNames.FormatParamName] = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceResponse_OutputFormatOption, Exports_2.OutputFormat[Exports_2.OutputFormat.Simple]).toLowerCase(); var _a = getDialogSpecificValues(dialogType), resourcePath = _a.resourcePath, version = _a.version, authHeader = _a.authHeader; var headers = {}; if (authInfo.token != null && authInfo.token !== "") { headers[authInfo.headerName] = authInfo.token; } headers[QueryParameterNames_1.QueryParameterNames.ConnectionIdHeader] = connectionId; if (applicationId !== "") { headers[authHeader] = applicationId; } var endpoint = config.parameters.getProperty(Exports_2.PropertyId.SpeechServiceConnection_Endpoint, ""); if (endpoint === "") { var hostSuffix = (region && region.toLowerCase().startsWith("china")) ? ".azure.cn" : ".microsoft.com"; // ApplicationId is only required for CustomCommands, so we're using that to determine default endpoint if (applicationId === "") { endpoint = "wss://" + region + "." + baseUrl + hostSuffix + "/" + pathSuffix + "/" + version; } else { endpoint = "wss://" + region + "." + baseUrl + hostSuffix + "/" + resourcePath + "/" + pathSuffix + "/" + version; } } _this.setCommonUrlParams(config, queryParams, endpoint); return new Exports_1.WebsocketConnection(endpoint, queryParams, headers, new Exports_3.WebsocketMessageFormatter(), Exports_1.ProxyInfo.fromRecognizerConfig(config), connectionId); }; return _this; } return DialogConnectionFactory; }(ConnectionFactoryBase_1.ConnectionFactoryBase)); exports.DialogConnectionFactory = DialogConnectionFactory; //# sourceMappingURL=DialogConnectorFactory.js.map