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.
@@ -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.72")
67
- implementation("io.github.gizwits:sdk-bluetooth:1.0.72")
68
- implementation("io.github.gizwits:sdk-lan:1.0.72")
69
- implementation("io.github.gizwits:sdk-mqtt:1.0.72")
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
@@ -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.disconnect()
315
- CapacityTypes.LAN -> device.lanCapability.disconnect()
316
- CapacityTypes.MQTT -> device.mqttCapability.disconnect()
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
- @SerializedName("productKey")
46
- val productKey: String,
50
+ @SerializedName("productKey")
51
+ val productKey: String,
47
52
  )
48
53
 
49
54
  data class GizFeedback(
50
- @SerializedName("uploadLog")
51
- val uploadLog: Boolean,
52
- @SerializedName("content")
53
- val content: String,
54
- @SerializedName("contact")
55
- val contact: String,
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
- private var mReactContext: ReactContext? = null
61
- init {
62
- mReactContext = reactContext
63
- }
64
- companion object {
65
- internal var devices = listOf<GizDevice>()
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
- enum class EventName(val value: String) {
68
- DeviceDataListener("DeviceDataListener"),
69
- DeviceListListener("DeviceListListener"),
70
- DeviceStateListener("DeviceStateListener"),
71
- DeviceBindStateListener("DeviceBindStateListener"),
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
- /** @hide */
75
- @OptIn(ExperimentalCoroutinesApi::class)
76
- fun <T1, T2, T3, R> combineLatest(
77
- flow1: Flow<T1>,
78
- flow2: Flow<T2>,
79
- flow3: Flow<T3>,
80
- transform: suspend (a: T1, b: T2, c: T3) -> R
81
- ): Flow<R> {
82
- return combine(flow1, flow2, flow3) { value1, value2, value3 ->
83
- Triple(value1, value2, value3)
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
- /** @hide */
89
- @OptIn(ExperimentalCoroutinesApi::class)
90
- fun <T1, T2, R> combineLatest(
91
- flow1: Flow<T1>,
92
- flow2: Flow<T2>,
93
- transform: suspend (a: T1, b: T2) -> R
94
- ): Flow<R> {
95
- return combine(flow1, flow2) { value1, value2 ->
96
- Pair(value1, value2)
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
- override fun getName() = "RNGizSDKManagerModule"
103
- private val deviceListState: Flow<List<GizDevice>> =
104
- combineLatest(
105
- GizSDKManager.subscribeBoundDeviceList(),
106
- GizSDKManager.subscribeBluetoothDeviceList(),
107
- GizSDKManager.subscribeLanDeviceList()
108
- ) { boundDeviceList, bluetoothDeviceList, lanDeviceList ->
109
- listOf(boundDeviceList, bluetoothDeviceList, lanDeviceList)
110
- .flatten()
111
- .distinct()
112
- }
113
-
114
- override fun initialize() {
115
- super.initialize()
116
- CoroutineScope(Dispatchers.IO).launch {
117
- GizSDKManager.subscribeBindEvent().collect {
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("did", it.first)
120
- data.put("isBind", it.second)
121
- sendEvent(EventName.DeviceBindStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
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
- scope.launch {
167
- combineLatest(
168
- dev.lanCapability.subscribeStatus(),
169
- dev.lanCapability.subscribeIsLogin(),
170
- ) { status, isLogin ->
171
- Pair(status, isLogin)
172
- }.collectLatest {
173
- val data = JSONObject()
174
- data.put("state", it.first.toInt())
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
- scope.launch {
200
- combineLatest(
201
- dev.mqttCapability.subscribeStatus(),
202
- dev.mqttCapability.subscribeIsLogin(),
203
- ) { status, isLogin ->
204
- Pair(status, isLogin)
205
- }.collectLatest {
206
- val data = JSONObject()
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
- * RN的场景下
238
- * module profile 变更 相当于设备列表变更
239
- */
240
- suspend fun emitDeviceListChange() {
241
- val deviceList = deviceListState.first()
242
- // 缓存变更
243
- val deviceListJson = JSONArray()
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
- fun sendEvent(name:String, data: WritableArray?) {
251
- mReactContext!!
252
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
253
- .emit(name, data)
254
- }
255
- fun sendEvent(name:String, data: WritableMap?) {
256
- mReactContext!!
257
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
258
- .emit(name, data)
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
- @ReactMethod
262
- fun initSDK(options: ReadableMap, result: Callback) {
263
- var config = RNGizParamsChecker.check(options, result, GizConfiguration::class.java)
264
- config?.let {
265
- CoroutineScope(Dispatchers.Main).launch {
266
- try {
267
- GizSDKManager.setDebug(true)
268
- GizSDKManager.initSDK(config)
269
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
270
- } catch (e: GizException) {
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
- @ReactMethod
277
- fun getProductDataPointConfig(options: ReadableMap, result: Callback) {
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
- @ReactMethod
296
- fun getDevices(options: ReadableMap, result: Callback) {
297
- CoroutineScope(Dispatchers.IO).launch {
298
- // 查询 绑定设备 返回设备列表
299
- GizSDKManager.queryBoundDevices()
300
- deviceListState.take(1).collect {
301
- val jsonData = JSONArray()
302
- it.forEach{device ->
303
- jsonData.put(device.toJsonObject())
304
- }
305
- // 设备列表比较特殊,手动回调
306
- val writableMap = Arguments.createMap()
307
- writableMap.putArray("data", GizRNCallbackManager.jsonArray2WriteableArray(jsonData))
308
- writableMap.putBoolean("success", true)
309
- writableMap.putInt("error", 0)
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
- @ReactMethod
329
- fun cleanCache(options: ReadableMap, result: Callback) {
330
- CoroutineScope(Dispatchers.IO).launch {
331
- GizSDKManager.cleanCache()
332
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
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
- @ReactMethod
337
- fun feedback(options: ReadableMap, result: Callback) {
338
- var config = RNGizParamsChecker.check(options, result, GizFeedback::class.java)
339
- config?.let {
340
- CoroutineScope(Dispatchers.IO).launch {
341
- GizSDKManager.feedback(config.uploadLog,config.contact,config.content)
342
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success<Number>(0))
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",
@@ -19,6 +19,6 @@ Pod::Spec.new do |s|
19
19
 
20
20
  s.dependency 'React'
21
21
  s.dependency 'CryptoSwift', '~> 1.8.0'
22
- s.dependency 'GizwitsiOSSDK', '~> 1.3.2'
22
+ s.dependency 'GizwitsiOSSDK', '~> 1.3.3'
23
23
 
24
24
  end