react-native-gizwits-sdk-v5 1.5.2-thirdbluetooth → 1.5.3-thirdbluetooth

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.
@@ -16,7 +16,6 @@ import com.gizwits.smart.sdk.common.GizWiFiActivatorEvent
16
16
  import com.gizwits.smart.sdk.core.capacity.CapacityTypes
17
17
  import com.gizwits.smart.sdk.exception.GizException
18
18
  import com.gizwits.smart.sdk.extend.hexToByteArray
19
- import android.util.Base64
20
19
  import com.gizwits.smart.sdk.lan.lanCapability
21
20
  import com.gizwits.smart.sdk.mqtt.mqttCapability
22
21
  import com.gizwits.smart.sdk.light.MusicalRhythmParseMode
@@ -571,20 +570,26 @@ fun wiFiCredentialsWithAirLinkEventHandler(event: GizWiFiActivatorEvent) {
571
570
  moduleScope.launch {
572
571
  try {
573
572
  // 第三方设备直接透传原始数据,使用特殊键 "rawData" 标识原始数据
574
- // 支持 Base64、十六进制或 UTF-8 字符串格式
575
- val rawData: ByteArray = try {
576
- // 首先尝试 Base64 解码
577
- Base64.decode(config.data, Base64.NO_WRAP)
578
- } catch (e: Exception) {
579
- try {
580
- // 如果 Base64 解码失败,尝试十六进制解码
581
- config.data.hexToByteArray()
582
- } catch (e2: Exception) {
583
- // 如果都失败,使用 UTF-8 编码
584
- config.data.toByteArray(Charsets.UTF_8)
585
- }
573
+ // 只支持十六进制字符串格式(只包含 0-9A-Fa-f,且长度为偶数)
574
+ if (!config.data.matches(Regex("^[0-9A-Fa-f]+$"))) {
575
+ GizRNCallbackManager.callbackWithResult(
576
+ callback = result,
577
+ result = Result.failure<Unit>(IllegalArgumentException("Data must be a valid hexadecimal string (0-9A-Fa-f only)"))
578
+ )
579
+ return@launch
580
+ }
581
+
582
+ if (config.data.length % 2 != 0) {
583
+ GizRNCallbackManager.callbackWithResult(
584
+ callback = result,
585
+ result = Result.failure<Unit>(IllegalArgumentException("Hex string length must be even"))
586
+ )
587
+ return@launch
586
588
  }
587
589
 
590
+ // 使用十六进制解码
591
+ val rawData: ByteArray = config.data.hexToByteArray()
592
+
588
593
  // 使用特殊键 "rawData" 传递原始数据,sendThirdDeviceDp 会识别并直接透传
589
594
  val res = device.sendThirdDeviceDp("rawData" to rawData, characteristicUuid = config.characteristicUuid)
590
595
  GizRNCallbackManager.callbackWithResult(callback = result, result = res)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.5.2-thirdbluetooth",
3
+ "version": "1.5.3-thirdbluetooth",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",