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.
@@ -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
- moduleScope.launch {
339
- val res = when(config.type) {
340
- CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
341
- config.ssid,
342
- config.password,
343
- config.timeout,
344
- processHandler = {
345
- wiFiCredentialsEventHandler(it, device)
346
- },
347
- bindWithUid = config.bindWithUid ?: false
348
- )
349
- CapacityTypes.LAN -> device.lanCapability.provideWiFiCredentials(
350
- config.ssid,
351
- config.password,
352
- config.timeout,
353
- processHandler = {
354
- wiFiCredentialsEventHandler(it, device)
355
- },
356
- bindWithUid = false
357
- )
358
- CapacityTypes.MQTT -> device.mqttCapability.provideWiFiCredentials(
359
- config.ssid,
360
- config.password,
361
- config.timeout,
362
- processHandler = {
363
- wiFiCredentialsEventHandler(it, device)
364
- },
365
- bindWithUid = false
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",