{"version":3,"sources":["src/common.speech/TranslationConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EAEd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACH,qBAAqB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,QAAQ,EAER,gBAAgB,EAEnB,MAAM,WAAW,CAAC;AAInB,qBAAa,4BAA6B,SAAQ,qBAAqB;IAE5D,MAAM,WACD,gBAAgB,YACd,QAAQ,iBACH,MAAM,KAAG,WAAW,CA0CtC;CACJ","file":"TranslationConnectionFactory.d.ts","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT license.\r\n\r\nimport {\r\n    ProxyInfo,\r\n    WebsocketConnection,\r\n} from \"../common.browser/Exports\";\r\nimport {\r\n    IConnection,\r\n    IStringDictionary,\r\n} from \"../common/Exports\";\r\nimport {\r\n    PropertyId\r\n} from \"../sdk/Exports\";\r\nimport {\r\n    ConnectionFactoryBase\r\n} from \"./ConnectionFactoryBase\";\r\nimport {\r\n    AuthInfo,\r\n    IConnectionFactory,\r\n    RecognizerConfig,\r\n    WebsocketMessageFormatter,\r\n} from \"./Exports\";\r\nimport { HeaderNames } from \"./HeaderNames\";\r\nimport { QueryParameterNames } from \"./QueryParameterNames\";\r\n\r\nexport class TranslationConnectionFactory extends ConnectionFactoryBase {\r\n\r\n    public create = (\r\n        config: RecognizerConfig,\r\n        authInfo: AuthInfo,\r\n        connectionId?: string): IConnection => {\r\n\r\n        let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\r\n        if (!endpoint) {\r\n            const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\r\n            const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\r\n            const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".s2s.speech\" + hostSuffix);\r\n            endpoint = host + \"/speech/translation/cognitiveservices/v1\";\r\n        }\r\n\r\n        const queryParams: IStringDictionary<string> = {\r\n            from: config.parameters.getProperty(PropertyId.SpeechServiceConnection_RecoLanguage),\r\n            to: config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationToLanguages),\r\n        };\r\n\r\n        this.setCommonUrlParams(config, queryParams, endpoint);\r\n        this.setUrlParameter(\r\n            PropertyId.SpeechServiceResponse_TranslationRequestStablePartialResult,\r\n            QueryParameterNames.StableTranslation,\r\n            config,\r\n            queryParams,\r\n            endpoint\r\n        );\r\n\r\n        const voiceName: string = \"voice\";\r\n        const featureName: string = \"features\";\r\n\r\n        if (config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice, undefined) !== undefined) {\r\n            queryParams[voiceName] = config.parameters.getProperty(PropertyId.SpeechServiceConnection_TranslationVoice);\r\n            queryParams[featureName] = \"texttospeech\";\r\n        }\r\n\r\n        const headers: IStringDictionary<string> = {};\r\n        if (authInfo.token !== undefined && authInfo.token !== \"\") {\r\n            headers[authInfo.headerName] = authInfo.token;\r\n        }\r\n        headers[HeaderNames.ConnectionId] = connectionId;\r\n\r\n        config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, endpoint);\r\n\r\n        const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\r\n        return new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\r\n    }\r\n}\r\n"]}