react-native-gizwits-sdk-v5 1.5.0-beta.7 → 1.5.0-beta.8

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.
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReadableMap
8
8
  import com.facebook.react.bridge.WritableMap
9
9
  import com.facebook.react.modules.core.DeviceEventManagerModule
10
10
  import com.gizwits.smart.sdk.GizDevice
11
+ import com.gizwits.smart.sdk.esptouch.GizESPTouchSmartConfig
11
12
  import com.gizwits.smart.sdk.GizSDKManager
12
13
  import com.gizwits.smart.sdk.bluetooth.bleCapability
13
14
  import com.gizwits.smart.sdk.common.GizConfiguration
@@ -26,6 +27,7 @@ import com.google.gson.JsonObject
26
27
  import com.google.gson.annotations.SerializedName
27
28
  import kotlinx.coroutines.CoroutineScope
28
29
  import kotlinx.coroutines.Dispatchers
30
+ import kotlinx.coroutines.SupervisorJob
29
31
  import kotlinx.coroutines.launch
30
32
  import org.json.JSONArray
31
33
  import org.json.JSONObject
@@ -117,6 +119,18 @@ data class GizProvideWiFiCredentialsParams(
117
119
  @SerializedName("timeout")
118
120
  val timeout: Long,
119
121
  ): DeviceParams
