react-native-gizwits-sdk-v5 1.4.57 → 1.4.58

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,12 @@ dependencies {
63
63
 
64
64
  implementation "androidx.startup:startup-runtime:$startup_version"
65
65
 
66
- implementation("io.github.gizwits:sdk:1.2.9")
67
- implementation("io.github.gizwits:sdk-bluetooth:1.2.9")
68
- implementation("io.github.gizwits:sdk-lan:1.2.9")
69
- implementation("io.github.gizwits:sdk-mqtt:1.2.9")
66
+ implementation 'com.github.wendykierp:JTransforms:3.1'
67
+
68
+ implementation("io.github.gizwits:sdk:1.3.0")
69
+ implementation("io.github.gizwits:sdk-bluetooth:1.3.0")
70
+ implementation("io.github.gizwits:sdk-lan:1.3.0")
71
+ implementation("io.github.gizwits:sdk-mqtt:1.3.0")
70
72
  // implementation files('libs/sdk-release.aar', 'libs/sdk-bluetooth-release.aar', 'libs/sdk-lan-release.aar', 'libs/sdk-mqtt-release.aar')
71
73
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
72
74
  // retrofit
@@ -27,440 +27,455 @@ import com.google.gson.annotations.SerializedName
27
27
  import kotlinx.coroutines.CoroutineScope
28
28
  import kotlinx.coroutines.Dispatchers
29
29
  import kotlinx.coroutines.launch
30
+ import org.json.JSONArray
30
31
  import org.json.JSONObject
31
32
 
32
33
  data class GizBindParams(
33
- @SerializedName("id")
34
- override val id: String,
35
- @SerializedName("alias")
36
- val alias: String,
37
- @SerializedName("remark")
38
- val remark: String,
34
+ @SerializedName("id")
35
+ override val id: String,
36
+ @SerializedName("alias")
37
+ val alias: String,
38
+ @SerializedName("remark")
39
+ val remark: String,
39
40
  ) : DeviceParams
40
41
 
41
42
  data class UpdateDeviceInfoParams(
42
- @SerializedName("id")
43
- override val id: String,
44
- @SerializedName("alias")
45
- val alias: String,
46
- @SerializedName("remark")
47
- val remark: String,
43
+ @SerializedName("id")
44
+ override val id: String,
45
+ @SerializedName("alias")
46
+ val alias: String,
47
+ @SerializedName("remark")
48
+ val remark: String,
48
49
  ) : DeviceParams
49
50
 
50
51
  data class GizGetDPParams(
51
- @SerializedName("id")
52
- override val id: String,
53
- @SerializedName("type")
54
- val type: CapacityTypes,
55
- @SerializedName("attrs")
56
- val attrs: JsonArray?,
52
+ @SerializedName("id")
53
+ override val id: String,
54
+ @SerializedName("type")
55
+ val type: CapacityTypes,
56
+ @SerializedName("attrs")
57
+ val attrs: JsonArray?,
57
58
  ) : DeviceParams
58
59
 
59
60
  data class GizSendDPParams(
60
- @SerializedName("id")
61
- override val id: String,
62
- @SerializedName("type")
63
- val type: CapacityTypes,
64
- @SerializedName("data")
65
- val data: String,
61
+ @SerializedName("id")
62
+ override val id: String,
63
+ @SerializedName("type")
64
+ val type: CapacityTypes,
65
+ @SerializedName("data")
66
+ val data: String,
66
67
  ) : DeviceParams
67
68
 
68
69
  data class GizUnBindParams(
69
- @SerializedName("id")
70
- override val id: String,
70
+ @SerializedName("id")
71
+ override val id: String,
71
72
  ): DeviceParams
72
73
 
73
74
  data class StopMusicalRhythmParams(
74
- @SerializedName("id")
75
- override val id: String,
75
+ @SerializedName("id")
76
+ override val id: String,
76
77
  ): DeviceParams
77
78
 
78
79
  data class StartMusicalRhythmParams(
79
- @SerializedName("id")
80
- override val id: String,
81
- @SerializedName("needMonitor")
82
- val needMonitor: Boolean,
83
- @SerializedName("sensitivity")
84
- val sensitivity: Int,
85
- @SerializedName("mode")
86
- val mode: MusicalRhythmParseMode,
80
+ @SerializedName("id")
81
+ override val id: String,
82
+ @SerializedName("needMonitor")
83
+ val needMonitor: Boolean,
84
+ @SerializedName("sensitivity")
85
+ val sensitivity: Int,
86
+ @SerializedName("mode")
87
+ val mode: MusicalRhythmParseMode,
87
88
  ): DeviceParams
88
89
 
89
90
  data class GizConnectParams(
90
- @SerializedName("id")
91
- override val id: String,
92
- @SerializedName("type")
93
- val type: CapacityTypes
91
+ @SerializedName("id")
92
+ override val id: String,
93
+ @SerializedName("type")
94
+ val type: CapacityTypes
94
95
  ): DeviceParams
95
96
  data class GizDisConnectParams(
96
- @SerializedName("id")
97
- override val id: String,
98
- @SerializedName("type")
99
- val type: CapacityTypes
97
+ @SerializedName("id")
98
+ override val id: String,
99
+ @SerializedName("type")
100
+ val type: CapacityTypes
100
101
  ): DeviceParams
101
102
 
102
103
  data class GizRegisterDeviceParams(
103
- @SerializedName("id")
104
- override val id: String,
104
+ @SerializedName("id")
105
+ override val id: String,
105
106
  ): DeviceParams
106
107
 
107
108
  data class GizProvideWiFiCredentialsParams(
108
- @SerializedName("id")
109
- override val id: String,
110
- @SerializedName("type")
111
- val type: CapacityTypes,
112
- @SerializedName("ssid")
113
- val ssid: String,
114
- @SerializedName("password")
115
- val password: String,
116
- @SerializedName("timeout")
117
- val timeout: Long,
109
+ @SerializedName("id")
110
+ override val id: String,
111
+ @SerializedName("type")
112
+ val type: CapacityTypes,
113
+ @SerializedName("ssid")
114
+ val ssid: String,
115
+ @SerializedName("password")
116
+ val password: String,
117
+ @SerializedName("timeout")
118
+ val timeout: Long,
118
119
  ): DeviceParams
119
120
  data class GizStopProvideWiFiCredentialsParams(
120
- @SerializedName("id")
121
- override val id: String,
122
- @SerializedName("type")
123
- val type: CapacityTypes,
121
+ @SerializedName("id")
122
+ override val id: String,
123
+ @SerializedName("type")
124
+ val type: CapacityTypes,
124
125
  ): DeviceParams
125
126
 
126
127
  data class GizGetDeviceInfoParams(
127
- @SerializedName("id")
128
- override val id: String,
129
- @SerializedName("type")
130
- val type: CapacityTypes
128
+ @SerializedName("id")
129
+ override val id: String,
130
+ @SerializedName("type")
131
+ val type: CapacityTypes
131
132
  ): DeviceParams
132
133
  data class GizCheckUpdateParams(
133
- @SerializedName("id")
134
- override val id: String,
135
- @SerializedName("type")
136
- val type: CapacityTypes,
137
- @SerializedName("firmwareType")
138
- val firmwareType: GizOTAFirmwareType
134
+ @SerializedName("id")
135
+ override val id: String,
136
+ @SerializedName("type")
137
+ val type: CapacityTypes,
138
+ @SerializedName("firmwareType")
139
+ val firmwareType: GizOTAFirmwareType
139
140
  ): DeviceParams
140
141
  data class StopUpgradeParams(
141
- @SerializedName("id")
142
- override val id: String,
143
- @SerializedName("type")
144
- val type: CapacityTypes,
142
+ @SerializedName("id")
143
+ override val id: String,
144
+ @SerializedName("type")
145
+ val type: CapacityTypes,
145
146
  ): DeviceParams
146
147
 
147
148
 
148
149
  class RNGizDeviceManagerModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
149
- enum class EventName(val value: String) {
150
- GizOTAProgressEvent("GizOTAProgressEvent"),
151
- GizProvideWiFiCredentialsEvent("GizProvideWiFiCredentialsEvent"),
152
- GizMusicalRhythmEvnet("GizMusicalRhythmEvnet")
153
- }
150
+ enum class EventName(val value: String) {
151
+ GizOTAProgressEvent("GizOTAProgressEvent"),
152
+ GizProvideWiFiCredentialsEvent("GizProvideWiFiCredentialsEvent"),
153
+ GizMusicalRhythmEvnet("GizMusicalRhythmEvnet")
154
+ }
154
155
 
155
- fun jsonObjectToPairs(jsonObject: JsonObject): Array<Pair<String, Any>> {
156
- val pairs = mutableListOf<Pair<String, Any>>()
157
- for ((key, value) in jsonObject.entrySet()) {
158
- val pair = key to value
159
- pairs.add(pair)
160
- }
161
- return pairs.toTypedArray()
156
+ fun jsonObjectToPairs(jsonObject: JsonObject): Array<Pair<String, Any>> {
157
+ val pairs = mutableListOf<Pair<String, Any>>()
158
+ for ((key, value) in jsonObject.entrySet()) {
159
+ val pair = key to value
160
+ pairs.add(pair)
162
161
  }
162
+ return pairs.toTypedArray()
163
+ }
163
164
 
164
- override fun getName() = "RNGizDeviceManagerModule"
165
- @ReactMethod
166
- fun sendDp(options: ReadableMap, result: Callback) {
167
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizSendDPParams::class.java)
168
- if (config !=null && device !=null) {
169
- CoroutineScope(Dispatchers.IO).launch {
170
- try {
171
- val gson = Gson()
172
- val jsonObject = gson.fromJson(config.data, JsonObject::class.java)
173
- val attrs = jsonObjectToPairs(jsonObject)
174
- val res = when(config.type) {
175
- CapacityTypes.BLE -> device.bleCapability.sendDp(*attrs)
176
- CapacityTypes.LAN -> device.lanCapability.sendDp(*attrs)
177
- CapacityTypes.MQTT -> device.mqttCapability.sendDp(*attrs)
178
- }
179
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
180
- }catch (e: Exception) {
181
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Unit>(e))
182
- }
183
- }
165
+ override fun getName() = "RNGizDeviceManagerModule"
166
+ @ReactMethod
167
+ fun sendDp(options: ReadableMap, result: Callback) {
168
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizSendDPParams::class.java)
169
+ if (config !=null && device !=null) {
170
+ CoroutineScope(Dispatchers.IO).launch {
171
+ try {
172
+ val gson = Gson()
173
+ val jsonObject = gson.fromJson(config.data, JsonObject::class.java)
174
+ val attrs = jsonObjectToPairs(jsonObject)
175
+ val res = when(config.type) {
176
+ CapacityTypes.BLE -> device.bleCapability.sendDp(*attrs)
177
+ CapacityTypes.LAN -> device.lanCapability.sendDp(*attrs)
178
+ CapacityTypes.MQTT -> device.mqttCapability.sendDp(*attrs)
179
+ }
180
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
181
+ }catch (e: Exception) {
182
+ GizRNCallbackManager.callbackWithResult(callback = result, result = Result.failure<Unit>(e))
184
183
  }
184
+ }
185
185
  }
186
- @ReactMethod
187
- fun getDp(options: ReadableMap, result: Callback) {
188
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDPParams::class.java)
189
- if (config !=null && device !=null) {
190
- CoroutineScope(Dispatchers.IO).launch {
191
- var res = when(config.type) {
192
- CapacityTypes.BLE -> device.bleCapability.getDp(config.attrs)
193
- CapacityTypes.LAN -> device.lanCapability.getDp(config.attrs)
194
- CapacityTypes.MQTT -> device.mqttCapability.getDp(config.attrs)
195
- }
196
- if (res.isSuccess) {
197
- var jsonObject = res.getOrNull() ?: JSONObject()
198
- val newRes = JSONObject()
199
- newRes.put("success", true)
200
- newRes.put("data", JSONObject(jsonObject.toString()))
201
- result.invoke(null, GizRNCallbackManager.jsonObject2WriteableMap(newRes))
202
- } else {
203
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
204
- }
205
- }
186
+ }
187
+ @ReactMethod
188
+ fun getDp(options: ReadableMap, result: Callback) {
189
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDPParams::class.java)
190
+ if (config !=null && device !=null) {
191
+ CoroutineScope(Dispatchers.IO).launch {
192
+ var res = when(config.type) {
193
+ CapacityTypes.BLE -> device.bleCapability.getDp(config.attrs)
194
+ CapacityTypes.LAN -> device.lanCapability.getDp(config.attrs)
195
+ CapacityTypes.MQTT -> device.mqttCapability.getDp(config.attrs)
196
+ }
197
+ if (res.isSuccess) {
198
+ var jsonObject = res.getOrNull() ?: JSONObject()
199
+ val newRes = JSONObject()
200
+ newRes.put("success", true)
201
+ newRes.put("data", JSONObject(jsonObject.toString()))
202
+ result.invoke(null, GizRNCallbackManager.jsonObject2WriteableMap(newRes))
203
+ } else {
204
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
206
205
  }
206
+ }
207
207
  }
208
- @ReactMethod
209
- fun getDeviceInfo(options: ReadableMap, result: Callback) {
210
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDeviceInfoParams::class.java)
211
- if (config !=null && device !=null) {
212
- CoroutineScope(Dispatchers.IO).launch {
213
- val res = when(config.type) {
214
- CapacityTypes.BLE -> device.bleCapability.getDeviceInfo()
215
- CapacityTypes.LAN -> device.lanCapability.getDeviceInfo()
216
- CapacityTypes.MQTT -> device.mqttCapability.getDeviceInfo()
217
- }
218
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
219
- }
208
+ }
209
+ @ReactMethod
210
+ fun getDeviceInfo(options: ReadableMap, result: Callback) {
211
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizGetDeviceInfoParams::class.java)
212
+ if (config !=null && device !=null) {
213
+ CoroutineScope(Dispatchers.IO).launch {
214
+ val res = when(config.type) {
215
+ CapacityTypes.BLE -> device.bleCapability.getDeviceInfo()
216
+ CapacityTypes.LAN -> device.lanCapability.getDeviceInfo()
217
+ CapacityTypes.MQTT -> device.mqttCapability.getDeviceInfo()
220
218
  }
219
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
220
+ }
221
221
  }
222
+ }
222
223
 
223
- @ReactMethod
224
- fun updateDeviceInfo(options: ReadableMap, result: Callback) {
225
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, UpdateDeviceInfoParams::class.java)
226
- if (config !=null && device !=null) {
227
- CoroutineScope(Dispatchers.IO).launch {
228
- val res = device.updateDeviceInfo(config.alias, config.remark)
229
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
230
- // if (res.isSuccess) {
231
- // GizSDKManager.queryBoundDevices()
232
- // }
233
- }
234
- }
224
+ @ReactMethod
225
+ fun updateDeviceInfo(options: ReadableMap, result: Callback) {
226
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, UpdateDeviceInfoParams::class.java)
227
+ if (config !=null && device !=null) {
228
+ CoroutineScope(Dispatchers.IO).launch {
229
+ val res = device.updateDeviceInfo(config.alias, config.remark)
230
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
231
+ // if (res.isSuccess) {
232
+ // GizSDKManager.queryBoundDevices()
233
+ // }
234
+ }
235
235
  }
236
+ }
236
237
 
