react-native-gizwits-sdk-v5 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt
CHANGED
|
@@ -27,8 +27,10 @@ import com.google.gson.JsonObject
|
|
|
27
27
|
import com.google.gson.annotations.SerializedName
|
|
28
28
|
import kotlinx.coroutines.CoroutineScope
|
|
29
29
|
import kotlinx.coroutines.Dispatchers
|
|
30
|
+
import kotlinx.coroutines.Job
|
|
30
31
|
import kotlinx.coroutines.SupervisorJob
|
|
31
32
|
import kotlinx.coroutines.cancel
|
|
33
|
+
import kotlinx.coroutines.isActive
|
|
32
34
|
import kotlinx.coroutines.launch
|
|
33
35
|
import org.json.JSONArray
|
|
34
36
|
import org.json.JSONObject
|
|
@@ -167,6 +169,7 @@ data class StopUpgradeParams(
|
|
|
167
169
|
|
|
168
170
|
class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
169
171
|
private val moduleScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
|
172
|
+
private var provideWiFiCredentialsJob: Job? = null
|
|
170
173
|
|
|
171
174
|
enum class EventName(val value: String) {
|
|
172
175
|
GizOTAProgressEvent("GizOTAProgressEvent"),
|
|
@@ -293,6 +296,8 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
293
296
|
fun stopProvideWiFiCredentials(options: ReadableMap, result: Callback) {
|
|
294
297
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizStopProvideWiFiCredentialsParams::class.java)
|
|
295
298
|
if (config !=null && device !=null) {
|
|
299
|
+
provideWiFiCredentialsJob?.cancel()
|
|
300
|
+
provideWiFiCredentialsJob = null
|
|
296
301
|
moduleScope.launch {
|
|
297
302
|
val res = when(config.type) {
|
|
298
303
|
CapacityTypes.BLE -> device.bleCapability.stopProvideWiFiCredentials()
|
|
@@ -335,37 +340,47 @@ fun wiFiCredentialsWithAirLinkEventHandler(event: GizWiFiActivatorEvent) {
|
|
|
335
340
|
fun provideWiFiCredentials(options: ReadableMap, result: Callback) {
|
|
336
341
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizProvideWiFiCredentialsParams::class.java)
|
|
337
342
|
if (config !=null && device !=null) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
343
|
+
provideWiFiCredentialsJob?.cancel()
|
|
344
|
+
provideWiFiCredentialsJob = moduleScope.launch {
|
|
345
|
+
val currentJob = coroutineContext[Job]!!
|
|
346
|
+
try {
|
|
347
|
+
val res = when(config.type) {
|
|
348
|
+
CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
|
|
349
|
+
config.ssid,
|
|
350
|
+
config.password,
|
|
351
|
+
config.timeout,
|
|
352
|
+
processHandler = {
|
|
353
|
+
wiFiCredentialsEventHandler(it, device)
|
|
354
|
+
},
|
|
355
|
+
bindWithUid = config.bindWithUid ?: false
|
|
356
|
+
)
|
|
357
|
+
CapacityTypes.LAN -> device.lanCapability.provideWiFiCredentials(
|
|
358
|
+
config.ssid,
|
|
359
|
+
config.password,
|
|
360
|
+
config.timeout,
|
|
361
|
+
processHandler = {
|
|
362
|
+
wiFiCredentialsEventHandler(it, device)
|
|
363
|
+
},
|
|
364
|
+
bindWithUid = false
|
|
365
|
+
)
|
|
366
|
+
CapacityTypes.MQTT -> device.mqttCapability.provideWiFiCredentials(
|
|
367
|
+
config.ssid,
|
|
368
|
+
config.password,
|
|
369
|
+
config.timeout,
|
|
370
|
+
processHandler = {
|
|
371
|
+
wiFiCredentialsEventHandler(it, device)
|
|
372
|
+
},
|
|
373
|
+
bindWithUid = false
|
|
374
|
+
)
|
|
375
|
+
}
|
|
376
|
+
if (isActive) {
|
|
377
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
378
|
+
}
|
|
379
|
+
} finally {
|
|
380
|
+
if (provideWiFiCredentialsJob === currentJob) {
|
|
381
|
+
provideWiFiCredentialsJob = null
|
|
382
|
+
}
|
|
367
383
|
}
|
|
368
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
369
384
|
}
|
|
370
385
|
}
|
|
371
386
|
}
|