@euirim/microsoft-cognitiveservices-speech-sdk
Version:
Microsoft Cognitive Services Speech SDK for JavaScript
78 lines (76 loc) • 3.55 kB
JavaScript
;
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
Object.defineProperty(exports, "__esModule", { value: true });
var Exports_1 = require("./Exports");
/**
* Connection is a proxy class for managing connection to the speech service of the specified Recognizer.
* By default, a Recognizer autonomously manages connection to service when needed.
* The Connection class provides additional methods for users to explicitly open or close a connection and
* to subscribe to connection status changes.
* The use of Connection is optional, and mainly for scenarios where fine tuning of application
* behavior based on connection status is needed. Users can optionally call Open() to manually set up a connection
* in advance before starting recognition on the Recognizer associated with this Connection.
* If the Recognizer needs to connect or disconnect to service, it will
* setup or shutdown the connection independently. In this case the Connection will be notified by change of connection
* status via Connected/Disconnected events.
* Added in version 1.2.0.
*/
var Connection = /** @class */ (function () {
function Connection() {
}
/**
* Gets the Connection instance from the specified recognizer.
* @param recognizer The recognizer associated with the connection.
* @return The Connection instance of the recognizer.
*/
Connection.fromRecognizer = function (recognizer) {
var recoBase = recognizer.internalData;
var ret = new Connection();
ret.privServiceRecognizer = recoBase;
ret.privEventListener = ret.privServiceRecognizer.connectionEvents.attach(function (connectionEvent) {
if (connectionEvent.name === "ConnectionEstablishedEvent") {
if (!!ret.connected) {
ret.connected(new Exports_1.ConnectionEventArgs(connectionEvent.connectionId));
}
}
else if (connectionEvent.name === "ConnectionClosedEvent") {
if (!!ret.disconnected) {
ret.disconnected(new Exports_1.ConnectionEventArgs(connectionEvent.connectionId));
}
}
});
return ret;
};
/**
* Starts to set up connection to the service.
* Users can optionally call openConnection() to manually set up a connection in advance before starting recognition on the
* Recognizer associated with this Connection. After starting recognition, calling Open() will have no effect
*
* Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to
* be notfied when the connection is established.
*/
Connection.prototype.openConnection = function () {
this.privServiceRecognizer.connect();
};
/**
* Closes the connection the service.
* Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer.
*
* If closeConnection() is called during recognition, recognition will fail and cancel wtih an error.
*/
Connection.prototype.closeConnection = function () {
this.privServiceRecognizer.disconnect();
};
/**
* Dispose of associated resources.
*/
Connection.prototype.close = function () {
/* tslint:disable:no-empty */
};
return Connection;
}());
exports.Connection = Connection;
//# sourceMappingURL=Connection.js.map