{"version":3,"sources":["src/common.speech/ConversationTranscriberConnectionFactory.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,WAAW,EACX,iBAAiB,EACpB,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EACH,qBAAqB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACH,QAAQ,EACR,gBAAgB,EAEnB,MAAM,cAAc,CAAC;AAMtB,qBAAa,wCAAyC,SAAQ,qBAAqB;IAC/E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAEtD,MAAM,CACf,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,QAAQ,EAClB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA4DhD,SAAS,CAAC,cAAc,CACpB,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACtC,QAAQ,EAAE,MAAM,GAAG,IAAI;CAuB9B","file":"ConversationTranscriberConnectionFactory.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.js\";\nimport {\n    IConnection,\n    IStringDictionary\n} from \"../common/Exports.js\";\nimport {\n    PropertyId\n} from \"../sdk/Exports.js\";\nimport {\n    ServicePropertiesPropertyName\n} from \"../common.speech/Exports.js\";\nimport {\n    ConnectionFactoryBase\n} from \"./ConnectionFactoryBase.js\";\nimport {\n    AuthInfo,\n    RecognizerConfig,\n    WebsocketMessageFormatter\n} from \"./Exports.js\";\nimport { HeaderNames } from \"./HeaderNames.js\";\nimport {\n    QueryParameterNames\n} from \"./QueryParameterNames.js\";\n\nexport class ConversationTranscriberConnectionFactory extends ConnectionFactoryBase {\n    private readonly universalUri: string = \"/stt/speech/universal/v2\";\n\n    public async create(\n        config: RecognizerConfig,\n        authInfo: AuthInfo,\n        connectionId?: string): Promise<IConnection> {\n\n        let endpoint: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Endpoint, undefined);\n        const region: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Region, undefined);\n        const hostSuffix: string = ConnectionFactoryBase.getHostSuffix(region);\n        const host: string = config.parameters.getProperty(PropertyId.SpeechServiceConnection_Host, \"wss://\" + region + \".stt.speech\" + hostSuffix);\n        const queryParams: IStringDictionary<string> = {};\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.CustomSpeechDeploymentId) === -1) {\n                queryParams[QueryParameterNames.CustomSpeechDeploymentId] = endpointId;\n            }\n        } else if (language) {\n            if (!endpoint || endpoint.search(QueryParameterNames.Language) === -1) {\n                queryParams[QueryParameterNames.Language] = language;\n            }\n        }\n\n        if (config.autoDetectSourceLanguages !== undefined) {\n            queryParams[QueryParameterNames.EnableLanguageId] = \"true\";\n        }\n\n        this.setV2UrlParams(config, queryParams, endpoint);\n\n        if (!!endpoint) {\n            const endpointUrl = new URL(endpoint);\n            const pathName = endpointUrl.pathname;\n\n            if (pathName === \"\" || pathName === \"/\") {\n                // We need to generate the path, and we need to check for a redirect.\n                endpointUrl.pathname = this.universalUri;\n\n                endpoint = await ConnectionFactoryBase.getRedirectUrlFromEndpoint(endpointUrl.toString());\n            }\n        }\n\n        if (!endpoint) {\n            endpoint = `${host}${this.universalUri}`;\n        }\n\n        const headers: IStringDictionary<string> = {};\n        if (authInfo.token !== undefined && authInfo.token !== \"\") {\n            headers[authInfo.headerName] = authInfo.token;\n        }\n        headers[HeaderNames.ConnectionId] = connectionId;\n\n        const enableCompression: boolean = config.parameters.getProperty(\"SPEECH-EnableWebsocketCompression\", \"false\") === \"true\";\n\n        const webSocketConnection = new WebsocketConnection(endpoint, queryParams, headers, new WebsocketMessageFormatter(), ProxyInfo.fromRecognizerConfig(config), enableCompression, connectionId);\n\n        // Set the value of SpeechServiceConnection_Url to webSocketConnection.uri (and not to `endpoint`), since this value is the final\n        // URI that was used to make the connection (including query parameters).\n        const uri: string = webSocketConnection.uri;\n        config.parameters.setProperty(PropertyId.SpeechServiceConnection_Url, uri);\n\n        return webSocketConnection;\n    }\n\n    protected setV2UrlParams(\n        config: RecognizerConfig,\n        queryParams: IStringDictionary<string>,\n        endpoint: string): void {\n\n        const propertyIdToParameterMap: Map<number, string> = new Map([\n            [PropertyId.Speech_SegmentationSilenceTimeoutMs, QueryParameterNames.SegmentationSilenceTimeoutMs],\n            [PropertyId.SpeechServiceConnection_EnableAudioLogging, QueryParameterNames.EnableAudioLogging],\n            [PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, QueryParameterNames.EndSilenceTimeoutMs],\n            [PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, QueryParameterNames.InitialSilenceTimeoutMs],\n            [PropertyId.SpeechServiceResponse_PostProcessingOption, QueryParameterNames.Postprocessing],\n            [PropertyId.SpeechServiceResponse_ProfanityOption, QueryParameterNames.Profanity],\n            [PropertyId.SpeechServiceResponse_StablePartialResultThreshold, QueryParameterNames.StableIntermediateThreshold],\n        ]);\n\n        propertyIdToParameterMap.forEach((parameterName: string, propertyId: PropertyId): void => {\n            this.setUrlParameter(propertyId, parameterName, config, queryParams, endpoint);\n        });\n\n\n        const serviceProperties: IStringDictionary<string> = JSON.parse(config.parameters.getProperty(ServicePropertiesPropertyName, \"{}\")) as IStringDictionary<string>;\n\n        Object.keys(serviceProperties).forEach((value: string): void => {\n            queryParams[value] = serviceProperties[value];\n        });\n    }\n}\n"]}