{"version":3,"sources":["src/common.speech/SpeechSynthesisConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EAEd,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACH,QAAQ,EACR,iBAAiB,EAEpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAK/E,qBAAa,gCAAiC,YAAW,2BAA2B;IAEhF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiD;IAEjE,MAAM,CACf,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAiDnD","file":"SpeechSynthesisConnectionFactory.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.js\";\r\nimport {\r\n    IConnection,\r\n    IStringDictionary\r\n} from \"../common/Exports.js\";\r\nimport { PropertyId } from \"../sdk/Exports.js\";\r\nimport { ConnectionFactoryBase } from \"./ConnectionFactoryBase.js\";\r\nimport {\r\n    AuthInfo,\r\n    SynthesizerConfig,\r\n    WebsocketMessageFormatter\r\n} from \"./Exports.js\";\r\nimport { HeaderNames } from \"./HeaderNames.js\";\r\nimport { ISynthesisConnectionFactory } from \"./ISynthesisConnectionFactory.js\";\r\nimport {\r\n    QueryParameterNames\r\n} from \"./QueryParameterNames.js\";\r\n\r\nexport class SpeechSynthesisConnectionFactory implements ISynthesisConnectionFactory {\r\n\r\n    private readonly synthesisUri: string = \"/tts/cognitiveservices/websocket/v1\";\r\n\r\n    public async create(\r\n        config: SynthesizerConfig,\r\n        authInfo: AuthInfo,\r\n        connectionId?: string): Promise<IConnection> {\r\n\r\n        let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\r\n        const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\r\n        const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\r\n        const endpointId = config.parameters.getProperty(PropertyId.SpeechServiceConnection_EndpointId, undefined);\r\n        const hostPrefix = (endpointId === undefined) ? \"tts\" : \"voice\";\r\n        const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".\" + hostPrefix + \".speech\" + hostSuffix);\r\n\r\n        const queryParams: IStringDictionary<string> = {};\r\n        const headers: IStringDictionary<string> = {};\r\n\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        if (endpointId !== undefined && endpointId !== \"\") {\r\n            if (!endpoint || endpoint.search(QueryParameterNames.CustomVoiceDeploymentId) === -1) {\r\n                queryParams[QueryParameterNames.CustomVoiceDeploymentId] = endpointId;\r\n            }\r\n        }\r\n\r\n        if (config.avatarEnabled) {\r\n            if (!endpoint || endpoint.search(QueryParameterNames.EnableAvatar) === -1) {\r\n                queryParams[QueryParameterNames.EnableAvatar] = \"true\";\r\n            }\r\n        }\r\n\r\n        if (!!endpoint) {\r\n            const endpointUrl = new URL(endpoint);\r\n            const pathName = endpointUrl.pathname;\r\n\r\n            if (pathName === \"\" || pathName === \"/\" || pathName.toLowerCase() === this.synthesisUri) {\r\n                // We need to generate the path, and we need to check for a redirect.\r\n                endpointUrl.pathname = this.synthesisUri;\r\n\r\n                endpoint = await ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());\r\n            }\r\n        }\r\n\r\n        if (!endpoint) {\r\n            endpoint = host + this.synthesisUri;\r\n        }\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.fromParameters(config.parameters), enableCompression, connectionId);\r\n    }\r\n}\r\n"]}