mannprerak2 / nearby_connections

Flutter plugin (android) for sharing bytes and files Offline, (Based on the android Nearby Connections API)
https://pub.dev/packages/nearby_connections
BSD 2-Clause "Simplified" License
94 stars 30 forks source link

Any way to expose the payload ID when sending bytes so that we can correlate it in transfer update? #69

Open sarbogast opened 9 months ago

sarbogast commented 9 months ago

Sometimes, when I send a bytes payload, it fails to transmit, and I receive an error in onPayloadTransferUpdate. Then, I would like to try resending the same payload again, but for that I would need to be able to correlate the payload ID I get in PayloadTransferUpdate with the ID of the payload that was sent, but I only get a payload ID back when sending a file, not bytes. I tried to add this feature myself, making sendBytesPayload return a Future<int> instead of a Future<void>, but it seems to be useless because the transfer update is called before sendBytes returns.

Would it even be possible?

mannprerak2 commented 9 months ago

This may be happening due to the async nature of the flutter method channel.

In my local experiments I am getting response from sendBytes before transfer update.

D/nearby_connections(27109): sentPayload: -8806054461585292721
I/flutter (27109): sendBytesPayload in flutter
D/nearby_connections(27109): onPayloadTransferUpdate :-8806054461585292721
I/flutter (27109): 2
D/nearby_connections(27109): onPayloadTransferUpdate :-8806054461585292721

The only other option I feel would be to use some sort of synchronization mechanism on Java side so that sendBytesPayload only returns after a successful call to payloadTransferUpdate.

mannprerak2 commented 9 months ago

Another option could be to separate out the Payload preparation and Payload sending methods.

Upon preparing the payload, you should get the payload Id back, after which you may send the payload in another call.