react-native-gizwits-sdk-v5 1.2.4 → 1.2.5
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 +3 -0
- package/android/libs/sdk-bluetooth-debug.aar +0 -0
- package/android/libs/sdk-bluetooth-release.aar +0 -0
- package/android/libs/sdk-debug.aar +0 -0
- package/android/libs/sdk-lan-debug.aar +0 -0
- package/android/libs/sdk-lan-release.aar +0 -0
- package/android/libs/sdk-mqtt-debug.aar +0 -0
- package/android/libs/sdk-mqtt-release.aar +0 -0
- package/android/libs/sdk-release.aar +0 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt +72 -3
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizParamsChecker.kt +23 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizSDKManagerModule.kt +3 -1
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizUserManagerModule.kt +16 -1
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -7,6 +7,7 @@ buildscript {
|
|
|
7
7
|
kotlin_coroutine_version = '1.6.4'
|
|
8
8
|
retrofit_version = '2.9.0'
|
|
9
9
|
room_version = '2.5.0'
|
|
10
|
+
mqtt_version = '1.2.5'
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
repositories {
|
|
@@ -58,6 +59,8 @@ dependencies {
|
|
|
58
59
|
implementation 'io.sentry:sentry-android-timber:6.29.0'
|
|
59
60
|
implementation 'com.jakewharton.timber:timber:5.0.1'
|
|
60
61
|
implementation 'io.sentry:sentry-android:6.29.0'
|
|
62
|
+
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:$mqtt_version"
|
|
63
|
+
|
|
61
64
|
|
|
62
65
|
implementation files('libs/sdk-debug.aar', 'libs/sdk-bluetooth-debug.aar', 'libs/sdk-lan-debug.aar', 'libs/sdk-mqtt-debug.aar')
|
|
63
66
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt
CHANGED
|
@@ -5,6 +5,41 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
5
5
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
6
|
import com.facebook.react.bridge.ReactMethod
|
|
7
7
|
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.gizwits.smart.sdk.GizDevice
|
|
9
|
+
import com.gizwits.smart.sdk.GizSDKManager
|
|
10
|
+
import com.gizwits.smart.sdk.bluetooth.bleCapacity
|
|
11
|
+
import com.gizwits.smart.sdk.common.GizConfiguration
|
|
12
|
+
import com.gizwits.smart.sdk.core.capacity.CapacityTypes
|
|
13
|
+
import com.gizwits.smart.sdk.exception.GizException
|
|
14
|
+
import com.gizwits.smart.sdk.lan.lanCapacity
|
|
15
|
+
import com.gizwits.smart.sdk.mqtt.mqttCapacity
|
|
16
|
+
import com.gizwits.smart.sdk.mqtt.queryBoundDevices
|
|
17
|
+
import com.google.gson.annotations.SerializedName
|
|
18
|
+
import kotlinx.coroutines.CoroutineScope
|
|
19
|
+
import kotlinx.coroutines.Dispatchers
|
|
20
|
+
import kotlinx.coroutines.launch
|
|
21
|
+
|
|
22
|
+
data class GizBindParams(
|
|
23
|
+
@SerializedName("id")
|
|
24
|
+
override val id: Int,
|
|
25
|
+
@SerializedName("alias")
|
|
26
|
+
val alias: String,
|
|
27
|
+
@SerializedName("remark")
|
|
28
|
+
val remark: String,
|
|
29
|
+
) : DeviceParams
|
|
30
|
+
|
|
31
|
+
data class GizUnBindParams(
|
|
32
|
+
@SerializedName("id")
|
|
33
|
+
override val id: Int,
|
|
34
|
+
): DeviceParams
|
|
35
|
+
|
|
36
|
+
data class GizConnectParams(
|
|
37
|
+
@SerializedName("id")
|
|
38
|
+
override val id: Int,
|
|
39
|
+
@SerializedName("type")
|
|
40
|
+
val type: CapacityTypes
|
|
41
|
+
): DeviceParams
|
|
42
|
+
|
|
8
43
|
|
|
9
44
|
class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
10
45
|
enum class EventName(val value: String) {
|
|
@@ -20,10 +55,32 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
20
55
|
fun getDeviceInfo(options: ReadableMap, result: Callback) {}
|
|
21
56
|
|
|
22
57
|
@ReactMethod
|
|
23
|
-
fun bind(options: ReadableMap, result: Callback) {
|
|
58
|
+
fun bind(options: ReadableMap, result: Callback) {
|
|
59
|
+
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizBindParams::class.java)
|
|
60
|
+
if (config !=null && device !=null) {
|
|
61
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
62
|
+
val res = device.bindDevice(config.alias, config.remark)
|
|
63
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
64
|
+
if (res.isSuccess) {
|
|
65
|
+
GizSDKManager.queryBoundDevices()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
24
70
|
|
|
25
71
|
@ReactMethod
|
|
26
|
-
fun unBind(options: ReadableMap, result: Callback) {
|
|
72
|
+
fun unBind(options: ReadableMap, result: Callback) {
|
|
73
|
+
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizUnBindParams::class.java)
|
|
74
|
+
if (config !=null && device !=null) {
|
|
75
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
76
|
+
val res = device.unbindDevice()
|
|
77
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
78
|
+
if (res.isSuccess) {
|
|
79
|
+
GizSDKManager.queryBoundDevices()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
27
84
|
@ReactMethod
|
|
28
85
|
fun checkUpdate(options: ReadableMap, result: Callback) {}
|
|
29
86
|
@ReactMethod
|
|
@@ -32,7 +89,19 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
32
89
|
fun register(options: ReadableMap, result: Callback) {}
|
|
33
90
|
|
|
34
91
|
@ReactMethod
|
|
35
|
-
fun connect(options: ReadableMap, result: Callback) {
|
|
92
|
+
fun connect(options: ReadableMap, result: Callback) {
|
|
93
|
+
val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizConnectParams::class.java)
|
|
94
|
+
if (config !=null && device !=null) {
|
|
95
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
96
|
+
val res = when(config.type) {
|
|
97
|
+
CapacityTypes.BLE -> device.bleCapacity.connect()
|
|
98
|
+
CapacityTypes.LAN -> device.lanCapacity.connect()
|
|
99
|
+
CapacityTypes.MQTT -> device.mqttCapacity.connect()
|
|
100
|
+
}
|
|
101
|
+
// GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
36
105
|
@ReactMethod
|
|
37
106
|
fun disConnect(options: ReadableMap, result: Callback) {}
|
|
38
107
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
package com.gizwits.reactnativegizwitssdkv5
|
|
2
2
|
import com.facebook.react.bridge.Callback
|
|
3
3
|
import com.facebook.react.bridge.ReadableMap
|
|
4
|
+
import com.gizwits.smart.sdk.GizDevice
|
|
5
|
+
import com.gizwits.smart.sdk.GizSDKManager
|
|
4
6
|
import com.gizwits.smart.sdk.exception.GizException
|
|
5
7
|
import com.gizwits.smart.sdk.exception.GizParseException
|
|
6
8
|
import com.google.gson.Gson
|
|
7
9
|
import com.google.gson.JsonSyntaxException
|
|
10
|
+
import com.google.gson.annotations.SerializedName
|
|
8
11
|
|
|
12
|
+
interface DeviceParams{
|
|
13
|
+
val id: Int
|
|
14
|
+
}
|
|
9
15
|
class RNGizParamsChecker {
|
|
10
16
|
companion object {
|
|
11
17
|
fun <T : Any> check(options: ReadableMap, result: Callback, paramsType: Class<T>): T? {
|
|
@@ -22,5 +28,22 @@ class RNGizParamsChecker {
|
|
|
22
28
|
return null
|
|
23
29
|
}
|
|
24
30
|
}
|
|
31
|
+
|
|
32
|
+
fun <T : DeviceParams> checkDeviceAndParams(options: ReadableMap, result: Callback, paramsType: Class<T>): Pair<T?, GizDevice?> {
|
|
33
|
+
val config = check(options, result, paramsType)
|
|
34
|
+
var dev: GizDevice? = null
|
|
35
|
+
config?.let {
|
|
36
|
+
dev = GizSDKManager.getRegisteredDevice(config.id)
|
|
37
|
+
if (dev == null) {
|
|
38
|
+
GizRNCallbackManager.callbackWithResult(
|
|
39
|
+
callback = result,
|
|
40
|
+
result = Result.failure<Number>(GizException.GIZ_OPENAPI_DEVICE_NOT_FOUND)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Pair(config, dev)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
25
48
|
}
|
|
26
49
|
}
|
|
@@ -38,7 +38,9 @@ import org.json.JSONObject
|
|
|
38
38
|
|
|
39
39
|
class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
companion object {
|
|
42
|
+
internal var devices = listOf<GizDevice>()
|
|
43
|
+
}
|
|
42
44
|
enum class EventName(val value: String) {
|
|
43
45
|
DeviceDataListener("DeviceDataListener"),
|
|
44
46
|
DeviceListListener("DeviceListListener"),
|
|
@@ -9,6 +9,9 @@ import com.gizwits.smart.sdk.GizUserManagerImpl
|
|
|
9
9
|
import com.gizwits.smart.sdk.common.GizConfiguration
|
|
10
10
|
import com.gizwits.smart.sdk.core.data.model.UserToken
|
|
11
11
|
import com.google.gson.annotations.SerializedName
|
|
12
|
+
import kotlinx.coroutines.CoroutineScope
|
|
13
|
+
import kotlinx.coroutines.Dispatchers
|
|
14
|
+
import kotlinx.coroutines.launch
|
|
12
15
|
import java.util.Date
|
|
13
16
|
|
|
14
17
|
data class UpdateAuthorizeDataParams(
|
|
@@ -33,10 +36,22 @@ class RNGizUserManagerModule(reactContext: ReactApplicationContext) : ReactConte
|
|
|
33
36
|
config?.let {
|
|
34
37
|
// Date 暂时没有用到
|
|
35
38
|
GizUserManagerImpl.updateAuthorizeData(UserToken(config.token, config.uid, Date()))
|
|
39
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(0))
|
|
36
40
|
}
|
|
41
|
+
|
|
37
42
|
}
|
|
38
43
|
@ReactMethod
|
|
39
44
|
fun loginByAnonymous(options: ReadableMap, result: Callback) {
|
|
40
|
-
|
|
45
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
46
|
+
val res = GizUserManagerImpl.loginByAnonymous()
|
|
47
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
@ReactMethod
|
|
51
|
+
fun logout(options: ReadableMap, result: Callback) {
|
|
52
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
53
|
+
val res = GizUserManagerImpl.logout()
|
|
54
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
55
|
+
}
|
|
41
56
|
}
|
|
42
57
|
}
|