published 1.0.0

multipeer_ios
Prerak Mann 5 years ago
parent 4d666c42a5
commit dcd86e885f

@ -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. So you would need to rename the file on receivers end.
```dart ```dart
//creates file with generic name (without extension) in Downloads Directory //creates file with generic name (without extension) in Downloads Directory
Nearby().sendFilePayload(endpointId, filePath); Nearby().sendFilePayload(endpointId, filePath);
//Send filename as well so that receiver can rename the file //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

@ -352,12 +352,15 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
args.put("endpointId", endpointId); args.put("endpointId", endpointId);
args.put("payloadId", payload.getId()); args.put("payloadId", payload.getId());
args.put("type", payload.getType()); args.put("type", payload.getType());
if (payload.getType() == Payload.Type.BYTES) { if (payload.getType() == Payload.Type.BYTES) {
byte[] bytes = payload.asBytes(); byte[] bytes = payload.asBytes();
assert bytes != null; assert bytes != null;
args.put("bytes", bytes); args.put("bytes", bytes);
} }
else if (payload.getType() == Payload.Type.BYTES) {
args.put("filePath", payload.asFile().asJavaFile().getAbsolutePath());
}
channel.invokeMethod("onPayloadReceived", args); channel.invokeMethod("onPayloadReceived", args);
} }

@ -4,15 +4,24 @@ import 'dart:typed_data';
import 'package:nearby_connections/src/defs.dart'; import 'package:nearby_connections/src/defs.dart';
/// Bytes may be null if [Payload.type] is not [PayloadType.BYTES] /// 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 { class Payload {
int id; int id;
PayloadType type; PayloadType type;
Uint8List bytes; Uint8List bytes;
String filePath;
Payload({ Payload({
this.id, this.id,
this.bytes, this.bytes,
this.type = PayloadType.NONE, this.type = PayloadType.NONE,
this.filePath,
}); });
} }

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

Loading…
Cancel
Save