Use conventional idioms to access connection and phraseListGrammar fr… (#586)

* Use conventional idioms to access connection and phraseListGrammar from ConversationTranscriber

* set connection property on ConversationTranscriber as deprecated

* add internalData property for ConversationTranscriber, remove recognizer property
This commit is contained in:
Glenn Harper 2022-10-26 16:08:52 -07:00 коммит произвёл GitHub
Родитель 3bc4dd907b
Коммит 7d1627bfcc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 24 добавлений и 27 удалений

Просмотреть файл

@ -22,6 +22,7 @@ import { Contracts } from "./Contracts";
import {
ConnectionEventArgs,
ConnectionMessageEventArgs,
ConversationTranscriber,
Recognizer,
ServiceEventArgs,
SpeechSynthesizer,
@ -50,9 +51,8 @@ export class Connection {
* @param recognizer The recognizer associated with the connection.
* @return The Connection instance of the recognizer.
*/
public static fromRecognizer(recognizer: Recognizer): Connection {
const recoBase: ServiceRecognizerBase = recognizer.internalData as ServiceRecognizerBase;
public static fromRecognizer(recognizer: Recognizer | ConversationTranscriber): Connection {
const recoBase = recognizer.internalData as ServiceRecognizerBase;
const ret: Connection = new Connection();
ret.privInternalData = recoBase;

Просмотреть файл

@ -5,7 +5,10 @@ import {
DynamicGrammarBuilder,
ServiceRecognizerBase,
} from "../common.speech/Exports";
import { Recognizer } from "./Exports";
import {
ConversationTranscriber,
Recognizer
} from "./Exports";
/**
* Allows additions of new phrases to improve speech recognition.
@ -24,9 +27,8 @@ export class PhraseListGrammar {
* Creates a PhraseListGrammar from a given speech recognizer. Will accept any recognizer that derives from @class Recognizer.
* @param recognizer The recognizer to add phrase lists to.
*/
public static fromRecognizer(recognizer: Recognizer): PhraseListGrammar {
const recoBase: ServiceRecognizerBase = recognizer.internalData as ServiceRecognizerBase;
public static fromRecognizer(recognizer: Recognizer | ConversationTranscriber): PhraseListGrammar {
const recoBase = recognizer.internalData as ServiceRecognizerBase;
return new PhraseListGrammar(recoBase);
}

Просмотреть файл

@ -9,7 +9,6 @@ import {
CancellationEventArgs,
Connection,
ConversationTranscriptionEventArgs,
PhraseListGrammar,
PropertyCollection,
PropertyId,
SessionEventArgs
@ -129,25 +128,21 @@ export class ConversationTranscriber implements ConversationTranscriptionHandler
}
/**
* Gets the Connection instance from the specified recognizer.
* @member ConversationTranscriber.prototype.connection
* @function
* @public
* @return {Connection} The Connection instance of the recognizer.
* @Internal
* Internal data member to support fromRecognizer* pattern methods on other classes.
* Do not use externally, object returned will change without warning or notice.
*/
public get connection(): Connection {
return Connection.fromRecognizer(this.privRecognizer);
public get internalData(): object {
return this.privRecognizer.internalData;
}
/**
* Gets the PhraseListGrammar instance from the specified recognizer.
* @member ConversationTranscriber.prototype.phraseListGrammar
* @function
* @public
* @return {PhraseListGrammar} The PhraseListGrammar instance of the recognizer.
* @Deprecated
* @Obsolete
* Please use the Connection.fromRecognizer pattern to obtain a connection object
*/
public get phraseListGrammar(): PhraseListGrammar {
return PhraseListGrammar.fromRecognizer(this.privRecognizer);
public get connection(): Connection {
return Connection.fromRecognizer(this.privRecognizer);
}
/**
@ -174,7 +169,7 @@ export class ConversationTranscriber implements ConversationTranscriptionHandler
}
/**
* @param {Conversation} converation - conversation to be recognized
* @param {Conversation} conversation - conversation to be recognized
*/
public joinConversationAsync(conversation: IConversation, cb?: Callback, err?: Callback): void {
const conversationImpl = conversation as ConversationImpl;

Просмотреть файл

@ -421,16 +421,16 @@ test("Create Conversation and create PhraseListGrammar", (done: jest.DoneCallbac
const t: sdk.ConversationTranscriber = BuildTranscriber();
t.joinConversationAsync(c,
() => {
(): void => {
try {
var phraseListGrammar = t.phraseListGrammar
expect(phraseListGrammar).not.toBeUndefined()
const phraseListGrammar = sdk.PhraseListGrammar.fromRecognizer(t);
expect(phraseListGrammar).not.toBeUndefined();
done();
} catch (error) {
done(error);
}
},
(error: string) => {
(error: string): void => {
done(error);
});
});