237
- @ReactMethod
238
- fun bind(options: ReadableMap, result: Callback) {
239
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizBindParams::class.java)
240
- if (config !=null && device !=null) {
241
- CoroutineScope(Dispatchers.IO).launch {
242
- val res = device.bind(config.alias, config.remark)
243
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
244
- // if (res.isSuccess) {
245
- // GizSDKManager.queryBoundDevices()
246
- // }
247
- }
248
- }
238
+ @ReactMethod
239
+ fun bind(options: ReadableMap, result: Callback) {
240
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizBindParams::class.java)
241
+ if (config !=null && device !=null) {
242
+ CoroutineScope(Dispatchers.IO).launch {
243
+ val res = device.bind(config.alias, config.remark)
244
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
245
+ // if (res.isSuccess) {
246
+ // GizSDKManager.queryBoundDevices()
247
+ // }
248
+ }
249
249
  }
250
+ }
250
251
 
251
- @ReactMethod
252
- fun unBind(options: ReadableMap, result: Callback) {
253
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizUnBindParams::class.java)
254
- if (config !=null && device !=null) {
255
- CoroutineScope(Dispatchers.IO).launch {
256
- val res = device.unBind()
257
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
258
- if (res.isSuccess) {
259
- GizSDKManager.queryBoundDevices()
260
- }
261
- }
252
+ @ReactMethod
253
+ fun unBind(options: ReadableMap, result: Callback) {
254
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizUnBindParams::class.java)
255
+ if (config !=null && device !=null) {
256
+ CoroutineScope(Dispatchers.IO).launch {
257
+ val res = device.unBind()
258
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
259
+ if (res.isSuccess) {
260
+ GizSDKManager.queryBoundDevices()
262
261
  }
262
+ }
263
263
  }
264
- @ReactMethod
265
- fun stopProvideWiFiCredentials(options: ReadableMap, result: Callback) {
266
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizStopProvideWiFiCredentialsParams::class.java)
267
- if (config !=null && device !=null) {
268
- CoroutineScope(Dispatchers.IO).launch {
269
- val res = when(config.type) {
270
- CapacityTypes.BLE -> device.bleCapability.stopProvideWiFiCredentials()
271
- CapacityTypes.LAN -> device.lanCapability.stopProvideWiFiCredentials()
272
- CapacityTypes.MQTT -> device.mqttCapability.stopProvideWiFiCredentials()
273
- }
274
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
275
- }
264
+ }
265
+ @ReactMethod
266
+ fun stopProvideWiFiCredentials(options: ReadableMap, result: Callback) {
267
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizStopProvideWiFiCredentialsParams::class.java)
268
+ if (config !=null && device !=null) {
269
+ CoroutineScope(Dispatchers.IO).launch {
270
+ val res = when(config.type) {
271
+ CapacityTypes.BLE -> device.bleCapability.stopProvideWiFiCredentials()
272
+ CapacityTypes.LAN -> device.lanCapability.stopProvideWiFiCredentials()
273
+ CapacityTypes.MQTT -> device.mqttCapability.stopProvideWiFiCredentials()
276
274
  }
275
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
276
+ }
277
277
  }
278
+ }
278
279
 
