Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 440b50b

Browse files
committed
fix: resolve initialize early if already initialized (idempotent)
1 parent f49f1bd commit 440b50b

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

android/src/main/java/com/reactnativespokestack/SpokestackModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ class SpokestackModule(private val reactContext: ReactApplicationContext): React
122122

123123
@ReactMethod
124124
fun initialize(clientId: String, clientSecret: String, config: ReadableMap, promise: Promise) = runBlocking(Dispatchers.Default) {
125+
if (initialized()) {
126+
promise.resolve(null)
127+
return@runBlocking
128+
}
125129
if (clientId.isEmpty() || clientSecret.isEmpty()) {
126130
val e = IllegalArgumentException("Client ID and Client Secret are required to initialize Spokestack")
127131
promise.reject(e)

example/src/checkPermission.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export default async function checkPermission() {
2222

2323
// iOS brings up its own dialogs automatically
2424
// However, the best way to handle permissions is
25-
// to request both microphone and speech recognition
26-
// access in an onboarding screen for your app that
25+
// to request speech recognition access in an
26+
// onboarding screen for your app that
2727
// explains why the permissions are needed.
2828
return true
2929
}

ios/RNSpokestack.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class RNSpokestack: RCTEventEmitter, SpokestackDelegate {
240240
@objc(initialize:withClientSecret:withConfig:withResolver:withRejecter:)
241241
func initialize(clientId: String, clientSecret: String, config: Dictionary<String, Any>?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
242242
if speechPipeline != nil {
243+
resolve(nil)
243244
return
244245
}
245246
downloader = Downloader(allowCellular: RCTConvert.bool(config?["allowCellular"]), refreshModels: RCTConvert.bool(config?["refreshModels"]))

0 commit comments

Comments
 (0)