flutter_nearby_connections icon indicating copy to clipboard operation
flutter_nearby_connections copied to clipboard

Can we share file using this? There is only method for sending message.

Open faizatflutter opened this issue 2 years ago • 4 comments

faizatflutter avatar Apr 06 '22 20:04 faizatflutter

Actually you can send file. For large files you have to read them which will consume more memory, I guess the maxed allowed packet size is 1mb so break your file into chunks and send which will save ram also.

abhay-s-rawat avatar Apr 29 '22 08:04 abhay-s-rawat

I forgot to tell use jsonEncode/Decode for conversion of your message to string. I created function below for my project.I used webrct data channel.

    final Completer completer = Completer();
    int start = (currentChunkId - 1) * Config.webrtcDataChannelChunkSize;
    int end = currentChunkId * Config.webrtcDataChannelChunkSize;
    if (end > mainModel.offerModel.fileSize) {
      end = mainModel.offerModel.fileSize;
    }
    List<int> data = [];
    Stream<List<int>> dataStream = mainModel.file.openRead(start, end);
    dataStream.listen((List<int> event) {
      data.addAll(event);
    }, onDone: () async {
      DCTransferModel model = DCTransferModel(
        fileId: mainModel.offerModel.fileId,
        chunkId: currentChunkId,
        //data: data,
        data: base64Encode(gzip.encode(data)),
      );
      await _dataChannel!.send(RTCDataChannelMessage(model.toJson));
      mainModel.progress.value =
          currentChunkId / mainModel.offerModel.totalChunks;
      completer.complete();
    });
    return completer.future;
  }```

abhay-s-rawat avatar Apr 29 '22 08:04 abhay-s-rawat

I forgot to tell use jsonEncode/Decode for conversion of your message to string. I created function below for my project.I used webrct data channel.

@abhay-s-rawat Can you provide a more detailed example?

serzhikdnepr avatar Aug 08 '22 20:08 serzhikdnepr

Did anyone get this working?

IPODG avatar Sep 12 '22 14:09 IPODG