{"version":3,"sources":["src/common.speech/SpeechConnectionFactory.ts"],"names":[],"mappings":"AAWA,OAAO,EACH,WAAW,EAEd,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EACH,qBAAqB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,QAAQ,EAER,gBAAgB,EAEnB,MAAM,WAAW,CAAC;AAKnB,qBAAa,uBAAwB,SAAQ,qBAAqB;IAE9D,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAkE;IACzG,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAmE;IAC3G,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAgE;IAE9F,MAAM,uFAuDZ;CACJ","file":"SpeechConnectionFactory.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 {\n    ForceDictationPropertyName,\n    OutputFormatPropertyName,\n} from \"../common.speech/Exports\";\nimport {\n    IConnection,\n    IStringDictionary\n} from \"../common/Exports\";\nimport {\n    OutputFormat,\n    PropertyId\n} from \"../sdk/Exports\";\nimport {\n    ConnectionFactoryBase\n} from \"./ConnectionFactoryBase\";\nimport {\n    AuthInfo,\n    RecognitionMode,\n    RecognizerConfig,\n    WebsocketMessageFormatter\n} from \"./Exports\";\nimport {\n    QueryParameterNames\n} from \"./QueryParameterNames\";\n\nexport class SpeechConnectionFactory extends ConnectionFactoryBase {\n\n    private readonly interactiveRelativeUri: string = \"/speech/recognition/interactive/cognitiveservices/v1\";\n    private readonly conversationRelativeUri: string = \"/speech/recognition/conversation/cognitiveservices/v1\";\n    private readonly dictationRelativeUri: string = \"/speech/recognition/dictation/cognitiveservices/v1\";\n\n    public create = (\n        config: RecognizerConfig,\n        authInfo: AuthInfo,\n        connectionId?: string): IConnection => {\n\n        let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\n\n        const queryParams: IStringDictionary<string> = {};\n\n        const endpointId: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_EndpointId, undefined);\n        const language: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage, undefined);\n\n        if (endpointId) {\n            if (!endpoint || endpoint.search(QueryParameterNames.DeploymentIdParamName) === -1) {\n                queryParams[QueryParameterNames.DeploymentIdParamName] = endpointId;\n            }\n        } else if (language) {\n            if (!endpoint || endpoint.search(QueryParameterNames.LanguageParamName) === -1) {\n                queryParams[QueryParameterNames.LanguageParamName] = language;\n            }\n        }\n\n        if (!endpoint || endpoint.search(QueryParameterNames.FormatParamName) === -1) {\n            queryParams[QueryParameterNames.FormatParamName] = config.parameters.getProperty(OutputFormatPropertyName, OutputFormat[OutputFormat.Simple]).toLowerCase();\n        }\n\n        this.setCommonUrlParams(config, queryParams, endpoint);\n\n        if (!endpoint) {\n            const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\n\n            const host: string = \"wss://\" + region + \".stt.speech.microsoft.com\";\n\n            switch (config.recognitionMode) {\n                case RecognitionMode.Conversation:\n                    if (config.parameters.getProperty(ForceDictationPropertyName, \"false\") === \"true\") {\n                        endpoint = host + this.dictationRelativeUri;\n                    } else {\n                        endpoint = host + this.conversationRelativeUri;\n                    }\n                    break;\n                case RecognitionMode.Dictation:\n                    endpoint = host + this.dictationRelativeUri;\n                    break;\n                default:\n                    endpoint = host + this.interactiveRelativeUri; // default is interactive\n                    break;\n            }\n        }\n\n        const headers: IStringDictionary<string> = {};\n        headers[authInfo.headerName] = authInfo.token;\n        headers[QueryParameterNames.ConnectionIdHeader] = connectionId;\n\n        return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), connectionId);\n    }\n}\n"]}