react-native-gizwits-sdk-v5 1.5.0-beta.4 → 1.5.0-beta.40
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/build.gradle +6 -4
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt +79 -16
- package/ios/RNGizDeviceManagerModule.m +2 -0
- package/ios/RNGizDeviceManagerModule.swift +11 -4
- package/package.json +1 -1
- package/react-native-gizwits-sdk-v5.podspec +1 -1
package/android/build.gradle
CHANGED
|
@@ -64,11 +64,13 @@ dependencies {
|
|
|
64
64
|
implementation "androidx.startup:startup-runtime:$startup_version"
|
|
65
65
|
|
|
66
66
|
implementation 'com.github.wendykierp:JTransforms:3.1'
|
|
67
|
+
// ESPTouch
|
|
68
|
+
implementation 'com.github.EspressifApp:lib-esptouch-android:1.1.1'
|
|
67
69
|
|
|
68
|
-
implementation("io.github.gizwits:sdk:1.
|
|
69
|
-
implementation("io.github.gizwits:sdk-bluetooth:1.
|
|
70
|
-
implementation("io.github.gizwits:sdk-lan:1.
|
|
71
|
-
implementation("io.github.gizwits:sdk-mqtt:1.
|
|
70
|
+
implementation("io.github.gizwits:sdk:1.4.2")
|
|
71
|
+
implementation("io.github.gizwits:sdk-bluetooth:1.4.2")
|
|
72
|
+
implementation("io.github.gizwits:sdk-lan:1.4.2")
|
|
73
|
+
implementation("io.github.gizwits:sdk-mqtt:1.4.2")
|
|
72
74
|
// implementation files('libs/sdk-release.aar', 'libs/sdk-bluetooth-release.aar', 'libs/sdk-lan-release.aar', 'libs/sdk-mqtt-release.aar')
|
|
73
75
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
|
|
74
76
|
// retrofit
|
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,8 @@ 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
|
|
31
|
+
import kotlinx.coroutines.cancel
|
|
29
32
|
import kotlinx.coroutines.launch
|
|
30
33
|
import org.json.JSONArray
|
|
31
34
|
import org.json.JSONObject
|
|
@@ -117,6 +120,20 @@ data class GizProvideWiFiCredentialsParams(
|
|
|
117
120
|
@SerializedName("timeout")
|
|
118
121
|
val timeout: Long,
|
|
119
122
|
): DeviceParams
|
|
123
|
+
|
|
124
|
+
data class GizProvideWiFiCredentialsWithAirLinkParams(
|
|
125
|
+
@SerializedName("ssid")
|
|
126
|
+
val ssid: String,
|
|
127
|
+
@SerializedName("password")
|
|
128
|
+
val password: String,
|
|
129
|
+
@SerializedName("timeout")
|
|
130
|
+
val timeout: Long,
|
|
131
|
+
@SerializedName("productKeys")
|
|
132
|
+
val productKeys: List<String>,
|
|
133
|
+
): DeviceParams {
|
|
134
|
+
override val id: String = "airlink" // AirLink 配网不需要设备ID
|
|
135
|
+
}
|
|
136
|
+
|
|
120
137
|
data class GizStopProvideWiFiCredentialsParams(
|
|
121
138
|
@SerializedName("id")
|
|
122
139
|
override val id: String,
|
|
@@ -147,6 +164,8 @@ data class StopUpgradeParams(
|
|
|
147
164
|
|
|
148
165
|
|
|
149
166
|
class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
167
|
+
private val moduleScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
|
168
|
+
|
|
150
169
|
enum class EventName(val value: String) {
|
|
151
170
|
GizOTAProgressEvent("GizOTAProgressEvent"),
|
|
152
171
|
GizProvideWiFiCredentialsEvent("GizProvideWiFiCredentialsEvent"),
|
|
@@ -163,11 +182,17 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
163
182
|
}
|
|
164
183
|
|
|
165
184
|
override fun getName() = "RNGizDeviceManagerModule"
|
|
185
|
+
|
|
186
|
+
override fun onCatalystInstanceDestroy() {
|
|
187
|
+
super.onCatalystInstanceDestroy()
|
|
188
|
+
moduleScope.cancel() // 取消所有协程
|
|
189
|
+
}
|
|
190
|
+
|
|
166
191
|
@ReactMethod
|
|
167
192
|
fun sendDp(options: ReadableMap, result: Callback) {
|
|
168
193
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizSendDPParams::class.java)
|
|
169
194
|
if (config !=null && device !=null) {
|
|
170
|
-
|
|
195
|
+
moduleScope.launch {
|
|
171
196
|
try {
|
|
172
197
|
val gson = Gson()
|
|
173
198
|
val jsonObject = gson.fromJson(config.data, JsonObject::class.java)
|
|
@@ -188,7 +213,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
188
213
|
fun getDp(options: ReadableMap, result: Callback) {
|
|
189
214
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDPParams::class.java)
|
|
190
215
|
if (config !=null && device !=null) {
|
|
191
|
-
|
|
216
|
+
moduleScope.launch {
|
|
192
217
|
var res = when(config.type) {
|
|
193
218
|
CapacityTypes.BLE -> device.bleCapability.getDp(config.attrs)
|
|
194
219
|
CapacityTypes.LAN -> device.lanCapability.getDp(config.attrs)
|
|
@@ -210,7 +235,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
210
235
|
fun getDeviceInfo(options: ReadableMap, result: Callback) {
|
|
211
236
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDeviceInfoParams::class.java)
|
|
212
237
|
if (config !=null && device !=null) {
|
|
213
|
-
|
|
238
|
+
moduleScope.launch {
|
|
214
239
|
val res = when(config.type) {
|
|
215
240
|
CapacityTypes.BLE -> device.bleCapability.getDeviceInfo()
|
|
216
241
|
CapacityTypes.LAN -> device.lanCapability.getDeviceInfo()
|
|
@@ -225,7 +250,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
225
250
|
fun updateDeviceInfo(options: ReadableMap, result: Callback) {
|
|
226
251
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, UpdateDeviceInfoParams::class.java)
|
|
227
252
|
if (config !=null && device !=null) {
|
|
228
|
-
|
|
253
|
+
moduleScope.launch {
|
|
229
254
|
val res = device.updateDeviceInfo(config.alias, config.remark)
|
|
230
255
|
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
231
256
|
// if (res.isSuccess) {
|
|
@@ -239,7 +264,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
239
264
|
fun bind(options: ReadableMap, result: Callback) {
|
|
240
265
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizBindParams::class.java)
|
|
241
266
|
if (config !=null && device !=null) {
|
|
242
|
-
|
|
267
|
+
moduleScope.launch {
|
|
243
268
|
val res = device.bind(config.alias, config.remark)
|
|
244
269
|
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
245
270
|
// if (res.isSuccess) {
|
|
@@ -253,7 +278,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
253
278
|
fun unBind(options: ReadableMap, result: Callback) {
|
|
254
279
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizUnBindParams::class.java)
|
|
255
280
|
if (config !=null && device !=null) {
|
|
256
|
-
|
|
281
|
+
moduleScope.launch {
|
|
257
282
|
val res = device.unBind()
|
|
258
283
|
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
259
284
|
if (res.isSuccess) {
|
|
@@ -266,7 +291,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
266
291
|
fun stopProvideWiFiCredentials(options: ReadableMap, result: Callback) {
|
|
267
292
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizStopProvideWiFiCredentialsParams::class.java)
|
|
268
293
|
if (config !=null && device !=null) {
|
|
269
|
-
|
|
294
|
+
moduleScope.launch {
|
|
270
295
|
val res = when(config.type) {
|
|
271
296
|
CapacityTypes.BLE -> device.bleCapability.stopProvideWiFiCredentials()
|
|
272
297
|
CapacityTypes.LAN -> device.lanCapability.stopProvideWiFiCredentials()
|
|
@@ -277,6 +302,14 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
277
302
|
}
|
|
278
303
|
}
|
|
279
304
|
|
|
305
|
+
@ReactMethod
|
|
306
|
+
fun stopProvideWiFiCredentialsWithAirLink(result: Callback) {
|
|
307
|
+
moduleScope.launch {
|
|
308
|
+
val res = GizESPTouchSmartConfig.stopProvideWiFiCredentialsWithAirLink()
|
|
309
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
280
313
|
fun wiFiCredentialsEventHandler(event: GizWiFiActivatorEvent, device: GizDevice) {
|
|
281
314
|
val jsonObject = JSONObject()
|
|
282
315
|
jsonObject.put("data", event.toString())
|
|
@@ -286,11 +319,21 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
286
319
|
GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
|
|
287
320
|
)
|
|
288
321
|
}
|
|
322
|
+
|
|
323
|
+
fun wiFiCredentialsWithAirLinkEventHandler(event: GizWiFiActivatorEvent) {
|
|
324
|
+
val jsonObject = JSONObject()
|
|
325
|
+
jsonObject.put("data", event.toString())
|
|
326
|
+
sendEvent(
|
|
327
|
+
EventName.GizProvideWiFiCredentialsEvent.name,
|
|
328
|
+
GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
|
|
289
332
|
@ReactMethod
|
|
290
333
|
fun provideWiFiCredentials(options: ReadableMap, result: Callback) {
|
|
291
334
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizProvideWiFiCredentialsParams::class.java)
|
|
292
335
|
if (config !=null && device !=null) {
|
|
293
|
-
|
|
336
|
+
moduleScope.launch {
|
|
294
337
|
val res = when(config.type) {
|
|
295
338
|
CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
|
|
296
339
|
config.ssid,
|
|
@@ -322,11 +365,31 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
322
365
|
}
|
|
323
366
|
}
|
|
324
367
|
|
|
368
|
+
@ReactMethod
|
|
369
|
+
fun provideWiFiCredentialsWithAirLink(options: ReadableMap, result: Callback) {
|
|
370
|
+
val config = RNGizParamsChecker.check(options, result, GizProvideWiFiCredentialsWithAirLinkParams::class.java)
|
|
371
|
+
config?.let {
|
|
372
|
+
moduleScope.launch {
|
|
373
|
+
val res = GizESPTouchSmartConfig.provideWiFiCredentialsWithAirLink(
|
|
374
|
+
reactApplicationContext,
|
|
375
|
+
config.ssid,
|
|
376
|
+
config.password,
|
|
377
|
+
config.timeout,
|
|
378
|
+
config.productKeys,
|
|
379
|
+
processHandler = {
|
|
380
|
+
wiFiCredentialsWithAirLinkEventHandler(it)
|
|
381
|
+
}
|
|
382
|
+
)
|
|
383
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
325
388
|
@ReactMethod
|
|
326
389
|
fun register(options: ReadableMap, result: Callback) {
|
|
327
390
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizRegisterDeviceParams::class.java)
|
|
328
391
|
if (config !=null && device !=null) {
|
|
329
|
-
|
|
392
|
+
moduleScope.launch {
|
|
330
393
|
val res = device.register()
|
|
331
394
|
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
332
395
|
}
|
|
@@ -337,7 +400,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
337
400
|
fun connect(options: ReadableMap, result: Callback) {
|
|
338
401
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizConnectParams::class.java)
|
|
339
402
|
if (config !=null && device !=null) {
|
|
340
|
-
|
|
403
|
+
moduleScope.launch {
|
|
341
404
|
val res = when(config.type) {
|
|
342
405
|
CapacityTypes.BLE -> device.bleCapability.connect()
|
|
343
406
|
CapacityTypes.LAN -> device.lanCapability.connect()
|
|
@@ -351,7 +414,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
351
414
|
fun disConnect(options: ReadableMap, result: Callback) {
|
|
352
415
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizDisConnectParams::class.java)
|
|
353
416
|
if (config !=null && device !=null) {
|
|
354
|
-
|
|
417
|
+
moduleScope.launch {
|
|
355
418
|
val res = when(config.type) {
|
|
356
419
|
CapacityTypes.BLE -> device.bleCapability.disConnect()
|
|
357
420
|
CapacityTypes.LAN -> device.lanCapability.disConnect()
|
|
@@ -366,7 +429,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
366
429
|
fun checkUpdate(options: ReadableMap, result: Callback) {
|
|
367
430
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
|
|
368
431
|
if (config !=null && device !=null) {
|
|
369
|
-
|
|
432
|
+
moduleScope.launch {
|
|
370
433
|
val res = when(config.type) {
|
|
371
434
|
CapacityTypes.BLE -> device.bleCapability.checkUpdate(config.firmwareType)
|
|
372
435
|
CapacityTypes.LAN -> device.lanCapability.checkUpdate(config.firmwareType)
|
|
@@ -393,7 +456,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
393
456
|
fun startUpgrade(options: ReadableMap, result: Callback) {
|
|
394
457
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
|
|
395
458
|
if (config !=null && device !=null) {
|
|
396
|
-
|
|
459
|
+
moduleScope.launch {
|
|
397
460
|
val res = when(config.type) {
|
|
398
461
|
CapacityTypes.BLE -> {
|
|
399
462
|
device.bleCapability.startUpgrade(config.firmwareType, processHandler = {
|
|
@@ -415,7 +478,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
415
478
|
fun cancelUpgrade(options: ReadableMap, result: Callback) {
|
|
416
479
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopUpgradeParams::class.java)
|
|
417
480
|
if (config !=null && device !=null) {
|
|
418
|
-
|
|
481
|
+
moduleScope.launch {
|
|
419
482
|
val res = when(config.type) {
|
|
420
483
|
CapacityTypes.BLE -> device.bleCapability.cancelUpgrade()
|
|
421
484
|
CapacityTypes.LAN -> device.lanCapability.cancelUpgrade()
|
|
@@ -430,7 +493,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
430
493
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StartMusicalRhythmParams::class.java)
|
|
431
494
|
print("startMusicalRhythm ${config}")
|
|
432
495
|
if (config !=null && device !=null) {
|
|
433
|
-
|
|
496
|
+
moduleScope.launch {
|
|
434
497
|
val res = device.startMusicalRhythm(config.sensitivity, config.mode) { data ->
|
|
435
498
|
if (config.needMonitor) {
|
|
436
499
|
val jsonObject = JSONObject()
|
|
@@ -465,7 +528,7 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
465
528
|
fun stopMusicalRhythm(options: ReadableMap, result: Callback) {
|
|
466
529
|
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopMusicalRhythmParams::class.java)
|
|
467
530
|
if (config !=null && device !=null) {
|
|
468
|
-
|
|
531
|
+
moduleScope.launch {
|
|
469
532
|
val res = device.stopMusicalRhythm();
|
|
470
533
|
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
|
|
471
534
|
}
|
|
@@ -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)
|
|
@@ -81,12 +81,10 @@ struct ProvideWiFiCredentialsParams: Decodable {
|
|
|
81
81
|
var timeout: Int
|
|
82
82
|
}
|
|
83
83
|
struct ProvideWiFiCredentialsWithAirLinkParams: Decodable {
|
|
84
|
-
var type: GizwitsiOSSDK.GizCapability
|
|
85
|
-
var id: String
|
|
86
84
|
var ssid: String
|
|
87
85
|
var password: String
|
|
88
86
|
var timeout: Int
|
|
89
|
-
var
|
|
87
|
+
var productKeys: [String]
|
|
90
88
|
}
|
|
91
89
|
struct StopProvideWiFiCredentialsParams: Decodable {
|
|
92
90
|
var type: GizwitsiOSSDK.GizCapability
|
|
@@ -467,11 +465,20 @@ class RNGizDeviceManagerModule: RCTEventEmitter {
|
|
|
467
465
|
}
|
|
468
466
|
Task {
|
|
469
467
|
var data: GizResult<GizBaseProfile?, GizActivatorException?>
|
|
470
|
-
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)
|
|
471
469
|
GizRNCallbackManager.callbackWithResult(callback: result, result:data)
|
|
472
470
|
}
|
|
473
471
|
}
|
|
474
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
|
+
}
|
|
475
482
|
|
|
476
483
|
@objc
|
|
477
484
|
public func stopProvideWiFiCredentials(_ options: NSDictionary, result: @escaping RCTResponseSenderBlock) {
|
package/package.json
CHANGED