kard-network-ble-mesh 1.0.0 → 1.1.1

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.
@@ -66,12 +66,12 @@ android {
66
66
  }
67
67
 
68
68
  compileOptions {
69
- sourceCompatibility JavaVersion.VERSION_1_8
70
- targetCompatibility JavaVersion.VERSION_1_8
69
+ sourceCompatibility JavaVersion.VERSION_17
70
+ targetCompatibility JavaVersion.VERSION_17
71
71
  }
72
72
 
73
73
  kotlinOptions {
74
- jvmTarget = "1.8"
74
+ jvmTarget = "17"
75
75
  }
76
76
 
77
77
  sourceSets {
@@ -145,6 +145,14 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
145
145
  fun start(nickname: String, promise: Promise) {
146
146
  myNickname = nickname
147
147
 
148
+ // If already running, just update nickname and resolve
149
+ if (isRunning) {
150
+ Log.d(TAG, "Already running, updating nickname to: $nickname")
151
+ sendAnnounce()
152
+ promise.resolve(null)
153
+ return
154
+ }
155
+
148
156
  scope.launch {
149
157
  try {
150
158
  startBleServices()
@@ -162,6 +170,13 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
162
170
 
163
171
  @ReactMethod
164
172
  fun stop(promise: Promise) {
173
+ // If not running, just resolve
174
+ if (!isRunning) {
175
+ Log.d(TAG, "Already stopped, nothing to do")
176
+ promise.resolve(null)
177
+ return
178
+ }
179
+
165
180
  scope.launch {
166
181
  try {
167
182
  sendLeaveAnnouncement()
@@ -481,7 +496,9 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
481
496
  BluetoothProfile.STATE_CONNECTED -> {
482
497
  Log.d(TAG, "Connected to GATT server: $address")
483
498
  gattConnections[address] = gatt
484
- gatt.discoverServices()
499
+ // Request larger MTU for bigger packets (512 bytes)
500
+ Log.d(TAG, "Requesting MTU 512 for $address")
501
+ gatt.requestMtu(512)
485
502
  }
486
503
  BluetoothProfile.STATE_DISCONNECTED -> {
487
504
  Log.d(TAG, "Disconnected from GATT server: $address")
@@ -500,9 +517,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
500
517
 
501
518
  @SuppressLint("MissingPermission")
502
519
  override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
520
+ Log.d(TAG, "onServicesDiscovered: status=$status for ${gatt.device.address}")
503
521
  if (status == BluetoothGatt.GATT_SUCCESS) {
504
522
  val service = gatt.getService(serviceUUID)
523
+ Log.d(TAG, "Found service: ${service != null}, UUID: $serviceUUID")
505
524
  val characteristic = service?.getCharacteristic(characteristicUUID)
525
+ Log.d(TAG, "Found characteristic: ${characteristic != null}")
506
526
 
507
527
  if (characteristic != null) {
508
528
  gatt.setCharacteristicNotification(characteristic, true)
@@ -510,21 +530,40 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
510
530
  val descriptor = characteristic.getDescriptor(
511
531
  UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
512
532
  )
533
+ Log.d(TAG, "Found descriptor: ${descriptor != null}")
513
534
  descriptor?.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
514
535
  gatt.writeDescriptor(descriptor)
515
536
 
516
537
  // Send announce
538
+ Log.d(TAG, "Sending announce after services discovered")
517
539
  sendAnnounce()
540
+ } else {
541
+ Log.e(TAG, "Characteristic not found on remote device!")
518
542
  }
543
+ } else {
544
+ Log.e(TAG, "Service discovery failed with status: $status")
519
545
  }
520
546
  }
521
547
 
522
548
  override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
523
549
  val data = characteristic.value
550
+ Log.d(TAG, "onCharacteristicChanged: received ${data?.size ?: 0} bytes from ${gatt.device.address}")
524
551
  if (data != null) {
525
552
  handleReceivedPacket(data, gatt.device.address)
526
553
  }
527
554
  }
555
+
556
+ @SuppressLint("MissingPermission")
557
+ override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
558
+ Log.d(TAG, "MTU changed to $mtu for ${gatt.device.address}, status: $status")
559
+ if (status == BluetoothGatt.GATT_SUCCESS) {
560
+ // Now discover services after MTU is set
561
+ gatt.discoverServices()
562
+ } else {
563
+ Log.e(TAG, "MTU negotiation failed, discovering services anyway")
564
+ gatt.discoverServices()
565
+ }
566
+ }
528
567
  }
529
568
 
530
569
  private val gattServerCallback = object : BluetoothGattServerCallback() {
@@ -553,8 +592,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
553
592
  offset: Int,
554
593
  value: ByteArray
555
594
  ) {
595
+ Log.d(TAG, "onCharacteristicWriteRequest: ${value.size} bytes from ${device.address}, uuid=${characteristic.uuid}")
556
596
  if (characteristic.uuid == characteristicUUID) {
597
+ Log.d(TAG, "Characteristic matches, handling packet")
557
598
  handleReceivedPacket(value, device.address)
599
+ } else {
600
+ Log.d(TAG, "Characteristic UUID mismatch: expected $characteristicUUID")
558
601
  }
559
602
  if (responseNeeded) {
560
603
  gattServer?.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0, null)
@@ -579,26 +622,41 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
579
622
  // MARK: - Packet Handling
580
623
 
581
624
  private fun handleReceivedPacket(data: ByteArray, fromAddress: String) {
582
- val packet = BitchatPacket.decode(data) ?: return
625
+ Log.d(TAG, "handleReceivedPacket: ${data.size} bytes from $fromAddress")
626
+ val packet = BitchatPacket.decode(data)
627
+ if (packet == null) {
628
+ Log.e(TAG, "Failed to decode packet!")
629
+ return
630
+ }
583
631
 
584
632
  val senderId = packet.senderId.joinToString("") { "%02x".format(it) }
633
+ Log.d(TAG, "Packet from sender: $senderId, type: ${packet.type}, myPeerId: $myPeerId")
585
634
 
586
635
  // Skip our own packets
587
- if (senderId == myPeerId) return
636
+ if (senderId == myPeerId) {
637
+ Log.d(TAG, "Skipping own packet")
638
+ return
639
+ }
588
640
 
589
641
  // Deduplication
590
642
  val messageId = "$senderId-${packet.timestamp}-${packet.type}"
591
- if (processedMessages.contains(messageId)) return
643
+ if (processedMessages.contains(messageId)) {
644
+ Log.d(TAG, "Duplicate packet, skipping")
645
+ return
646
+ }
592
647
  processedMessages.add(messageId)
593
648
 
649
+ val messageType = MessageType.fromValue(packet.type)
650
+ Log.d(TAG, "Processing packet type: $messageType")
651
+
594
652
  // Handle by type
595
- when (MessageType.fromValue(packet.type)) {
653
+ when (messageType) {
596
654
  MessageType.ANNOUNCE -> handleAnnounce(packet, senderId)
597
655
  MessageType.MESSAGE -> handleMessage(packet, senderId)
598
656
  MessageType.NOISE_HANDSHAKE -> handleNoiseHandshake(packet, senderId)
599
657
  MessageType.NOISE_ENCRYPTED -> handleNoiseEncrypted(packet, senderId)
600
658
  MessageType.LEAVE -> handleLeave(senderId)
601
- else -> {}
659
+ else -> Log.d(TAG, "Unknown message type: ${packet.type}")
602
660
  }
603
661
 
604
662
  // Relay if TTL > 0
@@ -633,6 +691,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
633
691
  }
634
692
 
635
693
  private fun handleAnnounce(packet: BitchatPacket, senderId: String) {
694
+ Log.d(TAG, "handleAnnounce from $senderId, payload size: ${packet.payload.size}")
636
695
  // Parse TLV payload
637
696
  var nickname = senderId
638
697
  var noisePublicKey: ByteArray? = null
@@ -656,6 +715,8 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
656
715
  }
657
716
  }
658
717
 
718
+ Log.d(TAG, "Parsed announce: nickname=$nickname from peer $senderId")
719
+
659
720
  peers[senderId] = PeerInfo(
660
721
  peerId = senderId,
661
722
  nickname = nickname,
@@ -665,6 +726,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
665
726
  isVerified = false
666
727
  )
667
728
 
729
+ Log.d(TAG, "Peer added, total peers: ${peers.size}")
668
730
  notifyPeerListUpdated()
669
731
  }
670
732
 
@@ -1041,7 +1103,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
1041
1103
  REQUEST_SYNC(0x08);
1042
1104
 
1043
1105
  companion object {
1044
- fun fromValue(value: Byte): MessageType? = entries.find { it.value == value }
1106
+ fun fromValue(value: Byte): MessageType? = values().find { it.value == value }
1045
1107
  }
1046
1108
  }
1047
1109
 
@@ -1054,7 +1116,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
1054
1116
  VERIFY_RESPONSE(0x06);
1055
1117
 
1056
1118
  companion object {
1057
- fun fromValue(value: Byte): NoisePayloadType? = entries.find { it.value == value }
1119
+ fun fromValue(value: Byte): NoisePayloadType? = values().find { it.value == value }
1058
1120
  }
1059
1121
  }
1060
1122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kard-network-ble-mesh",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Kard Network BLE Mesh networking library for React Native with seamless permissions",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -49,14 +49,17 @@
49
49
  ],
50
50
  "repository": {
51
51
  "type": "git",
52
- "url": "git+https://github.com/anthropics/kard-network-ble-mesh.git"
52
+ "url": "git+https://github.com/kard-network/kard-network-ble-mesh.git"
53
+ },
54
+ "author": {
55
+ "name": "rrigoni",
56
+ "email": "rrigoni@gmail.com"
53
57
  },
54
- "author": "Kard Network",
55
58
  "license": "MIT",
56
59
  "bugs": {
57
- "url": "https://github.com/anthropics/kard-network-ble-mesh/issues"
60
+ "url": "https://github.com/kard-network/kard-network-ble-mesh/issues"
58
61
  },
59
- "homepage": "https://github.com/anthropics/kard-network-ble-mesh#readme",
62
+ "homepage": "https://github.com/kard-network/kard-network-ble-mesh#readme",
60
63
  "publishConfig": {
61
64
  "registry": "https://registry.npmjs.org/"
62
65
  },