279
- fun wiFiCredentialsEventHandler(event: ProvideWiFiCredentialsEvent, device: GizDevice) {
280
- val jsonObject = JSONObject()
281
- jsonObject.put("data", event.toString())
282
- jsonObject.put("device", device.toJsonObject())
283
- sendEvent(
284
- EventName.GizProvideWiFiCredentialsEvent.name,
285
- GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
286
- )
287
- }
288
- @ReactMethod
289
- fun provideWiFiCredentials(options: ReadableMap, result: Callback) {
290
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizProvideWiFiCredentialsParams::class.java)
291
- if (config !=null && device !=null) {
292
- CoroutineScope(Dispatchers.IO).launch {
293
- val res = when(config.type) {
294
- CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
295
- config.ssid,
296
- config.password,
297
- config.timeout,
298
- processHandler = {
299
- wiFiCredentialsEventHandler(it, device)
300
- }
301
- )
302
- CapacityTypes.LAN -> device.lanCapability.provideWiFiCredentials(
303
- config.ssid,
304
- config.password,
305
- config.timeout,
306
- processHandler = {
307
- wiFiCredentialsEventHandler(it, device)
308
- }
309
- )
310
- CapacityTypes.MQTT -> device.mqttCapability.provideWiFiCredentials(
311
- config.ssid,
312
- config.password,
313
- config.timeout,
314
- processHandler = {
315
- wiFiCredentialsEventHandler(it, device)
316
- }
317
- )
318
- }
319
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
280
+ fun wiFiCredentialsEventHandler(event: ProvideWiFiCredentialsEvent, device: GizDevice) {
281
+ val jsonObject = JSONObject()
282
+ jsonObject.put("data", event.toString())
283
+ jsonObject.put("device", device.toJsonObject())
284
+ sendEvent(
285
+ EventName.GizProvideWiFiCredentialsEvent.name,
286
+ GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
287
+ )
288
+ }
289
+ @ReactMethod
290
+ fun provideWiFiCredentials(options: ReadableMap, result: Callback) {
291
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizProvideWiFiCredentialsParams::class.java)
292
+ if (config !=null && device !=null) {
293
+ CoroutineScope(Dispatchers.IO).launch {
294
+ val res = when(config.type) {
295
+ CapacityTypes.BLE -> device.bleCapability.provideWiFiCredentials(
296
+ config.ssid,
297
+ config.password,
298
+ config.timeout,
299
+ processHandler = {
300
+ wiFiCredentialsEventHandler(it, device)
301
+ }
302
+ )
303
+ CapacityTypes.LAN -> device.lanCapability.provideWiFiCredentials(
304
+ config.ssid,
305
+ config.password,
306
+ config.timeout,
307
+ processHandler = {
308
+ wiFiCredentialsEventHandler(it, device)
309
+ }
310
+ )
311
+ CapacityTypes.MQTT -> device.mqttCapability.provideWiFiCredentials(
312
+ config.ssid,
313
+ config.password,
314
+ config.timeout,
315
+ processHandler = {
316
+ wiFiCredentialsEventHandler(it, device)
320
317
  }
318
+ )
321
319
  }
320
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
321
+ }
322
322
  }
323
+ }
323
324
 
