react-native-gizwits-sdk-v5 1.3.28 → 1.3.29
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
|
@@ -19,7 +19,9 @@ import com.gizwits.smart.sdk.mqtt.mqttCapacity
|
|
|
19
19
|
import com.gizwits.smart.sdk.mqtt.queryBoundDevices
|
|
20
20
|
import com.gizwits.smart.sdk.ota.GizOTAFirmwareType
|
|
21
21
|
import com.gizwits.smart.sdk.ota.OTAProgressData
|
|
22
|
+
import com.google.gson.Gson
|
|
22
23
|
import com.google.gson.JsonArray
|
|
24
|
+
import com.google.gson.JsonObject
|
|
23
25
|
import com.google.gson.annotations.SerializedName
|
|
24
26
|
import kotlinx.coroutines.CoroutineScope
|
|
25
27
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -123,15 +125,12 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
123
125
|
GizProvideWiFiCredentialsEvent("GizProvideWiFiCredentialsEvent"),
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
fun jsonObjectToPairs(jsonObject:
|
|
128
|
+
fun jsonObjectToPairs(jsonObject: JsonObject): Array<Pair<String, Any>> {
|
|
127
129
|
val pairs = mutableListOf<Pair<String, Any>>()
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
val pair = key to value
|
|
132
|
-
pairs.add(pair)
|
|
130
|
+
for ((key, value) in jsonObject.entrySet()) {
|
|
131
|
+
val pair = key to value
|
|
132
|
+
pairs.add(pair)
|
|
133
133
|
}
|
|
134
|
-
|
|
135
134
|
return pairs.toTypedArray()
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -142,7 +141,8 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
142
141
|
if (config !=null && device !=null) {
|
|
143
142
|
CoroutineScope(Dispatchers.Main).launch {
|
|
144
143
|
try {
|
|
145
|
-
val
|
|
144
|
+
val gson = Gson()
|
|
145
|
+
val jsonObject = gson.fromJson(config.data, JsonObject::class.java)
|
|
146
146
|
val attrs = jsonObjectToPairs(jsonObject)
|
|
147
147
|
val res = when(config.type) {
|
|
148
148
|
CapacityTypes.BLE -> device.bleCapacity.sendDp(*attrs)
|
|
@@ -385,4 +385,4 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
385
385
|
.emit(name, data)
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
}
|
|
388
|
+
}
|
|
@@ -3,6 +3,7 @@ package com.gizwits.reactnativegizwitssdkv5
|
|
|
3
3
|
import com.facebook.react.bridge.Arguments
|
|
4
4
|
import com.facebook.react.bridge.Callback
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
|
6
7
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
8
|
import com.facebook.react.bridge.ReactMethod
|
|
8
9
|
import com.facebook.react.bridge.ReadableMap
|
|
@@ -11,7 +12,6 @@ import com.facebook.react.bridge.WritableMap
|
|
|
11
12
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
12
13
|
import com.gizwits.smart.sdk.GizDevice
|
|
13
14
|
import com.gizwits.smart.sdk.GizSDKManager
|
|
14
|
-
import com.gizwits.smart.sdk.GizUserManager
|
|
15
15
|
import com.gizwits.smart.sdk.bluetooth.bleCapacity
|
|
16
16
|
import com.gizwits.smart.sdk.bluetooth.startBleScan
|
|
17
17
|
import com.gizwits.smart.sdk.bluetooth.stopBleScan
|
|
@@ -28,20 +28,17 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
28
28
|
import kotlinx.coroutines.Dispatchers
|
|
29
29
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
30
30
|
import kotlinx.coroutines.flow.Flow
|
|
31
|
-
import kotlinx.coroutines.flow.collect
|
|
32
31
|
import kotlinx.coroutines.flow.collectLatest
|
|
33
32
|
import kotlinx.coroutines.flow.combine
|
|
34
33
|
import kotlinx.coroutines.flow.debounce
|
|
35
|
-
import kotlinx.coroutines.flow.drop
|
|
36
34
|
import kotlinx.coroutines.flow.first
|
|
37
|
-
import kotlinx.coroutines.flow.last
|
|
38
35
|
import kotlinx.coroutines.flow.mapLatest
|
|
39
36
|
import kotlinx.coroutines.flow.take
|
|
40
|
-
import kotlinx.coroutines.flow.toList
|
|
41
37
|
import kotlinx.coroutines.launch
|
|
42
38
|
import org.json.JSONArray
|
|
43
39
|
import org.json.JSONObject
|
|
44
40
|
|
|
41
|
+
|
|
45
42
|
data class GizGetProductConfig(
|
|
46
43
|
@SerializedName("productKey")
|
|
47
44
|
val productKey: String,
|
|
@@ -50,6 +47,10 @@ data class GizGetProductConfig(
|
|
|
50
47
|
|
|
51
48
|
class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
52
49
|
|
|
50
|
+
private var mReactContext: ReactContext? = null
|
|
51
|
+
init {
|
|
52
|
+
mReactContext = reactContext
|
|
53
|
+
}
|
|
53
54
|
companion object {
|
|
54
55
|
internal var devices = listOf<GizDevice>()
|
|
55
56
|
}
|
|
@@ -197,14 +198,14 @@ class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContex
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
fun sendEvent(name:String, data: WritableArray?) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
mReactContext!!
|
|
202
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
203
|
+
.emit(name, data)
|
|
203
204
|
}
|
|
204
205
|
fun sendEvent(name:String, data: WritableMap?) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
mReactContext!!
|
|
207
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
208
|
+
.emit(name, data)
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
@ReactMethod
|