From 74126af19f80a65fde101683777525fb6e0566ad Mon Sep 17 00:00:00 2001 From: David Pine Date: Thu, 14 Apr 2022 15:11:10 -0500 Subject: [PATCH] Minor clean up, and verified usage through testing. --- .../wwwroot/blazorators.speechRecognition.js | 12 +++++++++--- .../wwwroot/blazorators.speechRecognition.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Blazor.SpeechRecognition.WebAssembly/wwwroot/blazorators.speechRecognition.js b/src/Blazor.SpeechRecognition.WebAssembly/wwwroot/blazorators.speechRecognition.js index 78a2e0d..8e2f613 100644 --- a/src/Blazor.SpeechRecognition.WebAssembly/wwwroot/blazorators.speechRecognition.js +++ b/src/Blazor.SpeechRecognition.WebAssembly/wwwroot/blazorators.speechRecognition.js @@ -42,8 +42,11 @@ export const recognizeSpeech = if (typeof (webkitSpeechRecognition) !== "undefined" && recognitionImplementation == null) recognitionImplementation = webkitSpeechRecognition; - if (recognitionImplementation == null) { - dotnetObj.invokeMethodAsync(onErrorMethodName, key, { "error": "Not supported", "message": "This browser does not support any known SpeechRecognition method."}); + if (onErrorMethodName && recognitionImplementation == null) { + dotnetObj.invokeMethod(onErrorMethodName, key, { + Error: "Not supported", + Message: "This browser does not support any known SpeechRecognition method." + }); return; } @@ -63,7 +66,10 @@ export const recognizeSpeech = } if (onErrorMethodName) { _recognition.onerror = (error) => { - dotnetObj.invokeMethod(onErrorMethodName, key, error); + dotnetObj.invokeMethod(onErrorMethodName, key, { + Error: error.error, + Message: error.message + }); }; } _recognition.onresult = (result) => { diff --git a/src/Blazor.SpeechRecognition/wwwroot/blazorators.speechRecognition.js b/src/Blazor.SpeechRecognition/wwwroot/blazorators.speechRecognition.js index f6d7953..08c6790 100644 --- a/src/Blazor.SpeechRecognition/wwwroot/blazorators.speechRecognition.js +++ b/src/Blazor.SpeechRecognition/wwwroot/blazorators.speechRecognition.js @@ -42,8 +42,11 @@ export const recognizeSpeech = if (typeof (webkitSpeechRecognition) !== "undefined" && recognitionImplementation == null) recognitionImplementation = webkitSpeechRecognition; - if (recognitionImplementation == null) { - dotnetObj.invokeMethodAsync(onErrorMethodName, key, { "error": "Not supported", "message": "This browser does not support any known SpeechRecognition method." }); + if (onErrorMethodName && recognitionImplementation == null) { + dotnetObj.invokeMethodAsync(onErrorMethodName, key, { + Error: "Not supported", + Message: "This browser does not support any known SpeechRecognition method." + }); return; } @@ -63,7 +66,10 @@ export const recognizeSpeech = } if (onErrorMethodName) { _recognition.onerror = (error) => { - dotnetObj.invokeMethodAsync(onErrorMethodName, key, error); + dotnetObj.invokeMethodAsync(onErrorMethodName, key, { + Error: error.error, + Message: error.message + }); }; } _recognition.onresult = (result) => {