react-native-gizwits-sdk-v5 1.4.3 → 1.4.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 +4 -4
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt +3 -3
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizSDKManagerModule.kt +279 -264
- package/package.json +1 -1
- package/react-native-gizwits-sdk-v5.podspec +1 -1
package/android/build.gradle
CHANGED
|
@@ -63,10 +63,10 @@ dependencies {
|
|
|
63
63
|
|
|
64
64
|
implementation "androidx.startup:startup-runtime:$startup_version"
|
|
65
65
|
|
|
66
|
-
implementation("io.github.gizwits:sdk:1.0.
|
|
67
|
-
implementation("io.github.gizwits:sdk-bluetooth:1.0.
|
|
68
|
-
implementation("io.github.gizwits:sdk-lan:1.0.
|
|
69
|
-
implementation("io.github.gizwits:sdk-mqtt:1.0.
|
|
66
|
+
implementation("io.github.gizwits:sdk:1.0.73")
|
|
67
|
+
implementation("io.github.gizwits:sdk-bluetooth:1.0.73")
|
|
68
|
+
implementation("io.github.gizwits:sdk-lan:1.0.73")
|
|
69
|
+
implementation("io.github.gizwits:sdk-mqtt:1.0.73")
|
|
70
70
|
// implementation files('libs/sdk-release.aar', 'libs/sdk-bluetooth-release.aar', 'libs/sdk-lan-release.aar', 'libs/sdk-mqtt-release.aar')
|
|
71
71
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
|
|
72
72
|
// retrofit
|
package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt
CHANGED
|
@@ -311,9 +311,9 @@ class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
311
311
|
if (config !=null && device !=null) {
|
|
312
312
|
CoroutineScope(Dispatchers.IO).launch {
|
|
313
313
|
val res = when(config.type) {
|
|
314
|
-
CapacityTypes.BLE -> device.bleCapability.
|
|
315
|
-
CapacityTypes.LAN -> device.lanCapability.
|
|
316
|
-
CapacityTypes.MQTT -> device.mqttCapability.
|
|
314
|
+
CapacityTypes.BLE -> device.bleCapability.disConnect()
|
|
315
|
+
CapacityTypes.LAN -> device.lanCapability.disConnect()
|
|
316
|
+
CapacityTypes.MQTT -> device.mqttCapability.disConnect()
|
|
317
317
|
}
|
|
318
318
|
GizRNCallbackManager.callbackWithResult(callback = result, result = res)
|
|
319
319
|
}
|
|
@@ -28,12 +28,17 @@ import com.google.gson.annotations.SerializedName
|
|
|
28
28
|
import kotlinx.coroutines.CoroutineScope
|
|
29
29
|
import kotlinx.coroutines.Dispatchers
|
|
30
30
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
31
|
+
import kotlinx.coroutines.async
|
|
32
|
+
import kotlinx.coroutines.coroutineScope
|
|
31
33
|
import kotlinx.coroutines.flow.Flow
|
|
32
34
|
import kotlinx.coroutines.flow.collectLatest
|
|
33
35
|
import kotlinx.coroutines.flow.combine
|
|
34
36
|
import kotlinx.coroutines.flow.debounce
|
|
37
|
+
import kotlinx.coroutines.flow.emptyFlow
|
|
35
38
|
import kotlinx.coroutines.flow.first
|
|
39
|
+
import kotlinx.coroutines.flow.flatMapConcat
|
|
36
40
|
import kotlinx.coroutines.flow.last
|
|
41
|
+
import kotlinx.coroutines.flow.launchIn
|
|
37
42
|
import kotlinx.coroutines.flow.mapLatest
|
|
38
43
|
import kotlinx.coroutines.flow.take
|
|
39
44
|
import kotlinx.coroutines.launch
|
|
@@ -42,306 +47,316 @@ import org.json.JSONObject
|
|
|
42
47
|
|
|
43
48
|
|
|
44
49
|
data class GizGetProductConfig(
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
@SerializedName("productKey")
|
|
51
|
+
val productKey: String,
|
|
47
52
|
)
|
|
48
53
|
|
|
49
54
|
data class GizFeedback(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
@SerializedName("uploadLog")
|
|
56
|
+
val uploadLog: Boolean,
|
|
57
|
+
@SerializedName("content")
|
|
58
|
+
val content: String,
|
|
59
|
+
@SerializedName("contact")
|
|
60
|
+
val contact: String,
|
|
56
61
|
)
|
|
57
62
|
|
|
58
63
|
class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
private var mReactContext: ReactContext? = null
|
|
66
|
+
init {
|
|
67
|
+
mReactContext = reactContext
|
|
68
|
+
}
|
|
69
|
+
companion object {
|
|
70
|
+
internal var devices = listOf<GizDevice>()
|
|
71
|
+
}
|
|
72
|
+
enum class EventName(val value: String) {
|
|
73
|
+
DeviceDataListener("DeviceDataListener"),
|
|
74
|
+
DeviceListListener("DeviceListListener"),
|
|
75
|
+
DeviceStateListener("DeviceStateListener"),
|
|
76
|
+
DeviceBindStateListener("DeviceBindStateListener"),
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** @hide */
|
|
80
|
+
@OptIn(ExperimentalCoroutinesApi::class)
|
|
81
|
+
fun <T1, T2, T3, R> combineLatest(
|
|
82
|
+
flow1: Flow<T1>,
|
|
83
|
+
flow2: Flow<T2>,
|
|
84
|
+
flow3: Flow<T3>,
|
|
85
|
+
transform: suspend (a: T1, b: T2, c: T3) -> R
|
|
86
|
+
): Flow<R> {
|
|
87
|
+
return combine(flow1, flow2, flow3) { value1, value2, value3 ->
|
|
88
|
+
Triple(value1, value2, value3)
|
|
89
|
+
}.mapLatest {
|
|
90
|
+
transform(it.first, it.second, it.third)
|
|
66
91
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
}
|
|
93
|
+
/** @hide */
|
|
94
|
+
@OptIn(ExperimentalCoroutinesApi::class)
|
|
95
|
+
fun <T1, T2, R> combineLatest(
|
|
96
|
+
flow1: Flow<T1>,
|
|
97
|
+
flow2: Flow<T2>,
|
|
98
|
+
transform: suspend (a: T1, b: T2) -> R
|
|
99
|
+
): Flow<R> {
|
|
100
|
+
return combine(flow1, flow2) { value1, value2 ->
|
|
101
|
+
Pair(value1, value2)
|
|
102
|
+
}.mapLatest {
|
|
103
|
+
transform(it.first, it.second)
|
|
72
104
|
}
|
|
105
|
+
}
|
|
73
106
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}.mapLatest {
|
|
85
|
-
transform(it.first, it.second, it.third)
|
|
86
|
-
}
|
|
107
|
+
override fun getName() = "RNGizSDKManagerModule"
|
|
108
|
+
private val deviceListState: Flow<List<GizDevice>> =
|
|
109
|
+
combineLatest(
|
|
110
|
+
GizSDKManager.subscribeBoundDeviceList(),
|
|
111
|
+
GizSDKManager.subscribeBluetoothDeviceList(),
|
|
112
|
+
GizSDKManager.subscribeLanDeviceList()
|
|
113
|
+
) { boundDeviceList, bluetoothDeviceList, lanDeviceList ->
|
|
114
|
+
listOf(boundDeviceList, bluetoothDeviceList, lanDeviceList)
|
|
115
|
+
.flatten()
|
|
116
|
+
.distinct()
|
|
87
117
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}.mapLatest {
|
|
98
|
-
transform(it.first, it.second)
|
|
118
|
+
|
|
119
|
+
override fun initialize() {
|
|
120
|
+
super.initialize()
|
|
121
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
122
|
+
GizSDKManager.subscribeBindEvent().collect {
|
|
123
|
+
val data = JSONObject()
|
|
124
|
+
data.put("did", it.first)
|
|
125
|
+
data.put("isBind", it.second)
|
|
126
|
+
sendEvent(EventName.DeviceBindStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
99
127
|
}
|
|
100
128
|
}
|
|
101
129
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
130
|
+
// 监听设备对象
|
|
131
|
+
deviceListState
|
|
132
|
+
.debounce(500)
|
|
133
|
+
.flatMapConcat { deviceList ->
|
|
134
|
+
deviceList.map { dev ->
|
|
135
|
+
coroutineScope {
|
|
136
|
+
async {
|
|
137
|
+
dev.bleCapability.subscribeModuleProfile().debounce(500).collect {
|
|
138
|
+
if (it != null) {
|
|
139
|
+
emitDeviceListChange()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async {
|
|
144
|
+
combine(
|
|
145
|
+
dev.bleCapability.subscribeStatus(),
|
|
146
|
+
dev.bleCapability.subscribeIsLogin(),
|
|
147
|
+
) { status, isLogin ->
|
|
148
|
+
Pair(status, isLogin)
|
|
149
|
+
}.collect {
|
|
118
150
|
val data = JSONObject()
|
|
119
|
-
data.put("
|
|
120
|
-
data.put("
|
|
121
|
-
|
|
151
|
+
data.put("state", it.first.toInt())
|
|
152
|
+
data.put("isLogin", it.second)
|
|
153
|
+
data.put("type", "BLE")
|
|
154
|
+
data.put("device", dev.toJsonObject())
|
|
155
|
+
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async {
|
|
159
|
+
dev.bleCapability.subscribeDp().collect{
|
|
160
|
+
val data = JSONObject()
|
|
161
|
+
data.put("data", JSONObject(it.toString()))
|
|
162
|
+
data.put("type", "BLE")
|
|
163
|
+
data.put("device", dev.toJsonObject())
|
|
164
|
+
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async {
|
|
168
|
+
dev.lanCapability.subscribeModuleProfile().debounce(500).collectLatest{
|
|
169
|
+
if (it != null) {
|
|
170
|
+
emitDeviceListChange()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
122
173
|
}
|
|
123
|
-
}
|
|
124
|
-
CoroutineScope(Dispatchers.IO).launch {
|
|
125
|
-
deviceListState.debounce(500).collectLatest { deviceList ->
|
|
126
|
-
val newDevices = deviceList - devices
|
|
127
|
-
devices = deviceList
|
|
128
|
-
newDevices.forEach{dev ->
|
|
129
|
-
val devJob = dev.getDeviceJob()
|
|
130
|
-
val scope = CoroutineScope(devJob)
|
|
131
|
-
// 新增的设备挂监听
|
|
132
|
-
// 被移除的设备携程会自动销毁
|
|
133
|
-
scope.launch {
|
|
134
|
-
combineLatest(
|
|
135
|
-
dev.bleCapability.subscribeStatus(),
|
|
136
|
-
dev.bleCapability.subscribeIsLogin(),
|
|
137
|
-
) { status, isLogin ->
|
|
138
|
-
Pair(status, isLogin)
|
|
139
|
-
}.collectLatest {
|
|
140
|
-
val data = JSONObject()
|
|
141
|
-
data.put("state", it.first.toInt())
|
|
142
|
-
data.put("isLogin", it.second)
|
|
143
|
-
data.put("type", "BLE")
|
|
144
|
-
data.put("device", dev.toJsonObject())
|
|
145
|
-
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
scope.launch {
|
|
149
|
-
dev.bleCapability.subscribeModuleProfile().debounce(500).collectLatest{
|
|
150
|
-
if (it != null) {
|
|
151
|
-
emitDeviceListChange()
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
scope.launch {
|
|
156
|
-
dev.bleCapability.subscribeDp().collect{
|
|
157
|
-
val data = JSONObject()
|
|
158
|
-
data.put("data", JSONObject(it.toString()))
|
|
159
|
-
data.put("type", "BLE")
|
|
160
|
-
data.put("device", dev.toJsonObject())
|
|
161
|
-
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
174
|
|
|
175
|
+
async {
|
|
176
|
+
combineLatest(
|
|
177
|
+
dev.lanCapability.subscribeStatus(),
|
|
178
|
+
dev.lanCapability.subscribeIsLogin(),
|
|
179
|
+
) { status, isLogin ->
|
|
180
|
+
Pair(status, isLogin)
|
|
181
|
+
}.collectLatest {
|
|
182
|
+
val data = JSONObject()
|
|
183
|
+
data.put("state", it.first.toInt())
|
|
184
|
+
data.put("isLogin", it.second)
|
|
185
|
+
data.put("type", "LAN")
|
|
186
|
+
data.put("device", dev.toJsonObject())
|
|
187
|
+
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
188
|
+
}
|
|
189
|
+
}
|
|
165
190
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
data.put("isLogin", it.second)
|
|
176
|
-
data.put("type", "LAN")
|
|
177
|
-
data.put("device", dev.toJsonObject())
|
|
178
|
-
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
scope.launch {
|
|
182
|
-
dev.lanCapability.subscribeModuleProfile().debounce(500).collectLatest{
|
|
183
|
-
if (it != null) {
|
|
184
|
-
emitDeviceListChange()
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
scope.launch {
|
|
189
|
-
dev.lanCapability.subscribeDp().collect{
|
|
190
|
-
val data = JSONObject()
|
|
191
|
-
data.put("data", JSONObject(it.toString()))
|
|
192
|
-
data.put("type", "LAN")
|
|
193
|
-
data.put("device", dev.toJsonObject())
|
|
194
|
-
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
195
|
-
}
|
|
196
|
-
}
|
|
191
|
+
async {
|
|
192
|
+
dev.lanCapability.subscribeDp().collect{
|
|
193
|
+
val data = JSONObject()
|
|
194
|
+
data.put("data", JSONObject(it.toString()))
|
|
195
|
+
data.put("type", "LAN")
|
|
196
|
+
data.put("device", dev.toJsonObject())
|
|
197
|
+
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
198
|
+
}
|
|
199
|
+
}
|
|
197
200
|
|
|
201
|
+
async {
|
|
202
|
+
combineLatest(
|
|
203
|
+
dev.mqttCapability.subscribeStatus(),
|
|
204
|
+
dev.mqttCapability.subscribeIsLogin(),
|
|
205
|
+
) { status, isLogin ->
|
|
206
|
+
Pair(status, isLogin)
|
|
207
|
+
}.collectLatest {
|
|
208
|
+
val data = JSONObject()
|
|
209
|
+
data.put("state", it.first.toInt())
|
|
210
|
+
data.put("isLogin", it.second)
|
|
211
|
+
data.put("type", "MQTT")
|
|
212
|
+
data.put("device", dev.toJsonObject())
|
|
213
|
+
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
214
|
+
}
|
|
215
|
+
}
|
|
198
216
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
data.put("state", it.first.toInt())
|
|
208
|
-
data.put("isLogin", it.second)
|
|
209
|
-
data.put("type", "MQTT")
|
|
210
|
-
data.put("device", dev.toJsonObject())
|
|
211
|
-
sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
// scope.launch {
|
|
215
|
-
// dev.mqttCapability.subscribeModuleProfile().debounce(500).collectLatest{
|
|
216
|
-
// if (it != null) {
|
|
217
|
-
// emitDeviceListChange()
|
|
218
|
-
// }
|
|
219
|
-
// }
|
|
220
|
-
// }
|
|
221
|
-
scope.launch {
|
|
222
|
-
dev.mqttCapability.subscribeDp().collect{
|
|
223
|
-
val data = JSONObject()
|
|
224
|
-
data.put("data", JSONObject(it.toString()))
|
|
225
|
-
data.put("type", "MQTT")
|
|
226
|
-
data.put("device", dev.toJsonObject())
|
|
227
|
-
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
emitDeviceListChange()
|
|
217
|
+
async {
|
|
218
|
+
dev.mqttCapability.subscribeDp().collect{
|
|
219
|
+
val data = JSONObject()
|
|
220
|
+
data.put("data", JSONObject(it.toString()))
|
|
221
|
+
data.put("type", "MQTT")
|
|
222
|
+
data.put("device", dev.toJsonObject())
|
|
223
|
+
sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
|
|
224
|
+
}
|
|
232
225
|
}
|
|
226
|
+
}
|
|
233
227
|
}
|
|
234
|
-
}
|
|
235
228
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
deviceList.forEach{ item ->
|
|
245
|
-
deviceListJson.put(item.toJsonObject())
|
|
246
|
-
}
|
|
247
|
-
sendEvent(EventName.DeviceListListener.name, GizRNCallbackManager.jsonArray2WriteableArray(deviceListJson))
|
|
248
|
-
}
|
|
229
|
+
// 不会主动发生改表
|
|
230
|
+
// async {
|
|
231
|
+
// dev.mqttCapability.subscribeModuleProfile().debounce(500).collectLatest{
|
|
232
|
+
// if (it != null) {
|
|
233
|
+
// emitDeviceListChange()
|
|
234
|
+
// }
|
|
235
|
+
// }
|
|
236
|
+
// }
|
|
249
237
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
238
|
+
emptyFlow<Unit>()
|
|
239
|
+
}
|
|
240
|
+
.launchIn(CoroutineScope(Dispatchers.IO))
|
|
241
|
+
|
|
242
|
+
// 推送设备列表变化
|
|
243
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
244
|
+
deviceListState.debounce(500).collectLatest { deviceList ->
|
|
245
|
+
devices = deviceList
|
|
246
|
+
emitDeviceListChange()
|
|
247
|
+
}
|
|
259
248
|
}
|
|
249
|
+
}
|
|
260
250
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Number>(e))
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
251
|
+
/**
|
|
252
|
+
* RN的场景下
|
|
253
|
+
* module profile 变更 相当于设备列表变更
|
|
254
|
+
*/
|
|
255
|
+
suspend fun emitDeviceListChange() {
|
|
256
|
+
val deviceList = deviceListState.first()
|
|
257
|
+
// 缓存变更
|
|
258
|
+
val deviceListJson = JSONArray()
|
|
259
|
+
deviceList.forEach{ item ->
|
|
260
|
+
deviceListJson.put(item.toJsonObject())
|
|
275
261
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
var config = RNGizParamsChecker.check(options, result, GizGetProductConfig::class.java)
|
|
279
|
-
config?.let {
|
|
280
|
-
CoroutineScope(Dispatchers.IO).launch {
|
|
281
|
-
try {
|
|
282
|
-
val config = GizSDKManager.getProductDataPointConfig(config.productKey)
|
|
283
|
-
if (config != null) {
|
|
284
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(config))
|
|
285
|
-
} else {
|
|
286
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<String?>(GizException.GIZ_SITE_PRODUCTKEY_INVALID))
|
|
287
|
-
}
|
|
288
|
-
} catch (e: GizException) {
|
|
289
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Number>(e))
|
|
290
|
-
}
|
|
291
|
-
}
|
|
262
|
+
sendEvent(EventName.DeviceListListener.name, GizRNCallbackManager.jsonArray2WriteableArray(deviceListJson))
|
|
263
|
+
}
|
|
292
264
|
|
|
265
|
+
fun sendEvent(name:String, data: WritableArray?) {
|
|
266
|
+
mReactContext!!
|
|
267
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
268
|
+
.emit(name, data)
|
|
269
|
+
}
|
|
270
|
+
fun sendEvent(name:String, data: WritableMap?) {
|
|
271
|
+
mReactContext!!
|
|
272
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
273
|
+
.emit(name, data)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@ReactMethod
|
|
277
|
+
fun initSDK(options: ReadableMap, result: Callback) {
|
|
278
|
+
var config = RNGizParamsChecker.check(options, result, GizConfiguration::class.java)
|
|
279
|
+
config?.let {
|
|
280
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
281
|
+
try {
|
|
282
|
+
GizSDKManager.setDebug(true)
|
|
283
|
+
GizSDKManager.initSDK(config)
|
|
284
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
285
|
+
} catch (e: GizException) {
|
|
286
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Number>(e))
|
|
293
287
|
}
|
|
288
|
+
}
|
|
294
289
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
writableMap.putString("message", "")
|
|
311
|
-
result.invoke(null, writableMap)
|
|
312
|
-
emitDeviceListChange()
|
|
313
|
-
}
|
|
290
|
+
}
|
|
291
|
+
@ReactMethod
|
|
292
|
+
fun getProductDataPointConfig(options: ReadableMap, result: Callback) {
|
|
293
|
+
var config = RNGizParamsChecker.check(options, result, GizGetProductConfig::class.java)
|
|
294
|
+
config?.let {
|
|
295
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
296
|
+
try {
|
|
297
|
+
val config = GizSDKManager.getProductDataPointConfig(config.productKey)
|
|
298
|
+
if (config != null) {
|
|
299
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(config))
|
|
300
|
+
} else {
|
|
301
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<String?>(GizException.GIZ_SITE_PRODUCTKEY_INVALID))
|
|
302
|
+
}
|
|
303
|
+
} catch (e: GizException) {
|
|
304
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Number>(e))
|
|
314
305
|
}
|
|
315
|
-
|
|
306
|
+
}
|
|
316
307
|
|
|
317
|
-
@ReactMethod
|
|
318
|
-
fun startBleScan(options: ReadableMap, result: Callback) {
|
|
319
|
-
GizSDKManager.startBleScan()
|
|
320
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
321
|
-
}
|
|
322
|
-
@ReactMethod
|
|
323
|
-
fun stopBleScan(options: ReadableMap, result: Callback) {
|
|
324
|
-
GizSDKManager.stopBleScan()
|
|
325
|
-
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
326
308
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
309
|
+
}
|
|
310
|
+
@ReactMethod
|
|
311
|
+
fun getDevices(options: ReadableMap, result: Callback) {
|
|
312
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
313
|
+
// 查询 绑定设备 返回设备列表
|
|
314
|
+
GizSDKManager.queryBoundDevices()
|
|
315
|
+
deviceListState.take(1).collect {
|
|
316
|
+
val jsonData = JSONArray()
|
|
317
|
+
it.forEach{device ->
|
|
318
|
+
jsonData.put(device.toJsonObject())
|
|
333
319
|
}
|
|
320
|
+
// 设备列表比较特殊,手动回调
|
|
321
|
+
val writableMap = Arguments.createMap()
|
|
322
|
+
writableMap.putArray("data", GizRNCallbackManager.jsonArray2WriteableArray(jsonData))
|
|
323
|
+
writableMap.putBoolean("success", true)
|
|
324
|
+
writableMap.putInt("error", 0)
|
|
325
|
+
writableMap.putString("message", "")
|
|
326
|
+
result.invoke(null, writableMap)
|
|
327
|
+
emitDeviceListChange()
|
|
328
|
+
}
|
|
334
329
|
}
|
|
330
|
+
}
|
|
335
331
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
332
|
+
@ReactMethod
|
|
333
|
+
fun startBleScan(options: ReadableMap, result: Callback) {
|
|
334
|
+
GizSDKManager.startBleScan()
|
|
335
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
336
|
+
}
|
|
337
|
+
@ReactMethod
|
|
338
|
+
fun stopBleScan(options: ReadableMap, result: Callback) {
|
|
339
|
+
GizSDKManager.stopBleScan()
|
|
340
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
@ReactMethod
|
|
344
|
+
fun cleanCache(options: ReadableMap, result: Callback) {
|
|
345
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
346
|
+
GizSDKManager.cleanCache()
|
|
347
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
348
|
+
}
|
|
349
|
+
}
|
|
345
350
|
|
|
351
|
+
@ReactMethod
|
|
352
|
+
fun feedback(options: ReadableMap, result: Callback) {
|
|
353
|
+
var config = RNGizParamsChecker.check(options, result, GizFeedback::class.java)
|
|
354
|
+
config?.let {
|
|
355
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
356
|
+
GizSDKManager.feedback(config.uploadLog,config.contact,config.content)
|
|
357
|
+
GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
|
|
358
|
+
}
|
|
346
359
|
}
|
|
360
|
+
|
|
361
|
+
}
|
|
347
362
|
}
|
package/package.json
CHANGED