correctly bind timeout when webWorkerLoadType is off

This commit is contained in:
glenn 2023-08-23 12:10:45 -04:00
Родитель 4175b698d6
Коммит 9ebb48b866
2 изменённых файлов: 20 добавлений и 3 удалений

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

@ -154,8 +154,13 @@ export abstract class ServiceRecognizerBase implements IDisposable {
this.privSpeechContext = new SpeechContext(this.privDynamicGrammar);
this.privAgentConfig = new AgentConfig();
const webWorkerLoadType: string = this.privRecognizerConfig.parameters.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase();
if (webWorkerLoadType === "off" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") {
if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") {
this.privSetTimeout = Timeout.setTimeout;
} else {
if (typeof window !== "undefined") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.privSetTimeout = window.setTimeout.bind(window);
}
}
this.connectionEvents.attach((connectionEvent: ConnectionEvent): void => {

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

@ -79,8 +79,20 @@ export class ConversationTranslatorRecognizer extends Recognizer implements Conv
this.privProperties = serviceConfigImpl.properties.clone();
this.privConnection = Connection.fromRecognizer(this);
const webWorkerLoadType: string = this.privProperties.getProperty(PropertyId.WebWorkerLoadType, "on").toLowerCase();
this.privClearTimeout = (typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout; this.privSetTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.setTimeout : setTimeout;
this.privClearTimeout = (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") ? Timeout.clearTimeout : clearTimeout;
if (webWorkerLoadType === "on" && typeof (Blob) !== "undefined" && typeof (Worker) !== "undefined") {
this.privSetTimeout = Timeout.setTimeout;
this.privClearTimeout = Timeout.clearTimeout;
} else {
if (typeof window !== "undefined") {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.privSetTimeout = window.setTimeout.bind(window);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.privClearTimeout = window.clearTimeout.bind(window);
} else {
this.privSetTimeout = setTimeout;
this.privClearTimeout = clearTimeout;
}
}
}
public canceled: (sender: ConversationRecognizer, event: ConversationTranslationCanceledEventArgs) => void;