react-native-gizwits-sdk-v5 1.5.0-beta.3 → 1.5.0-beta.31
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
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
528
|
+
moduleScope.launch {
|
|
469
529
|
val res = device.stopMusicalRhythm();
|
|
470
530
|
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
|
|
471
531
|
}
|
|
@@ -23,6 +23,8 @@ RCT_EXTERN_METHOD(updateDeviceInfo:(NSDictionary *)options result:(RCTResponseSe
|
|
|
23
23
|
RCT_EXTERN_METHOD(unBind:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
24
24
|
RCT_EXTERN_METHOD(stopProvideWiFiCredentials:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
25
25
|
RCT_EXTERN_METHOD(provideWiFiCredentials:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
26
|
+
RCT_EXTERN_METHOD(provideWiFiCredentialsWithAirLink:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
27
|
+
RCT_EXTERN_METHOD(stopProvideWiFiCredentialsWithAirLink:(RCTResponseSenderBlock)result)
|
|
26
28
|
|
|
27
29
|
RCT_EXTERN_METHOD(startMusicalRhythm:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
28
30
|
RCT_EXTERN_METHOD(stopMusicalRhythm:(NSDictionary *)options result:(RCTResponseSenderBlock)result)
|
|
@@ -80,6 +80,12 @@ struct ProvideWiFiCredentialsParams: Decodable {
|
|
|
80
80
|
var password: String
|
|
81
81
|
var timeout: Int
|
|
82
82
|
}
|
|
83
|
+
struct ProvideWiFiCredentialsWithAirLinkParams: Decodable {
|
|
84
|
+
var ssid: String
|
|
85
|
+
var password: String
|
|
86
|
+
var timeout: Int
|
|
87
|
+
var productKeys: [String]
|
|
88
|
+
}
|
|
83
89
|
struct StopProvideWiFiCredentialsParams: Decodable {
|
|
84
90
|
var type: GizwitsiOSSDK.GizCapability
|
|
85
91
|
var id: String
|
|
@@ -449,14 +455,30 @@ class RNGizDeviceManagerModule: RCTEventEmitter {
|
|
|
449
455
|
|
|
450
456
|
@objc
|
|
451
457
|
public func provideWiFiCredentialsWithAirLink(_ options: NSDictionary, result: @escaping RCTResponseSenderBlock) {
|
|
452
|
-
if let params = RNGizParamsChecker.check(options: options, result: result, paramsType:
|
|
458
|
+
if let params = RNGizParamsChecker.check(options: options, result: result, paramsType: ProvideWiFiCredentialsWithAirLinkParams.self) {
|
|
459
|
+
@Sendable func progressHandler(event: GizWiFiActivatorEvent) {
|
|
460
|
+
// 推送数据到 GizOTAProgressEvent
|
|
461
|
+
let data = [
|
|
462
|
+
"data": event.rawValue
|
|
463
|
+
] as [String : Any]
|
|
464
|
+
sendEvent(withName: "GizProvideWiFiCredentialsEvent", body: data)
|
|
465
|
+
}
|
|
453
466
|
Task {
|
|
454
467
|
var data: GizResult<GizBaseProfile?, GizActivatorException?>
|
|
455
|
-
data = await ESPTouchSmartConfig.sharedInstance.provideWiFiCredentialsWithAirLink(ssid: params.ssid, password: params.password, timeout: params.timeout,
|
|
468
|
+
data = await ESPTouchSmartConfig.sharedInstance.provideWiFiCredentialsWithAirLink(ssid: params.ssid, password: params.password, timeout: params.timeout, productKeys: params.productKeys, processHandler: progressHandler)
|
|
456
469
|
GizRNCallbackManager.callbackWithResult(callback: result, result:data)
|
|
457
470
|
}
|
|
458
471
|
}
|
|
459
472
|
}
|
|
473
|
+
|
|
474
|
+
@objc
|
|
475
|
+
public func stopProvideWiFiCredentialsWithAirLink(_ result: @escaping RCTResponseSenderBlock) {
|
|
476
|
+
Task {
|
|
477
|
+
var data: GizResult<Int?, GizActivatorException?>
|
|
478
|
+
data = await ESPTouchSmartConfig.sharedInstance.stopProvideWiFiCredentialsWithAirLink()
|
|
479
|
+
GizRNCallbackManager.callbackWithResult(callback: result, result:data)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
460
482
|
|
|
461
483
|
@objc
|
|
462
484
|
public func stopProvideWiFiCredentials(_ options: NSDictionary, result: @escaping RCTResponseSenderBlock) {
|
package/package.json
CHANGED