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