published 1.0.0

This commit is contained in:
Prerak Mann 2019-08-12 00:37:27 +05:30
parent 4d666c42a5
commit dcd86e885f
4 changed files with 24 additions and 5 deletions

View File

@ -132,15 +132,20 @@ File is stored in DOWNLOAD_DIRECTORY and given a generic name
So you would need to rename the file on receivers end.
```dart
//creates file with generic name (without extension) in Downloads Directory
Nearby().sendFilePayload(endpointId, filePath);
//Send filename as well so that receiver can rename the file
Nearby().sendBytesPayload(endpointId,fileNameEncoded);
Nearby().sendBytesPayload(endpointId,fileNameEncodedWithPayloadId);
//e.g send a string like "payloadId:FileExtensionOrName" as bytes
// payloads are recieved by callback given to acceptConnection method.
//payloads are recieved by callback given to acceptConnection method.
```
Every payload has an **ID** which is same for sender and receiver.
You can get the absolute FilePath from Payload in *onPayloadReceived* function
Check **Example** in Repository for more details

View File

@ -358,6 +358,9 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
assert bytes != null;
args.put("bytes", bytes);
}
else if (payload.getType() == Payload.Type.BYTES) {
args.put("filePath", payload.asFile().asJavaFile().getAbsolutePath());
}
channel.invokeMethod("onPayloadReceived", args);
}

View File

@ -4,15 +4,24 @@ import 'dart:typed_data';
import 'package:nearby_connections/src/defs.dart';
/// Bytes may be null if [Payload.type] is not [PayloadType.BYTES]
/// File may be null if [Payload.type] is not [PayloadType.FILE]
///
/// Filepath is the complete filepath(with name) of the file
///
/// The file at this location is incomplete until payloadTransferUpdate
/// gives SUCCESS for this payloadId
class Payload {
int id;
PayloadType type;
Uint8List bytes;
String filePath;
Payload({
this.id,
this.bytes,
this.type = PayloadType.NONE,
this.filePath,
});
}

View File

@ -96,11 +96,13 @@ class Nearby {
int type = args['type'];
Uint8List bytes = args['bytes'];
int payloadId = args['payloadId'];
String filePath = args['filePath'];
Payload payload = Payload(
type: PayloadType.values[type],
bytes: bytes,
id: payloadId,
filePath: filePath,
);
_onPayloadReceived?.call(endpointId, payload);