122
+
123
+ data class GizProvideWiFiCredentialsWithAirLinkParams(
124
+ @SerializedName("ssid")
125
+ val ssid: String,
126
+ @SerializedName("password")
127
+ val password: String,
128
+ @SerializedName("timeout")
129
+ val timeout: Long,
130
+ @SerializedName("productKeys")
131
+ val productKeys: List<String>,
132
+ ): DeviceParams
133
+
120
134
  data class GizStopProvideWiFiCredentialsParams(
121
135
  @SerializedName("id")
122
136
  override val id: String,
@@ -147,6 +161,8 @@ data class StopUpgradeParams(
147
161
 
148
162
 
149
163
  class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
164
+ private val moduleScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
165
+
150
166
  enum class EventName(val value: String) {
151
167
  GizOTAProgressEvent("GizOTAProgressEvent"),
152
168
  GizProvideWiFiCredentialsEvent("GizProvideWiFiCredentialsEvent"),
@@ -163,11 +179,17 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
163
179
  }
164
180
 
165
181
  override fun getName() = "RNGizDeviceManagerModule"
182
+
183
+ override fun onCatalystInstanceDestroy() {
184
+ super.onCatalystInstanceDestroy()
185
+ moduleScope.cancel() // 取消所有协程
186
+ }
187
+
166
188
  @ReactMethod
167
189
  fun sendDp(options: ReadableMap, result: Callback) {
168
190
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizSendDPParams::class.java)
169
191
  if (config !=null && device !=null) {
170
- CoroutineScope(Dispatchers.IO).launch {
192
+ moduleScope.launch {
171
193
  try {
172
194
  val gson = Gson()
173
195
  val jsonObject = gson.fromJson(config.data, JsonObject::class.java)
@@ -188,7 +210,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
188
210
  fun getDp(options: ReadableMap, result: Callback) {
189
211
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDPParams::class.java)
190
212
  if (config !=null && device !=null) {
191
- CoroutineScope(Dispatchers.IO).launch {
213
+ moduleScope.launch {
192
214
  var res = when(config.type) {
193
215
  CapacityTypes.BLE -> device.bleCapability.getDp(config.attrs)
194
216
  CapacityTypes.LAN -> device.lanCapability.getDp(config.attrs)
@@ -210,7 +232,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
210
232
  fun getDeviceInfo(options: ReadableMap, result: Callback) {
211
233
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDeviceInfoParams::class.java)
212
234
  if (config !=null && device !=null) {
213
- CoroutineScope(Dispatchers.IO).launch {
235
+ moduleScope.launch {
214
236
  val res = when(config.type) {
215
237
  CapacityTypes.BLE -> device.bleCapability.getDeviceInfo()
216
238
  CapacityTypes.LAN -> device.lanCapability.getDeviceInfo()
@@ -225,7 +247,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
225
247
  fun updateDeviceInfo(options: ReadableMap, result: Callback) {
226
248
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, UpdateDeviceInfoParams::class.java)
227
249
  if (config !=null && device !=null) {
228
- CoroutineScope(Dispatchers.IO).launch {
250
+ moduleScope.launch {
229
251
  val res = device.updateDeviceInfo(config.alias, config.remark)
230
252
  GizRNCallbackManager.callbackWithResult(callback = result, result = res)
231
253
  // if (res.isSuccess) {
@@ -239,7 +261,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
239
261
  fun bind(options: ReadableMap, result: Callback) {
240
262
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizBindParams::class.java)
241
263
  if (config !=null && device !=null) {
242
- CoroutineScope(Dispatchers.IO).launch {
264
+ moduleScope.launch {
243
265
  val res = device.bind(config.alias, config.remark)
244
266
  GizRNCallbackManager.callbackWithResult(callback = result, result = res)
245
267
  // if (res.isSuccess) {
@@ -253,7 +275,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
253
275
  fun unBind(options: ReadableMap, result: Callback) {
254
276
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizUnBindParams::class.java)
255
277
  if (config !=null && device !=null) {
256
- CoroutineScope(Dispatchers.IO).launch {
278
+ moduleScope.launch {
257
279
  val res = device.unBind()
258
280
  GizRNCallbackManager.callbackWithResult(callback = result, result = res)
259
281
  if (res.isSuccess) {
@@ -266,7 +288,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
266
288
  fun stopProvideWiFiCredentials(options: ReadableMap, result: Callback) {
267
289
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizStopProvideWiFiCredentialsParams::class.java)
268
290
  if (config !=null && device !=null) {
269
- CoroutineScope(Dispatchers.IO).launch {
291
+ moduleScope.launch {
270
292
  val res = when(config.type) {
271
293
  CapacityTypes.BLE -> device.bleCapability.stopProvideWiFiCredentials()
272
294
  CapacityTypes.LAN -> device.lanCapability.stopProvideWiFiCredentials()
@@ -277,6 +299,14 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
277
299
  }
278
300
  }
279
301
 
302
+ @ReactMethod
303
+ fun stopProvideWiFiCredentialsWithAirLink(options: ReadableMap, result: Callback) {
304
+ moduleScope.launch {
305
+ val res = GizESPTouchSmartConfig.stopProvideWiFiCredentialsWithAirLink()
306
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
307
+ }
308
+ }
309
+
280
310
  fun wiFiCredentialsEventHandler(event: GizWiFiActivatorEvent, device: GizDevice) {
281
311
  val jsonObject = JSONObject()
282
312
  jsonObject.put("data", event.toString())
@@ -286,11 +316,21 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
286
316
  GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
287
317
  )
288
318
  }
319
+
320
+ fun wiFiCredentialsWithAirLinkEventHandler(event: GizWiFiActivatorEvent) {
321
+ val jsonObject = JSONObject()
322
+ jsonObject.put("data", event.toString())
323
+ sendEvent(
324
+ EventName.GizProvideWiFiCredentialsEvent.name,
325
+ GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
326
+ )
327
+ }
328
+
289
329
  @ReactMethod
290
330
  fun provideWiFiCredentials(options: ReadableMap, result: Callback) {
291
331
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizProvideWiFiCredentialsParams::class.java)
292
332
  if (config !=null && device !=null) {
293
- CoroutineScope(Dispatchers.IO).launch {
333
+ moduleScope.launch {
294
334
  val res = when(config.type) {
295
335
  CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
296
336
  config.ssid,
@@ -322,11 +362,31 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
322
362
  }
323
363
  }
324
364
 
365
+ @ReactMethod
366
+ fun provideWiFiCredentialsWithAirLink(options: ReadableMap, result: Callback) {
367
+ val config = RNGizParamsChecker.check(options, result, GizProvideWiFiCredentialsWithAirLinkParams::class.java)
368
+ config?.let {
369
+ moduleScope.launch {
370
+ val res = GizESPTouchSmartConfig.provideWiFiCredentialsWithAirLink(
371
+ reactApplicationContext,
372
+ config.ssid,
373
+ config.password,
374
+ config.timeout,
375
+ config.productKeys,
376
+ processHandler = {
377
+ wiFiCredentialsWithAirLinkEventHandler(it)
378
+ }
379
+ )
380
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
381
+ }
382
+ }
383
+ }
384
+
325
385
  @ReactMethod
326
386
  fun register(options: ReadableMap, result: Callback) {
327
387
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizRegisterDeviceParams::class.java)
328
388
  if (config !=null && device !=null) {
329
- CoroutineScope(Dispatchers.IO).launch {
389
+ moduleScope.launch {
330
390
  val res = device.register()
331
391
  GizRNCallbackManager.callbackWithResult(callback = result, result = res)
332
392
  }
@@ -337,7 +397,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
337
397
  fun connect(options: ReadableMap, result: Callback) {
338
398
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizConnectParams::class.java)
339
399
  if (config !=null && device !=null) {
340
- CoroutineScope(Dispatchers.IO).launch {
400
+ moduleScope.launch {
341
401
  val res = when(config.type) {
342
402
  CapacityTypes.BLE -> device.bleCapability.connect()
343
403
  CapacityTypes.LAN -> device.lanCapability.connect()
@@ -351,7 +411,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
351
411
  fun disConnect(options: ReadableMap, result: Callback) {
352
412
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizDisConnectParams::class.java)
353
413
  if (config !=null && device !=null) {
354
- CoroutineScope(Dispatchers.IO).launch {
414
+ moduleScope.launch {
355
415
  val res = when(config.type) {
356
416
  CapacityTypes.BLE -> device.bleCapability.disConnect()
357
417
  CapacityTypes.LAN -> device.lanCapability.disConnect()
@@ -366,7 +426,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
366
426
  fun checkUpdate(options: ReadableMap, result: Callback) {
367
427
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
368
428
  if (config !=null && device !=null) {
369
- CoroutineScope(Dispatchers.IO).launch {
429
+ moduleScope.launch {
370
430
  val res = when(config.type) {
371
431
  CapacityTypes.BLE -> device.bleCapability.checkUpdate(config.firmwareType)
372
432
  CapacityTypes.LAN -> device.lanCapability.checkUpdate(config.firmwareType)
@@ -393,7 +453,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
393
453
  fun startUpgrade(options: ReadableMap, result: Callback) {
394
454
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
395
455
  if (config !=null && device !=null) {
396
- CoroutineScope(Dispatchers.IO).launch {
456
+ moduleScope.launch {
397
457
  val res = when(config.type) {
398
458
  CapacityTypes.BLE -> {
399
459
  device.bleCapability.startUpgrade(config.firmwareType, processHandler = {
@@ -415,7 +475,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
415
475
  fun cancelUpgrade(options: ReadableMap, result: Callback) {
416
476
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopUpgradeParams::class.java)
417
477
  if (config !=null && device !=null) {
418
- CoroutineScope(Dispatchers.IO).launch {
478
+ moduleScope.launch {
419
479
  val res = when(config.type) {
420
480
  CapacityTypes.BLE -> device.bleCapability.cancelUpgrade()
421
481
  CapacityTypes.LAN -> device.lanCapability.cancelUpgrade()
@@ -430,7 +490,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
430
490
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StartMusicalRhythmParams::class.java)
431
491
  print("startMusicalRhythm ${config}")
432
492
  if (config !=null && device !=null) {
433
- CoroutineScope(Dispatchers.IO).launch {
493
+ moduleScope.launch {
434
494
  val res = device.startMusicalRhythm(config.sensitivity, config.mode) { data ->
435
495
  if (config.needMonitor) {
436
496
  val jsonObject = JSONObject()
@@ -465,7 +525,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
465
525
  fun stopMusicalRhythm(options: ReadableMap, result: Callback) {
466
526
  val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopMusicalRhythmParams::class.java)
467
527
  if (config !=null && device !=null) {
468
- CoroutineScope(Dispatchers.IO).launch {
528
+ moduleScope.launch {
469
529
  val res = device.stopMusicalRhythm();
470
530
  GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
471
531
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.5.0-beta.7",
3
+ "version": "1.5.0-beta.8",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",
@@ -19,6 +19,6 @@ Pod::Spec.new do |s|
19
19
 
20
20
  s.dependency 'React'
21
21
  s.dependency 'CryptoSwift', '~> 1.8.0'
22
- s.dependency 'GizwitsiOSSDK', '~> 1.7.9'
22
+ s.dependency 'GizwitsiOSSDK', '~> 1.8.0'
23
23
 
24
24
  end