Conversation
Aniket392
commented
Feb 23, 2026
- Adding c4Peerdiscovery implementation, implementing all methods and connecting it to java
- BT connections discovery logic from both native as well as java side
- Writing helper class like MetadataHelper, to convert java map object
- Adding native implementation to BluetoothPeer
- Updating native_c4multipeerreplicator to take protocol parameter
| xmlns:tools="http://schemas.android.com/tools" | ||
| > | ||
|
|
||
| <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> |
There was a problem hiding this comment.
What does this mean to users who don't use MultipeerReplicator with Bluetooth?
There was a problem hiding this comment.
If anyone do not use MultipeerReplicator with Bluetooth, this permission has no effect.
| C4String protocols[] = {kPeerSyncProtocol_DNS_SD}; | ||
| params.protocols = protocols; | ||
| params.protocolsCount = sizeof(protocols) / sizeof(protocols[0]); | ||
| params.protocols = kPeerSyncProtocol_BluetoothLE; |
There was a problem hiding this comment.
Need to be passed as an array of transport values.
There was a problem hiding this comment.
Added
params.protocols = kPeerSyncProtocol_DNS_SD | kPeerSyncProtocol_BluetoothLE;
| m_C4PeerDiscoveryProvider_startBrowsing, | ||
| _contextToken); | ||
|
|
||
|
|
There was a problem hiding this comment.
Removed extra spaces
| } | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Removed extra lines
| auto peer = provider->discovery().peerWithID("peerIdObj"); | ||
| if (peer) { | ||
| // Notify about the incoming connection | ||
| bool accepted = provider->notifyIncomConnection(peer.get(), socket); |
There was a problem hiding this comment.
notifyIncomConnection -> there is a typo in this function name.
There was a problem hiding this comment.
Currently removed this
Will update with Socketfactory
| return setObj; | ||
| } | ||
|
|
||
| static C4PeerSyncProtocols toC4PeerSyncProtocols(JNIEnv* env, jobject enumSetTransports) { |
There was a problem hiding this comment.
I have looked where the other components implement something similar to this (e.g. database flags), the enums are implemented on the Java side in C4Constants class with the enum values copied from LiteCore.
Let's follow the same pattern. Here is an example :
Then the raw enum value can be passed between Java and JNI directly.
There was a problem hiding this comment.
Same for the transport enum above.
There was a problem hiding this comment.
For toC4PeerSyncProtocols, we can use the same pattern as you shared
But when we are converting from litecore flag to Java object, we need to have something like toJavaTransportSet
It is similar how we have
couchbase-lite-java-common/common/main/cpp/native_c4replutils.cc
Lines 81 to 92 in b7bcaf7
Or do you suggest something else?
There was a problem hiding this comment.
Removed toC4PeerSyncProtocols and other transport conversion method
| std::string peerId = JstringToUTF8(env, jPeerId); | ||
| if (peerId.empty()) { return 0; } | ||
|
|
||
| auto* peer = new C4Peer(provider, peerId); |
There was a problem hiding this comment.
I think make_retained should be used like this to get the refcount +1.
make_retained<C4Peer>(this, "null::" + id, "").detach()
However, when does this createC4Peer is used? If it's used by adding new peer. I think it's better to have the JNI's addPeer() method to create the C4Peer object by itself, add it to the C4DiscoveryProvider, then return the detached C4Peer object back to Java to retain if needed. By doing it that way, there will be only one JNI call.