@voice-ping/cognitive-services-speech
Version:
VoicePing Cognitive Services Speech SDK for JavaScript forked from Microsoft
1 lines • 4.14 kB
Source Map (JSON)
{"version":3,"sources":["src/common.speech/DialogConnectorFactory.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAqB,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAA6B,MAAM,WAAW,CAAC;AAqClF,qBAAa,uBAAwB,SAAQ,qBAAqB;IAEvD,MAAM,uFA0CZ;CACJ","file":"DialogConnectorFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\n// Licensed under the MIT license.\n\nimport {\n ProxyInfo,\n WebsocketConnection,\n} from \"../common.browser/Exports\";\nimport { OutputFormatPropertyName } from \"../common.speech/Exports\";\nimport { IConnection, IStringDictionary } from \"../common/Exports\";\nimport { OutputFormat, PropertyId } from \"../sdk/Exports\";\nimport { ConnectionFactoryBase } from \"./ConnectionFactoryBase\";\nimport { AuthInfo, RecognizerConfig, WebsocketMessageFormatter } from \"./Exports\";\nimport { QueryParameterNames } from \"./QueryParameterNames\";\n\nconst baseUrl: string = \"convai.speech\";\n\ninterface IBackendValues {\n authHeader: string;\n resourcePath: string;\n version: string;\n}\n\nconst botFramework: IBackendValues = {\n authHeader: \"X-DLS-Secret\",\n resourcePath: \"\",\n version: \"v3\"\n};\n\nconst customCommands: IBackendValues = {\n authHeader: \"X-CommandsAppId\",\n resourcePath: \"commands\",\n version: \"v1\"\n};\n\nconst pathSuffix: string = \"api\";\n\nfunction getDialogSpecificValues(dialogType: string): IBackendValues {\n switch (dialogType) {\n case \"custom_commands\": {\n return customCommands;\n }\n case \"bot_framework\": {\n return botFramework;\n }\n }\n throw new Error(`Invalid dialog type '${dialogType}'`);\n}\n\nexport class DialogConnectionFactory extends ConnectionFactoryBase {\n\n public create = (\n config: RecognizerConfig,\n authInfo: AuthInfo,\n connectionId?: string): IConnection => {\n\n const applicationId: string = config.parameters.getProperty(PropertyId.Conversation_ApplicationId, \"\");\n const dialogType: string = config.parameters.getProperty(PropertyId.Conversation_DialogType);\n const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region);\n\n const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, \"en-US\");\n\n const queryParams: IStringDictionary<string> = {};\n queryParams[QueryParameterNames.LanguageParamName] = language;\n queryParams[QueryParameterNames.FormatParamName] = config.parameters.getProperty(PropertyId.SpeechServiceResponse_OutputFormatOption, OutputFormat[OutputFormat.Simple]).toLowerCase();\n\n const {resourcePath, version, authHeader} = getDialogSpecificValues(dialogType);\n\n const headers: IStringDictionary<string> = {};\n\n if (authInfo.token != null && authInfo.token !== \"\") {\n headers[authInfo.headerName] = authInfo.token;\n }\n headers[QueryParameterNames.ConnectionIdHeader] = connectionId;\n\n if (applicationId !== \"\") {\n headers[authHeader] = applicationId;\n }\n\n let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, \"\");\n if (endpoint === \"\") {\n const hostSuffix = (region && region.toLowerCase().startsWith(\"china\")) ? \".azure.cn\" : \".microsoft.com\";\n // ApplicationId is only required for CustomCommands, so we're using that to determine default endpoint\n if (applicationId === \"\") {\n endpoint = `wss://${region}.${baseUrl}${hostSuffix}/${pathSuffix}/${version}`;\n } else {\n endpoint = `wss://${region}.${baseUrl}${hostSuffix}/${resourcePath}/${pathSuffix}/${version}`;\n }\n }\n\n this.setCommonUrlParams(config, queryParams, endpoint);\n\n return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), connectionId);\n }\n}\n"]}