react-native-gizwits-sdk-v5 1.4.20 → 1.4.22

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,6 +63,8 @@ data class GizFeedback(
63
63
  class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
64
64
 
65
65
  private var mReactContext: ReactContext? = null
66
+
67
+ private var isSubscriptDevices: List<String> = listOf();
66
68
  init {
67
69
  mReactContext = reactContext
68
70
  }
@@ -132,108 +134,119 @@ class RNGizSDKManagerModule(reactContext: ReactApplicationContext) : ReactContex
132
134
  .debounce(500)
133
135
  .flatMapConcat { deviceList ->
134
136
  deviceList.map { dev ->
135
- CoroutineScope(Dispatchers.IO).launch {
136
- async {
137
- dev.bleCapability.subscribeModuleProfile().debounce(500).collect {
138
- if (it != null) {
139
- emitDeviceListChange()
137
+
138
+ if (!isSubscriptDevices.contains(dev.mac)) {
139
+ CoroutineScope(Dispatchers.IO).launch {
140
+ async {
141
+ dev.bleCapability.subscribeModuleProfile().debounce(500).collect {
142
+ if (it != null) {
143
+ emitDeviceListChange()
144
+ }
140
145
  }
141
146
  }
142
- }
143
- async {
144
- combine(
145
- dev.bleCapability.subscribeStatus(),
146
- dev.bleCapability.subscribeIsLogin(),
147
- ) { status, isLogin ->
148
- Pair(status, isLogin)
149
- }.collect {
150
- val data = JSONObject()
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))
147
+ async {
148
+ combine(
149
+ dev.bleCapability.subscribeStatus(),
150
+ dev.bleCapability.subscribeIsLogin(),
151
+ ) { status, isLogin ->
152
+ Pair(status, isLogin)
153
+ }.collect {
154
+ val data = JSONObject()
155
+ data.put("state", it.first.toInt())
156
+ data.put("isLogin", it.second)
157
+ data.put("type", "BLE")
158
+ data.put("device", dev.toJsonObject())
159
+ sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
160
+ }
156
161
  }
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))
162
+ async {
163
+ dev.bleCapability.subscribeDp().collect{
164
+ val data = JSONObject()
165
+ data.put("data", JSONObject(it.toString()))
166
+ data.put("type", "BLE")
167
+ data.put("device", dev.toJsonObject())
168
+ sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
169
+ }
165
170
  }
166
- }
167
- async {
168
- dev.lanCapability.subscribeModuleProfile().debounce(500).collectLatest{
169
- if (it != null) {
170
- emitDeviceListChange()
171
+ async {
172
+ dev.lanCapability.subscribeModuleProfile().debounce(500).collectLatest{
173
+ if (it != null) {
174
+ emitDeviceListChange()
175
+ }
171
176
  }
172
177
  }
173
- }
174
178
 
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))
179
+ async {
180
+ combineLatest(
181
+ dev.lanCapability.subscribeStatus(),
182
+ dev.lanCapability.subscribeIsLogin(),
183
+ ) { status, isLogin ->
184
+ Pair(status, isLogin)
185
+ }.collectLatest {
186
+ val data = JSONObject()
187
+ data.put("state", it.first.toInt())
188
+ data.put("isLogin", it.second)
189
+ data.put("type", "LAN")
190
+ data.put("device", dev.toJsonObject())
191
+ sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
192
+ }
188
193
  }
189
- }
190
194
 
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))
195
+ async {
196
+ dev.lanCapability.subscribeDp().collect{
197
+ val data = JSONObject()
198
+ data.put("data", JSONObject(it.toString()))
199
+ data.put("type", "LAN")
200
+ data.put("device", dev.toJsonObject())
201
+ sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
202
+ }
198
203
  }
199
- }
200
204
 
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))
205
+ async {
206
+ combineLatest(
207
+ dev.mqttCapability.subscribeStatus(),
208
+ dev.mqttCapability.subscribeIsLogin(),
209
+ ) { status, isLogin ->
210
+ Pair(status, isLogin)
211
+ }.collectLatest {
212
+ val data = JSONObject()
213
+ data.put("state", it.first.toInt())
214
+ data.put("isLogin", it.second)
215
+ data.put("type", "MQTT")
216
+ data.put("device", dev.toJsonObject())
217
+ sendEvent(EventName.DeviceStateListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
218
+ }
214
219
  }
215
- }
216
220
 
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))
221
+ // 不会主动发生改表
222
+ // async {
223
+ // dev.mqttCapability.subscribeModuleProfile().debounce(500).collectLatest{
224
+ // if (it != null) {
225
+ // emitDeviceListChange()
226
+ // }
227
+ // }
228
+ // }
229
+
230
+ async {
231
+ dev.mqttCapability.subscribeDp().collect{
232
+ val data = JSONObject()
233
+ data.put("data", JSONObject(it.toString()))
234
+ data.put("type", "MQTT")
235
+ data.put("device", dev.toJsonObject())
236
+ sendEvent(EventName.DeviceDataListener.name, GizRNCallbackManager.jsonObject2WriteableMap(data))
237
+ }
224
238
  }
225
239
  }
226
240
  }
227
241
  }
228
242
 
229
- // 不会主动发生改表
230
- // async {
231
- // dev.mqttCapability.subscribeModuleProfile().debounce(500).collectLatest{
232
- // if (it != null) {
233
- // emitDeviceListChange()
234
- // }
235
- // }
236
- // }
243
+ /*
244
+ 更新当前已经订阅的设备
245
+ 如果设备消失,又出现,就可以正常的重新订阅
246
+ */
247
+ isSubscriptDevices = deviceList.map{
248
+ it.mac
249
+ }
237
250
 
238
251
  emptyFlow<Unit>()
239
252
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.4.20",
3
+ "version": "1.4.22",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",