324
- @ReactMethod
325
- fun register(options: ReadableMap, result: Callback) {
326
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizRegisterDeviceParams::class.java)
327
- if (config !=null && device !=null) {
328
- CoroutineScope(Dispatchers.IO).launch {
329
- val res = device.register()
330
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
331
- }
332
- }
325
+ @ReactMethod
326
+ fun register(options: ReadableMap, result: Callback) {
327
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizRegisterDeviceParams::class.java)
328
+ if (config !=null && device !=null) {
329
+ CoroutineScope(Dispatchers.IO).launch {
330
+ val res = device.register()
331
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
332
+ }
333
333
  }
334
+ }
334
335
 
335
- @ReactMethod
336
- fun connect(options: ReadableMap, result: Callback) {
337
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizConnectParams::class.java)
338
- if (config !=null && device !=null) {
339
- CoroutineScope(Dispatchers.IO).launch {
340
- val res = when(config.type) {
341
- CapacityTypes.BLE -> device.bleCapability.connect()
342
- CapacityTypes.LAN -> device.lanCapability.connect()
343
- CapacityTypes.MQTT -> device.mqttCapability.connect()
344
- }
345
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
346
- }
336
+ @ReactMethod
337
+ fun connect(options: ReadableMap, result: Callback) {
338
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizConnectParams::class.java)
339
+ if (config !=null && device !=null) {
340
+ CoroutineScope(Dispatchers.IO).launch {
341
+ val res = when(config.type) {
342
+ CapacityTypes.BLE -> device.bleCapability.connect()
343
+ CapacityTypes.LAN -> device.lanCapability.connect()
344
+ CapacityTypes.MQTT -> device.mqttCapability.connect()
347
345
  }
346
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
347
+ }
348
348
  }
349
- @ReactMethod
350
- fun disConnect(options: ReadableMap, result: Callback) {
351
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizDisConnectParams::class.java)
352
- if (config !=null && device !=null) {
353
- CoroutineScope(Dispatchers.IO).launch {
354
- val res = when(config.type) {
355
- CapacityTypes.BLE -> device.bleCapability.disConnect()
356
- CapacityTypes.LAN -> device.lanCapability.disConnect()
357
- CapacityTypes.MQTT -> device.mqttCapability.disConnect()
358
- }
359
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
360
- }
349
+ }
350
+ @ReactMethod
351
+ fun disConnect(options: ReadableMap, result: Callback) {
352
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizDisConnectParams::class.java)
353
+ if (config !=null && device !=null) {
354
+ CoroutineScope(Dispatchers.IO).launch {
355
+ val res = when(config.type) {
356
+ CapacityTypes.BLE -> device.bleCapability.disConnect()
357
+ CapacityTypes.LAN -> device.lanCapability.disConnect()
358
+ CapacityTypes.MQTT -> device.mqttCapability.disConnect()
361
359
  }
360
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
361
+ }
362
362
  }
363
+ }
363
364
 
