UNPKG

@euirim/microsoft-cognitiveservices-speech-sdk

Version:
1 lines 4.61 kB
{"version":3,"sources":["src/sdk/Connection.ts"],"names":[],"mappings":"AAYA,OAAO,EACH,mBAAmB,EACnB,UAAU,EACb,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,qBAAqB,CAAwB;IACrD,OAAO,CAAC,iBAAiB,CAAc;IAEvC;;;;OAIG;WACW,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU;IAqBhE;;;;;;;OAOG;IACI,cAAc,IAAI,IAAI;IAI7B;;;;;OAKG;IACI,eAAe,IAAI,IAAI;IAI9B;;OAEG;IACI,SAAS,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAEtD;;OAEG;IACI,YAAY,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAEzD;;OAEG;IACI,KAAK,IAAI,IAAI;CAGvB","file":"Connection.d.ts","sourcesContent":["//\n// Copyright (c) Microsoft. All rights reserved.\n// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.\n//\n\nimport {\n ServiceRecognizerBase,\n} from \"../common.speech/Exports\";\nimport {\n ConnectionEvent,\n IDetachable,\n} from \"../common/Exports\";\nimport {\n ConnectionEventArgs,\n Recognizer,\n} from \"./Exports\";\n\n/**\n * Connection is a proxy class for managing connection to the speech service of the specified Recognizer.\n * By default, a Recognizer autonomously manages connection to service when needed.\n * The Connection class provides additional methods for users to explicitly open or close a connection and\n * to subscribe to connection status changes.\n * The use of Connection is optional, and mainly for scenarios where fine tuning of application\n * behavior based on connection status is needed. Users can optionally call Open() to manually set up a connection\n * in advance before starting recognition on the Recognizer associated with this Connection.\n * If the Recognizer needs to connect or disconnect to service, it will\n * setup or shutdown the connection independently. In this case the Connection will be notified by change of connection\n * status via Connected/Disconnected events.\n * Added in version 1.2.0.\n */\nexport class Connection {\n private privServiceRecognizer: ServiceRecognizerBase;\n private privEventListener: IDetachable;\n\n /**\n * Gets the Connection instance from the specified recognizer.\n * @param recognizer The recognizer associated with the connection.\n * @return The Connection instance of the recognizer.\n */\n public static fromRecognizer(recognizer: Recognizer): Connection {\n const recoBase: ServiceRecognizerBase = recognizer.internalData as ServiceRecognizerBase;\n\n const ret: Connection = new Connection();\n\n ret.privServiceRecognizer = recoBase;\n ret.privEventListener = ret.privServiceRecognizer.connectionEvents.attach((connectionEvent: ConnectionEvent): void => {\n if (connectionEvent.name === \"ConnectionEstablishedEvent\") {\n if (!!ret.connected) {\n ret.connected(new ConnectionEventArgs(connectionEvent.connectionId));\n }\n } else if (connectionEvent.name === \"ConnectionClosedEvent\") {\n if (!!ret.disconnected) {\n ret.disconnected(new ConnectionEventArgs(connectionEvent.connectionId));\n }\n }\n });\n\n return ret;\n }\n\n /**\n * Starts to set up connection to the service.\n * Users can optionally call openConnection() to manually set up a connection in advance before starting recognition on the\n * Recognizer associated with this Connection. After starting recognition, calling Open() will have no effect\n *\n * Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to\n * be notfied when the connection is established.\n */\n public openConnection(): void {\n this.privServiceRecognizer.connect();\n }\n\n /**\n * Closes the connection the service.\n * Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer.\n *\n * If closeConnection() is called during recognition, recognition will fail and cancel wtih an error.\n */\n public closeConnection(): void {\n this.privServiceRecognizer.disconnect();\n }\n\n /**\n * The Connected event to indicate that the recognizer is connected to service.\n */\n public connected: (args: ConnectionEventArgs) => void;\n\n /**\n * The Diconnected event to indicate that the recognizer is disconnected from service.\n */\n public disconnected: (args: ConnectionEventArgs) => void;\n\n /**\n * Dispose of associated resources.\n */\n public close(): void {\n /* tslint:disable:no-empty */\n }\n}\n"]}