364
- @ReactMethod
365
- fun checkUpdate(options: ReadableMap, result: Callback) {
366
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
367
- if (config !=null && device !=null) {
368
- CoroutineScope(Dispatchers.IO).launch {
369
- val res = when(config.type) {
370
- CapacityTypes.BLE -> device.bleCapability.checkUpdate(config.firmwareType)
371
- CapacityTypes.LAN -> device.lanCapability.checkUpdate(config.firmwareType)
372
- CapacityTypes.MQTT -> device.mqttCapability.checkUpdate(config.firmwareType)
373
- }
374
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
375
- }
365
+ @ReactMethod
366
+ fun checkUpdate(options: ReadableMap, result: Callback) {
367
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
368
+ if (config !=null && device !=null) {
369
+ CoroutineScope(Dispatchers.IO).launch {
370
+ val res = when(config.type) {
371
+ CapacityTypes.BLE -> device.bleCapability.checkUpdate(config.firmwareType)
372
+ CapacityTypes.LAN -> device.lanCapability.checkUpdate(config.firmwareType)
373
+ CapacityTypes.MQTT -> device.mqttCapability.checkUpdate(config.firmwareType)
376
374
  }
375
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
376
+ }
377
377
  }
378
+ }
378
379
 
379
- fun handleStartUpgradeProgress(event: OTAProgressData, device: GizDevice) {
380
- val jsonObject = JSONObject()
381
- val dataObject = JSONObject()
382
- dataObject.put("percentage", event.percentage)
383
- dataObject.put("event", event.event.value)
384
- jsonObject.put("data", dataObject)
385
- jsonObject.put("device", device.toJsonObject())
386
- sendEvent(
387
- EventName.GizOTAProgressEvent.name,
388
- GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
389
- )
390
- }
391
- @ReactMethod
392
- fun startUpgrade(options: ReadableMap, result: Callback) {
393
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
394
- if (config !=null && device !=null) {
395
- CoroutineScope(Dispatchers.IO).launch {
396
- val res = when(config.type) {
397
- CapacityTypes.BLE -> {
398
- device.bleCapability.startUpgrade(config.firmwareType, processHandler = {
399
- handleStartUpgradeProgress(it, device)
400
- })
401
- }
402
- CapacityTypes.LAN -> device.lanCapability.startUpgrade(config.firmwareType, processHandler = {
403
- handleStartUpgradeProgress(it, device)
404
- })
405
- CapacityTypes.MQTT -> device.mqttCapability.startUpgrade(config.firmwareType, processHandler = {
406
- handleStartUpgradeProgress(it, device)
407
- })
408
- }
409
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
410
- }
380
+ fun handleStartUpgradeProgress(event: OTAProgressData, device: GizDevice) {
381
+ val jsonObject = JSONObject()
382
+ val dataObject = JSONObject()
383
+ dataObject.put("percentage", event.percentage)
384
+ dataObject.put("event", event.event.value)
385
+ jsonObject.put("data", dataObject)
386
+ jsonObject.put("device", device.toJsonObject())
387
+ sendEvent(
388
+ EventName.GizOTAProgressEvent.name,
389
+ GizRNCallbackManager.jsonObject2WriteableMap(jsonObject)
390
+ )
391
+ }
392
+ @ReactMethod
393
+ fun startUpgrade(options: ReadableMap, result: Callback) {
394
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, GizCheckUpdateParams::class.java)
395
+ if (config !=null && device !=null) {
396
+ CoroutineScope(Dispatchers.IO).launch {
397
+ val res = when(config.type) {
398
+ CapacityTypes.BLE -> {
399
+ device.bleCapability.startUpgrade(config.firmwareType, processHandler = {
400
+ handleStartUpgradeProgress(it, device)
401
+ })
402
+ }
403
+ CapacityTypes.LAN -> device.lanCapability.startUpgrade(config.firmwareType, processHandler = {
404
+ handleStartUpgradeProgress(it, device)
405
+ })
406
+ CapacityTypes.MQTT -> device.mqttCapability.startUpgrade(config.firmwareType, processHandler = {
407
+ handleStartUpgradeProgress(it, device)
408
+ })
411
409
  }
410
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
411
+ }
412
412
  }
413
- @ReactMethod
414
- fun cancelUpgrade(options: ReadableMap, result: Callback) {
415
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopUpgradeParams::class.java)
416
- if (config !=null && device !=null) {
417
- CoroutineScope(Dispatchers.IO).launch {
418
- val res = when(config.type) {
419
- CapacityTypes.BLE -> device.bleCapability.cancelUpgrade()
420
- CapacityTypes.LAN -> device.lanCapability.cancelUpgrade()
421
- CapacityTypes.MQTT -> device.mqttCapability.cancelUpgrade()
422
- }
423
- GizRNCallbackManager.callbackWithResult(callback = result, result = res)
424
- }
413
+ }
414
+ @ReactMethod
415
+ fun cancelUpgrade(options: ReadableMap, result: Callback) {
416
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopUpgradeParams::class.java)
417
+ if (config !=null && device !=null) {
418
+ CoroutineScope(Dispatchers.IO).launch {
419
+ val res = when(config.type) {
420
+ CapacityTypes.BLE -> device.bleCapability.cancelUpgrade()
421
+ CapacityTypes.LAN -> device.lanCapability.cancelUpgrade()
422
+ CapacityTypes.MQTT -> device.mqttCapability.cancelUpgrade()
425
423
  }
424
+ GizRNCallbackManager.callbackWithResult(callback = result, result = res)
425
+ }
426
426
  }
427
- @ReactMethod
428
- fun startMusicalRhythm(options: ReadableMap, result: Callback) {
429
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StartMusicalRhythmParams::class.java)
430
- print("startMusicalRhythm ${config}")
431
- if (config !=null && device !=null) {
432
- CoroutineScope(Dispatchers.IO).launch {
433
- val res = device.startMusicalRhythm(config.sensitivity, config.mode) {
434
- if (config.needMonitor) {
435
- val jsonObject = JSONObject()
436
- val gson = Gson()
437
- val dataString = gson.toJson(it)
438
- jsonObject.put("data", dataString)
439
- jsonObject.put("deviceID", config.id)
440
- sendEvent(EventName.GizMusicalRhythmEvnet.name, GizRNCallbackManager.jsonObject2WriteableMap(jsonObject))
441
- }
427
+ }
428
+ @ReactMethod
429
+ fun startMusicalRhythm(options: ReadableMap, result: Callback) {
430
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StartMusicalRhythmParams::class.java)
431
+ print("startMusicalRhythm ${config}")
432
+ if (config !=null && device !=null) {
433
+ CoroutineScope(Dispatchers.IO).launch {
434
+ val res = device.startMusicalRhythm(config.sensitivity, config.mode) { data ->
435
+ if (config.needMonitor) {
436
+ val jsonObject = JSONObject()
437
+ val jsonData = JSONObject()
438
+
439
+ jsonData.put("bpm",data.bpm)
440
+ jsonData.put("isBeat",data.isBeat)
441
+ jsonData.put("midiValue",data.midiValue)
442
+ jsonData.put("hue",data.hue)
443
+ jsonData.put("powerLevel",data.powerLevel)
444
+
445
+ val fftJsonArray = data.fft?.let { fftArray ->
446
+ JSONArray().apply {
447
+ for (value in fftArray) {
448
+ put(value.toDouble())
442
449
  }
443
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
450
+ }
444
451
  }
452
+ jsonData.put("fft", fftJsonArray)
453
+
454
+
455
+ jsonObject.put("data", jsonData)
456
+ jsonObject.put("deviceID", config.id)
457
+ sendEvent(EventName.GizMusicalRhythmEvnet.name, GizRNCallbackManager.jsonObject2WriteableMap(jsonObject))
458
+ }
445
459
  }
460
+ GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
461
+ }
446
462
  }
447
- @ReactMethod
448
- fun stopMusicalRhythm(options: ReadableMap, result: Callback) {
449
- val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopMusicalRhythmParams::class.java)
450
- if (config !=null && device !=null) {
451
- CoroutineScope(Dispatchers.IO).launch {
452
- val res = device.stopMusicalRhythm();
453
- GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
454
- }
455
- }
463
+ }
464
+ @ReactMethod
465
+ fun stopMusicalRhythm(options: ReadableMap, result: Callback) {
466
+ val (config, device) = RNGizParamsChecker.checkDeviceAndParams(options, result, StopMusicalRhythmParams::class.java)
467
+ if (config !=null && device !=null) {
468
+ CoroutineScope(Dispatchers.IO).launch {
469
+ val res = device.stopMusicalRhythm();
470
+ GizRNCallbackManager.callbackWithResult(callback = result, result = Result.success(Unit))
471
+ }
456
472
  }
473
+ }
457
474
 
458
-
459
-
460
- fun sendEvent(name:String, data: WritableMap?) {
461
- reactApplicationContext
462
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
463
- .emit(name, data)
464
- }
475
+ fun sendEvent(name:String, data: WritableMap?) {
476
+ reactApplicationContext
477
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
478
+ .emit(name, data)
479
+ }
465
480
 
466
481
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.4.57",
3
+ "version": "1.4.58",
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.6.6'
22
+ s.dependency 'GizwitsiOSSDK', '~> 1.6.7'
23
23
 
24
24
  end